【发布时间】:2014-03-04 09:49:45
【问题描述】:
设置新值后,我需要使用 Apache Poi 更新自定义属性。
我有为自定义属性设置新值的方法:
InputStream fs = new FileInputStream("D://test.docx");
XWPFDocument document = new XWPFDocument(OPCPackage.open(fs));
POIXMLProperties props = document.getProperties();
CustomProperties cp = props.getCustomProperties();
if (cp != null) {
List<CTProperty> ctProperties = cp.getUnderlyingProperties()
.getPropertyList();
for (CTProperty ctp : ctProperties) {
System.out.println(ctp.getName());
if (ctp.getName().equals("Test")) {
ctp.setLpwstr("Test");
}
}
}
document.write(new FileOutputStream(new File("D://test.docx")));
fs.close();
但是当我打开文档时,属性值已经过时了。而且我必须手动更新它们。
有没有一种方法可以使用 Apache Poi 自动更新属性值? 谢谢!
附:对不起我的英语不好。
【问题讨论】:
-
您在 Windows 上运行吗?如果是这样,请尝试写入不同的命名文件,因为 Windows 对同时读取和写入文件很有趣
-
@Gagravarr 它也发生在 linux ubuntu 上
-
你能把它变成一个显示问题的小型junit单元测试吗?如果是这样,请将其报告为bug in the Apache POI bug database
标签: java ms-word apache-poi