Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Docx File corruption due to the image wrapping #504

Closed
stevenxi opened this issue Jan 15, 2021 · 4 comments
Closed

Docx File corruption due to the image wrapping #504

stevenxi opened this issue Jan 15, 2021 · 4 comments
Labels
bug docx file_error file format generation/writing issue
Milestone

Comments

@stevenxi
Copy link

stevenxi commented Jan 15, 2021

When there's image in the .docx file (with text wrapping), open and save by NPOI. The file can no longer by open by Word there after.

version 2.5.2


            using (var fs = new FileStream(@"Template.docx", FileMode.Open, FileAccess.Read))
            using (var outputFile = new FileStream(@"out.docx", FileMode.Create, FileAccess.Write))
            {
                var doc = new XWPFDocument(fs);
                doc.Write(outputFile);
            }

Template.docx

Capture

@stevenxi stevenxi changed the title .docx file got corrupted after touched by NPOI .docx file got corrupted after touched by NPOI (NPOI 另存带图片的Word文档后,文件损坏) Jan 15, 2021
@stevenxi
Copy link
Author

It's related to this Stackoverflow issue: https://stackoverflow.com/questions/52169811/why-docx-file-is-corrupted-after-editing-with-npoi

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).

@stevenxi
Copy link
Author

Fixed few of them as PR #510

@tonyqus tonyqus added the file_error file format generation/writing issue label Mar 31, 2021
@tonyqus tonyqus added this to the NPOI 2.5.5 milestone Apr 18, 2021
@tonyqus tonyqus closed this as completed May 30, 2021
@tonyqus tonyqus modified the milestones: NPOI 2.5.5, NPOI 2.5.4 Jun 26, 2021
@tonyqus tonyqus changed the title .docx file got corrupted after touched by NPOI (NPOI 另存带图片的Word文档后,文件损坏) Docx File corruption due to the image wrapping Jul 10, 2021
@tohoaibao
Copy link

I still get error when Image wraping in header. I use version NPOI 2.5.4
Template.docx

@tonyqus
Copy link
Member

tonyqus commented Aug 25, 2021

@tohoaibao Your file has some special w14 attributes. I've figure out some issues from our word templates.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug docx file_error file format generation/writing issue
Projects
None yet
Development

No branches or pull requests

3 participants