From d1466728e243b706d4fae2c5eeef2ee867ec4a89 Mon Sep 17 00:00:00 2001 From: Balazs Varga Date: Wed, 22 Apr 2020 14:41:49 +0200 Subject: tdf#132174 Chart DOCX import: fix label number format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The inner data table of charts has no own cell number format, unlike the MSO embedded XLSX, so we always have to set the link number format to false, if we have an inner data table. Regression from commit: 9c1063ba13028244346528e307d5563d6faf949d (tdf#129173 tdf#129175 Fix number format of data labels) Change-Id: I5e7865cb8c19fc6fae5b68305c7dc302516c0ad4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92695 Tested-by: Jenkins Tested-by: László Németh Reviewed-by: Tünde Tóth Reviewed-by: László Németh (cherry picked from commit e0da00d655ecca5986eea3812a8a670c6adbc40f) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93007 Reviewed-by: Xisco Faulí --- chart2/qa/extras/chart2import.cxx | 24 ++++++++++++++++++++++++ chart2/qa/extras/data/docx/tdf132174.docx | Bin 0 -> 13865 bytes oox/source/drawingml/chart/seriesconverter.cxx | 4 ++++ 3 files changed, 28 insertions(+) create mode 100644 chart2/qa/extras/data/docx/tdf132174.docx diff --git a/chart2/qa/extras/chart2import.cxx b/chart2/qa/extras/chart2import.cxx index e637c3272d33..a2b77a851002 100644 --- a/chart2/qa/extras/chart2import.cxx +++ b/chart2/qa/extras/chart2import.cxx @@ -88,6 +88,7 @@ public: // void testTextCanOverlapXLSX(); // TODO : temporarily disabled. void testTextBreakXLSX(); void testNumberFormatsXLSX(); + void testNumberFormatsDOCX(); void testTransparentBackground(OUString const & filename); @@ -200,6 +201,7 @@ public: // CPPUNIT_TEST(testTextCanOverlapXLSX); // TODO : temporarily disabled. CPPUNIT_TEST(testTextBreakXLSX); CPPUNIT_TEST(testNumberFormatsXLSX); + CPPUNIT_TEST(testNumberFormatsDOCX); CPPUNIT_TEST(testAutoTitleDelDefaultValue2007XLSX); CPPUNIT_TEST(testAutoTitleDelDefaultValue2013XLSX); CPPUNIT_TEST(testDispBlanksAsDefaultValue2007XLSX); @@ -1267,6 +1269,28 @@ void Chart2ImportTest::testNumberFormatsXLSX() CPPUNIT_ASSERT_MESSAGE("\"LinkNumberFormatToSource\" should be set to true.", bSuccess && bLinkNumberFormatToSource); } +void Chart2ImportTest::testNumberFormatsDOCX() +{ + load("/chart2/qa/extras/data/docx/", "tdf132174.docx"); + uno::Reference< chart2::XChartDocument > xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY); + CPPUNIT_ASSERT(xChartDoc.is()); + + css::uno::Reference xDiagram(xChartDoc->getFirstDiagram(), UNO_SET_THROW); + Reference xDataSeries = getDataSeriesFromDoc(xChartDoc, 0); + uno::Reference xPropertySet(xDataSeries, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT(xPropertySet.is()); + + sal_Int32 nNumberFormat; + bool bLinkNumberFormatToSource = true; + const sal_Int32 nChartDataNumberFormat = getNumberFormat(xChartDoc, "0%"); + xPropertySet->getPropertyValue(CHART_UNONAME_NUMFMT) >>= nNumberFormat; + CPPUNIT_ASSERT_EQUAL(nChartDataNumberFormat, nNumberFormat); + xPropertySet->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT) >>= bLinkNumberFormatToSource; + // LinkNumberFormatToSource should be set to false even if the OOXML contain a true value, + // because the inner data table of charts have no own number format! + CPPUNIT_ASSERT_MESSAGE("\"LinkNumberFormatToSource\" should be set to false.", !bLinkNumberFormatToSource); +} + void Chart2ImportTest::testAutoTitleDelDefaultValue2007XLSX() { load("/chart2/qa/extras/data/xlsx/", "autotitledel_2007.xlsx"); diff --git a/chart2/qa/extras/data/docx/tdf132174.docx b/chart2/qa/extras/data/docx/tdf132174.docx new file mode 100644 index 000000000000..4f43695784fb Binary files /dev/null and b/chart2/qa/extras/data/docx/tdf132174.docx differ diff --git a/oox/source/drawingml/chart/seriesconverter.cxx b/oox/source/drawingml/chart/seriesconverter.cxx index 1a3936ecb2c9..02479b80ec46 100644 --- a/oox/source/drawingml/chart/seriesconverter.cxx +++ b/oox/source/drawingml/chart/seriesconverter.cxx @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -371,6 +372,9 @@ void DataLabelsConverter::convertFromModel( const Reference< XDataSeries >& rxDa if( !mrModel.mbDeleted ) { bool bMSO2007Doc = getFilter().isMSO2007Document(); + // tdf#132174: the inner data table has no own cell number format. + if( getChartDocument()->hasInternalDataProvider() ) + mrModel.maNumberFormat.mbSourceLinked = false; lclConvertLabelFormatting( aPropSet, getFormatter(), mrModel, rTypeGroup, true, bMSO2007Doc ); if (mrModel.mxShapeProp) -- cgit