C# 如何在使用NPOI编辑docx后保留所有样式和布局
我在c#NET中与NPOI合作 然后我在MS office中生成.docx文件作为模板 我的word模板包含如下内容C# 如何在使用NPOI编辑docx后保留所有样式和布局,c#,apache-poi,docx,npoi,xwpf,C#,Apache Poi,Docx,Npoi,Xwpf,我在c#NET中与NPOI合作 然后我在MS office中生成.docx文件作为模板 我的word模板包含如下内容 template.docx Name : {firstname} last name : {lastname} 然后,我使用下面的代码用另一个文本替换{firstname}和{lastname}来读取和编辑我的docx文件 foreach (XWPFParagraph p in plainTextParagraphs) { if (p.Text != n
template.docx
Name : {firstname}
last name : {lastname}
然后,我使用下面的代码用另一个文本替换{firstname}和{lastname}来读取和编辑我的docx文件
foreach (XWPFParagraph p in plainTextParagraphs)
{
if (p.Text != null)
{
while (p.Text.Contains(oldText))
{
p.ReplaceText(oldText, " " + newText + " ");
}
}
}
但当我把它保存回文件时
output.docx
打开查看结果,看起来好像我没有保留模板设置,例如,行与行之间有一个空格,请参见下图
第一张图片是模板上的间距。docx为0
但output.docx中为8(第二张图片)
所以我想保持所有的风格和布局