Java 使用apache poi更新word 2010中的自定义属性
设置新值后,我需要使用ApachePOI更新自定义属性 我有一个为自定义属性设置新值的方法:Java 使用apache poi更新word 2010中的自定义属性,java,ms-word,apache-poi,Java,Ms Word,Apache Poi,设置新值后,我需要使用ApachePOI更新自定义属性 我有一个为自定义属性设置新值的方法: InputStream fs = new FileInputStream("D://test.docx"); XWPFDocument document = new XWPFDocument(OPCPackage.open(fs)); POIXMLProperties props = document.getProperties(); CustomPropert
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();
InputStream fs=newfileinputstream(“D://test.docx”);
XWPFDocument document=新的XWPFDocument(OPCPackage.open(fs));
POIXMLProperties props=document.getProperties();
CustomProperties cp=props.getCustomProperties();
如果(cp!=null){
List ctProperties=cp.getUnderlineProperties()
.getPropertyList();
对于(CTProperty ctp:ctProperties){
System.out.println(ctp.getName());
if(ctp.getName().equals(“测试”)){
ctp.setLpwstr(“测试”);
}
}
}
write(新文件输出流(新文件(“D://test.docx”));
fs.close();
但是当我打开文档属性值时,它就过时了。我必须手动更新它们
有一种方法可以使用ApachePOI自动更新属性值?
谢谢
另外,很抱歉我的英语不好。我也有同样的问题,但我解决了打电话的问题:
document.enforceUpdateFields();
当用户打开文档时,将打开一个确认窗口,其中显示字段的更新。您是否在Windows上运行?如果是这样的话,请尝试写入另一个命名文件,因为Windows对于同时读取和写入文件非常有趣file@Gagravarr它发生在linux上,你能把它转换成一个小的junit单元测试来显示问题吗?如有,请以书面形式报告