aboutsummaryrefslogtreecommitdiffstats
path: root/src/ooxml
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2012-01-11 15:51:10 +0000
committerNick Burch <nick@apache.org>2012-01-11 15:51:10 +0000
commit9d68c28c694fbc7f0d8614a81d557cec3b93c295 (patch)
treeb585817b1dd5d3121882b7749f858144562cb5f0 /src/ooxml
parent57c4509faabf7025bc52ecfe90684512b2cf01a4 (diff)
downloadpoi-9d68c28c694fbc7f0d8614a81d557cec3b93c295.tar.gz
poi-9d68c28c694fbc7f0d8614a81d557cec3b93c295.zip
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
Diffstat (limited to 'src/ooxml')
-rw-r--r--src/ooxml/java/org/apache/poi/POIXMLPropertiesTextExtractor.java39
-rw-r--r--src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java17
2 files changed, 50 insertions, 6 deletions
diff --git a/src/ooxml/java/org/apache/poi/POIXMLPropertiesTextExtractor.java b/src/ooxml/java/org/apache/poi/POIXMLPropertiesTextExtractor.java
index 22ff8902c3..05528f6285 100644
--- a/src/ooxml/java/org/apache/poi/POIXMLPropertiesTextExtractor.java
+++ b/src/ooxml/java/org/apache/poi/POIXMLPropertiesTextExtractor.java
@@ -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"
);
}
diff --git a/src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java b/src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java
index b19477f04c..8ad2f78c4b 100644
--- a/src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java
+++ b/src/ooxml/testcases/org/apache/poi/TestXMLPropertiesTextExtractor.java
@@ -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"));
}
/**