<changes>
<release version="3.8-beta6" date="2012-??-??">
+ <action dev="poi-developers" type="add">POIXMLPropertiesTextExtractor support for extracting custom OOXML properties as text</action>
<action dev="poi-developers" type="fix">52449 - Support writing XWPF documents with glossaries (Glossaries are not yet supported, but can now be written out again without changes)</action>
<action dev="poi-developers" type="fix">52446 - Handle files which have been truncated by a few bytes in NPropertyTable</action>
<action dev="poi-developers" type="fix">52438 - Update CellDateFormatter to handle times without seconds</action>
import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
import org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperty;
+import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
props = getDocument().getProperties().getCustomProperties().getUnderlyingProperties();
List<CTProperty> properties = props.getPropertyList();
- for(int i = 0; i<properties.size(); i++) {
- // TODO - finish off
+ for(CTProperty property : properties) {
String val = "(not implemented!)";
-
+
+ if (property.isSetLpwstr()) {
+ val = property.getLpwstr();
+ }
+ else if (property.isSetFiletime()) {
+ val = property.getFiletime().toString();
+ }
+ else if (property.isSetDate()) {
+ val = property.getDate().toString();
+ }
+ else if (property.isSetDecimal()) {
+ BigDecimal d = property.getDecimal();
+ if (d == null) {
+ val = null;
+ } else {
+ val = d.toPlainString();
+ }
+ }
+ else if (property.isSetBool()) {
+ val = Boolean.toString( property.getBool() );
+ }
+ else if (property.isSetInt()) {
+ val = Integer.toString( property.getInt() );
+ }
+ else if (property.isSetLpstr()) {
+ val = property.getLpstr();
+ }
+ else if (property.isSetI4()) {
+ /* Number in Excel for example.... Why i4 ? Ask microsoft. */
+ val = Integer.toString(property.getI4());
+ }
+
text.append(
- properties.get(i).getName() +
+ property.getName() +
" = " + val + "\n"
);
}
assertTrue(eText.contains("Company = Mera"));
}
- public void testCustom() {
- // TODO!
+ public void testCustom() throws Exception {
+ OPCPackage pkg = OPCPackage.open(
+ _ssSamples.openResourceAsStream("ExcelWithAttachments.xlsm")
+ );
+ XSSFWorkbook wb = new XSSFWorkbook(pkg);
+
+ POIXMLPropertiesTextExtractor ext = new POIXMLPropertiesTextExtractor(wb);
+ ext.getText();
+
+ // Now check
+ String text = ext.getText();
+ String cText = ext.getCustomPropertiesText();
+
+ assertTrue(text.contains("description = another value"));
+ assertTrue(cText.contains("description = another value"));
}
/**