当前位置: 首页 > 工具软件 > OOXML SDK > 使用案例 >

OpenXml SDK 2.0 创建Word 2010文档(不带[Compatibility])最简代码

齐高寒
2023-12-01
 
            using (WordprocessingDocument objWordDocument = WordprocessingDocument.Create(@"C:\******.docx", WordprocessingDocumentType.Document))
            {
                MainDocumentPart objMainDocumentPart = objWordDocument.AddMainDocumentPart();
                Document objDocument = new Document() ;
                Body objBody = new Body();
                objDocument.Append(objBody);
                objMainDocumentPart.Document = objDocument;
                DocumentSettingsPart objDocumentSettingPart = objMainDocumentPart.AddNewPart<DocumentSettingsPart>();
                objDocumentSettingPart.Settings = new Settings();
                Compatibility objCompatibility = new Compatibility();
                CompatibilitySetting objCompatibilitySetting = new CompatibilitySetting() { Name = CompatSettingNameValues.CompatibilityMode, Uri = "http://schemas.microsoft.com/office/word", Val = "14" };
                objCompatibility.Append(objCompatibilitySetting);
                objDocumentSettingPart.Settings.Append(objCompatibility);
            }

转载于:https://www.cnblogs.com/mksword/archive/2011/11/21/3934149.html

 类似资料: