summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2014-08-29 17:43:00 -0400
committerKohei Yoshida <kohei.yoshida@collabora.com>2014-08-29 18:24:32 -0400
commitf37c6e0d111c2237d422be07acbb67b7d0dcbbeb (patch)
tree417f06c784019fcabc08e256359ab9635db5af77
parent3b856f028735d292c9b02168704d4a07e2f43cd5 (diff)
Correctly export subtotal functions of data fields.
Take note that data field may be duplicated. Change-Id: I8f787075869f38d0101da2787bac315c71d8a6e8
-rw-r--r--sc/source/filter/excel/xepivotxml.cxx62
1 files changed, 57 insertions, 5 deletions
diff --git a/sc/source/filter/excel/xepivotxml.cxx b/sc/source/filter/excel/xepivotxml.cxx
index 5ff871a517a6..3f7d320b4cff 100644
--- a/sc/source/filter/excel/xepivotxml.cxx
+++ b/sc/source/filter/excel/xepivotxml.cxx
@@ -18,6 +18,7 @@
#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
#include <com/sun/star/sheet/DataPilotOutputRangeType.hpp>
+#include <com/sun/star/sheet/GeneralFunction.hpp>
#include <vector>
@@ -74,6 +75,40 @@ const char* toOOXMLAxisType( sheet::DataPilotFieldOrientation eOrient )
return "";
}
+const char* toOOXMLSubtotalType( sheet::GeneralFunction eFunc )
+{
+ switch (eFunc)
+ {
+ case sheet::GeneralFunction_SUM:
+ return "sum";
+ case sheet::GeneralFunction_COUNT:
+ return "count";
+ case sheet::GeneralFunction_AVERAGE:
+ return "average";
+ case sheet::GeneralFunction_MAX:
+ return "max";
+ case sheet::GeneralFunction_MIN:
+ return "min";
+ case sheet::GeneralFunction_PRODUCT:
+ return "product";
+ case sheet::GeneralFunction_COUNTNUMS:
+ return "countNums";
+ case sheet::GeneralFunction_STDEV:
+ return "stdDev";
+ case sheet::GeneralFunction_STDEVP:
+ return "stdDevp";
+ case sheet::GeneralFunction_VAR:
+ return "var";
+ case sheet::GeneralFunction_VARP:
+ return "varp";
+ case sheet::GeneralFunction_NONE:
+ case sheet::GeneralFunction_AUTO:
+ default:
+ ;
+ }
+ return NULL;
+}
+
}
XclExpXmlPivotCaches::XclExpXmlPivotCaches( const XclExpRoot& rRoot ) :
@@ -354,6 +389,18 @@ void XclExpXmlPivotTables::SaveXml( XclExpXmlStream& rStrm )
}
}
+namespace {
+
+struct DataField
+{
+ long mnPos; // field index in pivot cache.
+ const ScDPSaveDimension* mpDim;
+
+ DataField( long nPos, const ScDPSaveDimension* pDim ) : mnPos(nPos), mpDim(pDim) {}
+};
+
+}
+
void XclExpXmlPivotTables::SavePivotTableXml( XclExpXmlStream& rStrm, const ScDPObject& rDPObj, sal_Int32 nCacheId )
{
typedef boost::unordered_map<OUString, long, OUStringHash> NameToIdMapType;
@@ -383,7 +430,7 @@ void XclExpXmlPivotTables::SavePivotTableXml( XclExpXmlStream& rStrm, const ScDP
std::vector<long> aRowFields;
std::vector<long> aColFields;
std::vector<long> aPageFields;
- std::vector<long> aDataFields;
+ std::vector<DataField> aDataFields;
// Use dimensions in the save data to get their correct ordering.
// Dimension order here is significant as they specify the order of
@@ -426,7 +473,7 @@ void XclExpXmlPivotTables::SavePivotTableXml( XclExpXmlStream& rStrm, const ScDP
aPageFields.push_back(nPos);
break;
case sheet::DataPilotFieldOrientation_DATA:
- aDataFields.push_back(nPos);
+ aDataFields.push_back(DataField(nPos, &rDim));
break;
case sheet::DataPilotFieldOrientation_HIDDEN:
default:
@@ -607,12 +654,12 @@ void XclExpXmlPivotTables::SavePivotTableXml( XclExpXmlStream& rStrm, const ScDP
XML_count, OString::number(static_cast<long>(aDataFields.size())),
FSEND);
- std::vector<long>::iterator it = aDataFields.begin(), itEnd = aDataFields.end();
+ std::vector<DataField>::iterator it = aDataFields.begin(), itEnd = aDataFields.end();
for (; it != itEnd; ++it)
{
- long nDimIdx = *it;
+ long nDimIdx = it->mnPos;
assert(aCachedDims[nDimIdx]); // the loop above should have screened for NULL's.
- const ScDPSaveDimension& rDim = *aCachedDims[nDimIdx];
+ const ScDPSaveDimension& rDim = *it->mpDim;
const OUString* pName = rDim.GetLayoutName();
pPivotStrm->write("<")->writeId(XML_dataField);
if (pName)
@@ -620,6 +667,11 @@ void XclExpXmlPivotTables::SavePivotTableXml( XclExpXmlStream& rStrm, const ScDP
rStrm.WriteAttributes(XML_fld, OString::number(nDimIdx).getStr(), FSEND);
+ sheet::GeneralFunction eFunc = static_cast<sheet::GeneralFunction>(rDim.GetFunction());
+ const char* pSubtotal = toOOXMLSubtotalType(eFunc);
+ if (pSubtotal)
+ rStrm.WriteAttributes(XML_subtotal, pSubtotal, FSEND);
+
pPivotStrm->write("/>");
}