aboutsummaryrefslogtreecommitdiffstats
path: root/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotCache.java
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2014-07-30 15:27:09 +0000
committerNick Burch <nick@apache.org>2014-07-30 15:27:09 +0000
commit939bc4442d6ae24acdd822c7f76fb7b1a56cec4e (patch)
treea8784a66f80aec5617dd04837e211f62d14c673e /src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotCache.java
parente7fcfa03eb72afa05f593c8a4bf82c92269d5dac (diff)
downloadpoi-939bc4442d6ae24acdd822c7f76fb7b1a56cec4e.tar.gz
poi-939bc4442d6ae24acdd822c7f76fb7b1a56cec4e.zip
Patch from Sofia Larsson and Martin Andersson from bug #56020 - XSSF support for creating Pivot tables
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1614684 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotCache.java')
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotCache.java78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotCache.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotCache.java
new file mode 100644
index 0000000000..e5896e73a1
--- /dev/null
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotCache.java
@@ -0,0 +1,78 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.xssf.usermodel;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.poi.POIXMLDocumentPart;
+import static org.apache.poi.POIXMLDocumentPart.DEFAULT_XML_OPTIONS;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.util.Beta;
+
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlOptions;
+
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotCache;
+
+public class XSSFPivotCache extends POIXMLDocumentPart {
+
+ private CTPivotCache ctPivotCache;
+
+ @Beta
+ public XSSFPivotCache(){
+ super();
+ ctPivotCache = CTPivotCache.Factory.newInstance();
+ }
+
+ @Beta
+ public XSSFPivotCache(CTPivotCache ctPivotCache) {
+ super();
+ this.ctPivotCache = ctPivotCache;
+ }
+
+ /**
+ * Creates n XSSFPivotCache representing the given package part and relationship.
+ * Should only be called when reading in an existing file.
+ *
+ * @param part - The package part that holds xml data representing this pivot cache definition.
+ * @param rel - the relationship of the given package part in the underlying OPC package
+ */
+ @Beta
+ protected XSSFPivotCache(PackagePart part, PackageRelationship rel) throws IOException {
+ super(part, rel);
+ readFrom(part.getInputStream());
+ }
+
+ @Beta
+ protected void readFrom(InputStream is) throws IOException {
+ try {
+ XmlOptions options = new XmlOptions(DEFAULT_XML_OPTIONS);
+ //Removing root element
+ options.setLoadReplaceDocumentElement(null);
+ ctPivotCache = CTPivotCache.Factory.parse(is, options);
+ } catch (XmlException e) {
+ throw new IOException(e.getLocalizedMessage());
+ }
+ }
+
+ @Beta
+ public CTPivotCache getCTPivotCache() {
+ return ctPivotCache;
+ }
+} \ No newline at end of file