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

XWPFRun类的AddPicture方法在某种情况下会造成文档打开异常 #443

Closed
sid033 opened this issue Oct 18, 2020 · 2 comments
Closed

Comments

@sid033
Copy link

sid033 commented Oct 18, 2020

问题描述:我在导出图片到word表格内的时候,只要有图片的表格,在word就无法打开,提示/word/document.xml的某一行某一列xml有错误。
使用情景:数据库中事件,附有若干图片。我把事件导出成一个word表格,把若干张图片存放在表格某一单元格内。
问题分析:我首先把docx文件解压出来,把document.xml用文本打开,想办法定位该处错误。结果发现该处提示的错误附近的xml从形式上是没有问题的。然后我就用word新建了一个文档,在表格内插入图片。然后再重复刚才的方法,把这个新文件和旧文件对比,发现通过程序生成的word的document.xml文档中首个图片的段落中缺失id属性。于是我把文件中手动添加了一个id属性,并令这个id与其他id不重复。结果成功打开文件。定位的xml段为<wp:docPr name="Drawing 0" descr="当心爆炸"/>变成<wp:docPr id="26" name="Drawing 0" descr="当心爆炸"/>。仔细测试了一下,发现是第一张图片没有这个id属性。其他的图片都有。所以我猜是边界可能没处理好。

@sid033
Copy link
Author

sid033 commented Oct 18, 2020

npoi版本2.5.1.word版本2007build12.0.6787.5000

@tonyqus
Copy link
Member

tonyqus commented Oct 18, 2020

这问题应该已经修复
duplicate with #373

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