summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2019-03-11 16:30:36 +0100
committerLászló Németh <nemeth@numbertext.org>2019-03-12 13:16:00 +0100
commitf684c074d5f66c8b1546a626766bc045c04cebc3 (patch)
tree0178d1ba6514a79effff58dbcc6a9320ff781f3b /oox
parentadb08e892b37ea9e155abbdee4e0c9951a1d163b (diff)
tdf#115012 XLSX chart import: workaround for no gap
DispBlanksAs=gap mode of OOXML is different from treat-empty-cells=leave-gap mode of OpenDocument, because formulas with no numerical values and strings are no gaps in OOXML line charts, but zeroes. When the data source of the line charts contains formulas with no numerical values or strings, but it doesn't contain empty cells, as a workaround, the charts will be imported with the treat-empty-cells=use-zero setting to get the same line chart as in MSO. Note: now result of ScChart2DataSequence::getData(), a sequence of Any values contains UNO void values for empty cells instead empty strings, allowing the distinction of the empty cells and cells with empty string values. Change-Id: If9a101d66b5b750051928fa7b10b05cea6040071 Reviewed-on: https://gerrit.libreoffice.org/69054 Tested-by: Jenkins Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'oox')
-rw-r--r--oox/source/drawingml/chart/chartspaceconverter.cxx85
1 files changed, 85 insertions, 0 deletions
diff --git a/oox/source/drawingml/chart/chartspaceconverter.cxx b/oox/source/drawingml/chart/chartspaceconverter.cxx
index 6ddbb2ab76bb..2e2c8bc3885b 100644
--- a/oox/source/drawingml/chart/chartspaceconverter.cxx
+++ b/oox/source/drawingml/chart/chartspaceconverter.cxx
@@ -22,6 +22,10 @@
#include <com/sun/star/chart/MissingValueTreatment.hpp>
#include <com/sun/star/chart/XChartDocument.hpp>
#include <com/sun/star/chart2/XChartDocument.hpp>
+#include <com/sun/star/chart2/XChartType.hpp>
+#include <com/sun/star/chart2/XChartTypeContainer.hpp>
+#include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
+#include <com/sun/star/chart2/XDataSeriesContainer.hpp>
#include <com/sun/star/chart2/XTitled.hpp>
#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
#include <com/sun/star/drawing/FillStyle.hpp>
@@ -67,6 +71,82 @@ ChartSpaceConverter::~ChartSpaceConverter()
{
}
+// Formulas with no numeric values and strings are zeroes in OOXML line charts also in the mode DispBlanksAs=gap,
+// unlike in OpenDocument LEAVE_GAP mode. As a workaround, we will use the OpenDocument mode USE_ZERO, if the OOXML
+// line chart has got formulas with no numeric values and strings, but it doesn't have empty cells, showing the
+// same chart as in MSO. (Empty cells need gaps, so in that case, we cannot use this workaround).
+static bool lcl_useWorkaroundForNoGapInOOXML( Reference< chart2::XChartDocument > const & xChartDoc)
+{
+ Reference <chart2::XDiagram > xDiagram = xChartDoc->getFirstDiagram();
+ if ( !xDiagram.is() )
+ return false;
+
+ Reference< chart2::XCoordinateSystemContainer > xCooSysContainer( xDiagram, UNO_QUERY_THROW );
+
+ Sequence< Reference< chart2::XCoordinateSystem > > xCooSysSequence( xCooSysContainer->getCoordinateSystems());
+ if ( xCooSysSequence.getLength() == 0 )
+ return false;
+
+ Reference< chart2::XChartTypeContainer > xChartTypeContainer( xCooSysSequence[0], UNO_QUERY_THROW );
+
+ Sequence< Reference< chart2::XChartType > > xChartTypeSequence( xChartTypeContainer->getChartTypes() );
+ if ( xChartTypeSequence.getLength() == 0 )
+ return false;
+
+ const Reference<chart2::XChartType>& xCT = xChartTypeSequence[0];
+
+ if ( xCT->getChartType() != "com.sun.star.chart2.LineChartType" )
+ return false;
+
+ Reference<chart2::XDataSeriesContainer> xDSCont(xCT, uno::UNO_QUERY);
+
+ if (!xDSCont.is())
+ return false;
+
+ Sequence<uno::Reference<chart2::XDataSeries> > aDataSeriesSeq = xDSCont->getDataSeries();
+
+ bool bHasNoGapBlankValue = false;
+ bool bHasEmptyCell = false;
+
+ for (sal_Int32 i = 0; i < aDataSeriesSeq.getLength(); ++i)
+ {
+ uno::Reference<chart2::data::XDataSource> xDSrc(aDataSeriesSeq[i], uno::UNO_QUERY);
+ if (!xDSrc.is())
+ return false;
+
+ uno::Sequence<Reference<chart2::data::XLabeledDataSequence> > aDataSeqs = xDSrc->getDataSequences();
+ for (sal_Int32 j = 0; j < aDataSeqs.getLength(); ++j)
+ {
+ Reference<chart2::data::XDataSequence> xValues = aDataSeqs[j]->getValues();
+ if(!xValues.is())
+ return false;
+ Reference<beans::XPropertySet> xPropSet(xValues, uno::UNO_QUERY);
+ if (!xPropSet.is())
+ continue;
+
+ OUString aRoleName;
+ xPropSet->getPropertyValue("Role") >>= aRoleName;
+ if (aRoleName == "values-y")
+ {
+ uno::Sequence<uno::Any> aData = xValues->getData();
+ for (sal_Int32 nVal = 0; nVal < aData.getLength(); ++nVal)
+ {
+ double fVal;
+ OUString sStr;
+ if (aData[nVal] >>= fVal)
+ continue;
+ else if (aData[nVal] >>= sStr)
+ bHasNoGapBlankValue = true;
+ else
+ bHasEmptyCell = true;
+ }
+ }
+ }
+ }
+
+ return bHasNoGapBlankValue && !bHasEmptyCell;
+}
+
void ChartSpaceConverter::convertFromModel( const Reference< XShapes >& rxExternalPage, const awt::Point& rChartPos )
{
/* create data provider (virtual function in the ChartConverter class,
@@ -132,6 +212,11 @@ void ChartSpaceConverter::convertFromModel( const Reference< XShapes >& rxExtern
case XML_zero: nMissingValues = USE_ZERO; break;
case XML_span: nMissingValues = CONTINUE; break;
}
+
+ // use a workaround, if it's possible for the difference of OOXML and OpenDocument
+ if ( nMissingValues == LEAVE_GAP && lcl_useWorkaroundForNoGapInOOXML(getChartDocument()) )
+ nMissingValues = USE_ZERO;
+
PropertySet aDiaProp( xDiagram );
aDiaProp.setProperty( PROP_MissingValueTreatment, nMissingValues );
}