C# 如何设置打开的xml文档的文本编码

C# 如何设置打开的xml文档的文本编码,c#,asp.net,openxml,openxml-sdk,C#,Asp.net,Openxml,Openxml Sdk,如何设置打开的xml文档的文本编码 在Office2003中,当我打开一个通过OpenXML构建的文档时,出现了一个关于编码的错误。如何设置编码或如何修复此错误 我已经安装了兼容包,我可以打开每个.docx文件,但这一个似乎我需要设置编码 如何创建文档 private static void BuildDocument(string fileName, List<string> lista, string tipo) { using

如何设置打开的xml文档的文本编码

在Office2003中,当我打开一个通过OpenXML构建的文档时,出现了一个关于编码的错误。如何设置编码或如何修复此错误

我已经安装了兼容包,我可以打开每个.docx文件,但这一个似乎我需要设置编码

如何创建文档

private static void BuildDocument(string fileName, List<string> lista, string tipo)
        {     

            using (WordprocessingDocument w = WordprocessingDocument.Create(fileName, WordprocessingDocumentType.Document))
            {                
                MainDocumentPart mp = w.AddMainDocumentPart();
                DocumentFormat.OpenXml.Wordprocessing.Document d = new DocumentFormat.OpenXml.Wordprocessing.Document();
                Body b = new Body();                
                DocumentFormat.OpenXml.Wordprocessing.Paragraph p = new DocumentFormat.OpenXml.Wordprocessing.Paragraph();
                Run r = new Run();
                for (int i = 0; i < lista.Count; i++)
                {
                    Text t = new Text();
                    t.Text = lista[i];

                    if (t.Text == "          ")
                    {
                        r.Append(new CarriageReturn());
                    }
                    else
                    {                        
                        r.Append(t);
                        r.Append(new CarriageReturn());
                    }
                }

                lista.Clear();
                p.Append(r);
                b.Append(p);
                HeaderPart hp = mp.AddNewPart<HeaderPart>();
                string headerRelationshipID = mp.GetIdOfPart(hp);
                SectionProperties sectPr = new SectionProperties();
                HeaderReference headerReference = new HeaderReference();
                headerReference.Id = headerRelationshipID;
                headerReference.Type = HeaderFooterValues.Default;
                sectPr.Append(headerReference);
                b.Append(sectPr);
                d.Append(b);

                hp.Header.Save();
                mp.Document = d;
                mp.Document.Save();
                w.Close();
            }             
        }
private static void BuildDocument(字符串文件名、列表列表A、字符串tipo)
{     
使用(WordprocessingDocument w=WordprocessingDocument.Create(文件名,WordprocessingDocumentType.Document))
{                
MainDocumentPart mp=w.AddMainDocumentPart();
DocumentFormat.OpenXml.Wordprocessing.Document d=新的DocumentFormat.OpenXml.Wordprocessing.Document();
主体b=新主体();
DocumentFormat.OpenXml.Wordprocessing.Parague p=新的DocumentFormat.OpenXml.Wordprocessing.Parague();
运行r=新运行();
for(int i=0;i
开放式XML仅适用于Office documents 2007及更早版本。Office 2003及以下版本与Open XML不兼容,这就是为什么会出现此弹出窗口。这是无法通过Open XML控制的,当您打开不兼容的文档时,只有Word会弹出窗口。

@zmilojko看看我的更新,我是如何创建文档的,也许有一些方法可以通过代码设置编码。