POIXMLPropertiesTextExtractor support for extracting custom OOXML properties as text
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1230106 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
477ae958e3
commit
2a22882dff
@ -34,6 +34,7 @@
|
||||
|
||||
<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>
|
||||
|
@ -20,6 +20,7 @@ package org.apache.poi;
|
||||
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;
|
||||
|
||||
@ -131,12 +132,42 @@ public class POIXMLPropertiesTextExtractor extends POIXMLTextExtractor {
|
||||
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"
|
||||
);
|
||||
}
|
||||
|
@ -84,8 +84,21 @@ public final class TestXMLPropertiesTextExtractor extends TestCase {
|
||||
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"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user