2

I'm working with NPOI in c#.NET then I make .docx file in MS office to make as template

my word template contain content like this

template.docx
    Name : {firstname}
    last name : {lastname}

then I using NPOI read and edit my docx file by replace {firstname} and {lastname} with another text using this code below

foreach (XWPFParagraph p in plainTextParagraphs)
{
    if (p.Text != null)
    {
          while (p.Text.Contains(oldText))
          {
               p.ReplaceText(oldText, " " + newText + " ");
          }
    }
}

but when I save it back to file

output.docx

and open to see result it's look like NPOI not keep my template setting for example a space between line see image below

template spacing

enter image description here

first picture is spacing on template.docx is 0

but 8 in output.docx (second picture)

So I want to keep all style and layout.

rene
  • 41,474
  • 78
  • 114
  • 152
Chanom First
  • 1,136
  • 1
  • 11
  • 25

0 Answers0