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

 
            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);
            }

你可能感兴趣的:(word)