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

Word can not open docx due to incorrect serialization for CT_Point2D when used in CT_Anchor for CT_Drawing #1498

Open
1 of 5 tasks
paulhahn-rapiddata opened this issue Feb 27, 2025 · 2 comments

Comments

@paulhahn-rapiddata
Copy link

paulhahn-rapiddata commented Feb 27, 2025

NPOI Version

2.7.2

File Type

  • XLSX
  • XLS
  • DOCX
  • XLSM
  • OTHER

Reproduce Steps

  1. Add drawing to your document
  2. anchor the drawing
  3. Set CT_Anchor.simplePos to an instance of CT_Point2D

This will create a tag:
<a:simplePos x="0" y="0" />
as child of the anchor tag.

Issue Description

The modified document can not be opened by word. If manually editing the tag to this:
<wp:simplePos x="0" y="0" />
word will be able to open and display the document.

I assume that this a tag should be a wp tag instead, but i am not a docx expert.
Here is the NPOI code line that would need the change from a to wp:

sw.Write(string.Format("<a:{0}", nodeName));

I tried to circumvent the issue by setting simplePos to null, which generates the anchor without the tag. However, this will also not be accepted by word.

This means that effectively it is not possible to anchor a drawing with NPOI, potentially other elements as well.

@tonyqus
Copy link
Member

tonyqus commented Feb 27, 2025

Can you create a PR for this?

@paulhahn-rapiddata
Copy link
Author

paulhahn-rapiddata commented Feb 28, 2025

I noticed the file with the problem was generated with Xsd2Code, so it might be better to regenerate the file and ensure the source is correct. Otherwise this change would risk being overwritten next time the file is regenerated.

I used OpenXml to fix this issue in post for my generated documents and can confirm that it also create a wp-tag, not "a". Question is why it was generated this way by the tool.

I could create a PR for the one-line change, if you still think that it makes sense to do so. But I do not know how to use Xsd2Code.

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