Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Link in picture breaks NPOI template edit #1010

Closed
Cpt-Falcon opened this issue Feb 1, 2023 · 5 comments
Closed

Link in picture breaks NPOI template edit #1010

Cpt-Falcon opened this issue Feb 1, 2023 · 5 comments

Comments

@Cpt-Falcon
Copy link

Putting a link in a picture, loading the document into NPOI, and then saving the document corrupts the word doc

@Cpt-Falcon
Copy link
Author

image

@tonyqus
Copy link
Member

tonyqus commented Feb 1, 2023

Can you share the original document?

@tonyqus
Copy link
Member

tonyqus commented Feb 1, 2023

Stop creating similar issues. Let's discuss in this thread. And I've closed #1009 as it's duplicate.

@Cpt-Falcon
Copy link
Author

@tonyqus Sorry, they seemed like different issues given one was about the link breaking picture in a template doc, and the other was about a picture in a table that doesn't persist after saving.

So my thinking was that hyperlink in picture corrupting doc=/= picture in table not persisting since they're two completely different behaviors and use cases.

I've created a mini demo repo with the documents. I have one document called working just as a demonstration that the code does work here and I have TestLinkBreak.docx as an example. There is a folder in NPOITest called TestDocs with the word documents. Output documents will be written to the bin\net6.0 dir.

https://github.com/Cpt-Falcon/NPOITest

I'm going to add additional documents here as a simple demonstration

@tonyqus tonyqus modified the milestones: NPOI 2.6.1, NPOI 2.6.2 Jun 8, 2023
@tonyqus
Copy link
Member

tonyqus commented Jul 23, 2023

I read your code. I don't think you can simply merge two docx with binary data. It's Office file instead of plain text.

byte[] bytes = await File.ReadAllBytesAsync(inputFile);
using MemoryStream ms = new(bytes);
XWPFDocument doc = new(ms);

MemoryStream result = new();
doc.Write(result);
result.Flush();
result.Position = 0;

await using FileStream fs = new($"{fileName}.docx", FileMode.Create, FileAccess.Write);
fs.Write(result.ToArray());

@tonyqus tonyqus removed this from the NPOI 2.7.0 milestone Jul 23, 2023
@tonyqus tonyqus added question and removed bug labels Jul 23, 2023
@tonyqus tonyqus closed this as completed Jul 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants