Thank 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 8 years, 5 months ago by tatsuya.