I want to edit .docx file and use npoi library.
Is is a snippet:
XWPFDocument doc;
using( FileStream fileStream = new FileStream(@"D:\\template.docx", FileMode.Open, FileAccess.Read) ) {
doc = new XWPFDocument(fileStream);
fileStream.Close();
}
// here can change doc or do nothing
using(FileStream fileStreamNew = new FileStream(@"D:\\test.docx", FileMode.CreateNew)) {
doc.Write(fileStreamNew);
fileStreamNew.Close();
}
But I get the corrupted file. When I try to open file, modal window is displayed: "We are sorry. We can't open test.docx we found a problem with its content. Details: Unspecified error. Location: /word/header1.xml, Line: 0, Column: 0"
Thank you in advance
============================================================
UPDATE:
Problem is in template file. If I remove images from header & footer then error pass away. But if I put template images back the error return. Any ideas?
=============================================================
UPDATE:
The problem occurs when the image property "Wrap Text" has a value other than "In Line With Text". In my case when the image is background of the text. ('behind text' value).