c# - 为什么用 npoi 编辑后 docx 文件损坏
问题描述
我想编辑 .docx 文件并使用 npoi 库。
是一个片段:
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();
}
但我得到了损坏的文件。当我尝试打开文件时,显示模式窗口:“我们很抱歉。我们无法打开 test.docx,我们发现其内容有问题。详细信息:未指定的错误。位置:/word/header1.xml,行:0 , 栏目: 0"
先感谢您
==================================================== ==========
更新:
问题出在模板文件中。如果我从页眉和页脚中删除图像,那么错误就会消失。但是,如果我将模板图像放回错误返回。有任何想法吗?
==================================================== ===========
更新:
当图像属性“Wrap Text”的值不是“In Line With Text”时,就会出现此问题。在我的情况下,图像是文本的背景。(“文本后面”值)。
解决方案
不确定你是否还需要它。 但是我修复了其中一些错误,这些错误与https://github.com/nissl-lab/npoi/pull/510中的换行文本图像有关, 让我知道。
推荐阅读
- javascript - 为什么我没有完成 POSTMAN 的 PUT 请求?
- javascript - 如何按年份将数据与付费和未付费值分组
- javascript - 如何定义一个可以在打字稿中未定义的变量?
- excel - 通过python访问excel文件时如何让excel中的rand()函数重新运行
- python - 如何注册要在垃圾收集 (GC) 开始并完成时调用的 python 函数?
- verilog - 输出处于未定义状态
- r - 在 R 中创建一个绑定指数列
- json - 如何使用本地路径将图像存储在 json 文件中?
- asp.net-mvc - 如何使 ASP.NET Core MVC 路由生成相对?
- javascript - 添加新元素后附加元素消失,点击 addEventListener