我正在尝试将一些自定义属性添加到现有文档中:
HWPFDocument document = new HWPFDocument(new FileInputStream(sourceFile));
DocumentSummaryInformation docSumInf = document.getDocumentSummaryInformation();
CustomProperties customProperties = docSumInf.getCustomProperties();
CustomProperty singleProp = null;
//...
singleProp = new CustomProperty();
singleProp.setName(entry.getKey());
singleProp.setType(Variant.VT_LPWSTR);
singleProp.setValue((String) entry.getValue());
//..
customProperties.put(entry.getKey(), singleProp);
docSumInf.setCustomProperties(customProperties);
return document;
但是,这些属性永远不会进入文件。我尝试过了
document.getDocumentSummaryInformation().getCustomProperties().putAll(customProperties);
我也试过
document.getDocumentSummaryInformation().getCustomProperties().put(entry.getKey(), singleProp);
System.out.println(document.getDocumentSummaryInformation().getCustomProperties().size() + " Elemente in Map");
在一个循环中。打印的尺寸总是一。
第一次尝试 (docSumInf.setCustomProperties(customProperties);) 在将其设置为 docSumInf 之前,我打印出了 customProperties。一旦我将它们设置为文档摘要,我就会错过所有新属性。
我没有看到我错过了什么......