tatsuya
Forum Replies Created
Viewing 1 post (of 1 total)
-
AuthorPosts
-
June 15, 2016 at 2:56 pm in reply to: How to prevent Microsoft Word from adding default paragraph spacing. #3490
tatsuya
ParticipantThank you very much for the advice, which solved my problem.
I wrote the following code.
private static void Main() { using (var wd = WordprocessingDocument.Create("HelloWorld.docx", WordprocessingDocumentType.Document)) { var mdp = wd.AddMainDocumentPart(); AddStyleDefinitionPart(mdp); AddParagraphPropertiesDefault(mdp.StyleDefinitionsPart); mdp.Document = new Document(new Body()); mdp.Document.Body.AppendChild(new Paragraph(new Run(new Text("Hello")))); mdp.Document.Body.AppendChild(new Paragraph(new Run(new Text("World")))); mdp.Document.Save(); wd.Close(); } } private static void AddStyleDefinitionPart(OpenXmlPartContainer oxpc) { new Styles().Save(oxpc.AddNewPart<StyleDefinitionsPart>()); } private static void AddParagraphPropertiesDefault(StylesPart sp) { sp.Styles = new Styles(new DocDefaults(new ParagraphPropertiesDefault())); }Now, even after opening and resaving HelloWorld.docx using Microsoft Word,
styles.xml remains the same as follows without w:spacing in it.<w:styles xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"> <w:docDefaults> <w:pPrDefault /> </w:docDefaults> </w:styles>-
This reply was modified 9 years, 8 months ago by
tatsuya.
-
This reply was modified 9 years, 8 months ago by
-
AuthorPosts
Viewing 1 post (of 1 total)