diff options
author | Dennis Francis <dennis.francis@collabora.co.uk> | 2017-07-31 10:52:55 +0530 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2017-08-02 07:44:58 +0200 |
commit | d8e731adb8608aab17385e02f4441ed3122efa40 (patch) | |
tree | 52c3a694d6d4e768ace0fdfe6cd87285665218ab | |
parent | 95c2f226b122c7fdb77c6e9085b1fbd02189db03 (diff) |
tdf#90352: set/handle LinkNumberFormatToSource property in xls...
Import/Export filter respectively for axis numbers. For ods and
xlsx this was already getting set/handled correctly.
Also add unit test to assert LinkNumberFormatToSource property
and number format for import and export-import roundtrip.
Change-Id: Id029ac7d0233ca490a6a00609e9cea8fdafee70f
Reviewed-on: https://gerrit.libreoffice.org/40577
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
-rw-r--r-- | chart2/qa/extras/chart2export.cxx | 61 | ||||
-rw-r--r-- | chart2/qa/extras/data/xls/axis_sourceformatting.xls | bin | 0 -> 7168 bytes | |||
-rw-r--r-- | sc/source/filter/excel/xechart.cxx | 6 | ||||
-rw-r--r-- | sc/source/filter/excel/xichart.cxx | 15 | ||||
-rw-r--r-- | sc/source/filter/inc/xlchart.hxx | 1 |
5 files changed, 79 insertions, 4 deletions
diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx index d9050f858c2c..67aa996c89d5 100644 --- a/chart2/qa/extras/chart2export.cxx +++ b/chart2/qa/extras/chart2export.cxx @@ -71,6 +71,7 @@ public: void testFdo78290ScatterChartMarkerX(); void testFdo78290CombinationChartMarkerX(); void testAxisNumberFormatODS(); + void testAxisNumberFormatXLS(); void testDataLabelBordersDOCX(); void testDataLabel3DChartDOCX(); void testDataLabelBarChartDOCX(); @@ -135,6 +136,7 @@ public: CPPUNIT_TEST(testFdo78290ScatterChartMarkerX); CPPUNIT_TEST(testFdo78290CombinationChartMarkerX); CPPUNIT_TEST(testAxisNumberFormatODS); + CPPUNIT_TEST(testAxisNumberFormatXLS); CPPUNIT_TEST(testDataLabelBordersDOCX); CPPUNIT_TEST(testDataLabel3DChartDOCX); CPPUNIT_TEST(testDataLabelBarChartDOCX); @@ -758,6 +760,65 @@ void Chart2ExportTest::testAxisNumberFormatODS() aTest.check(xChartDoc); } +void Chart2ExportTest::testAxisNumberFormatXLS() +{ + struct + { + void check( const Reference<chart2::XChartDocument>& xChartDoc, bool bNumFmtLinkedActual, sal_Int16 nNumFmtTypeFlag ) const + { + Reference<chart2::XAxis> xAxisY = getAxisFromDoc( xChartDoc, 0, 1, 0 ); + bool bNumFmtLinked = false; + Reference<beans::XPropertySet> xPS( xAxisY, uno::UNO_QUERY_THROW ); + xPS->getPropertyValue( "LinkNumberFormatToSource" ) >>= bNumFmtLinked; + + if ( bNumFmtLinkedActual ) + CPPUNIT_ASSERT_MESSAGE( "Y axis should have its number format linked to source.", bNumFmtLinked ); + else + { + CPPUNIT_ASSERT_MESSAGE( "Y axis should not have its number format linked to source.", !bNumFmtLinked ); + + sal_Int32 nNumFmt = getNumberFormatFromAxis( xAxisY ); + sal_Int16 nType = getNumberFormatType( xChartDoc, nNumFmt ); + if ( nNumFmtTypeFlag == util::NumberFormat::PERCENT ) + CPPUNIT_ASSERT_MESSAGE( "Y axis should be percentage format.", ( nType & util::NumberFormat::PERCENT ) ); + else + CPPUNIT_ASSERT_MESSAGE( "Y axis should be number format.", ( nType & util::NumberFormat::NUMBER ) ); + } + } + + void change( const Reference<chart2::XChartDocument>& xChartDoc, bool bSetNumFmtLinked, sal_Int16 nNumFmtTypeFlag ) + { + Reference<chart2::XAxis> xAxisY = getAxisFromDoc( xChartDoc, 0, 1, 0 ); + Reference<beans::XPropertySet> xPS( xAxisY, uno::UNO_QUERY_THROW ); + Any aAny( bSetNumFmtLinked ); + xPS->setPropertyValue( "LinkNumberFormatToSource", aAny ); + if ( !bSetNumFmtLinked ) + { + Reference<util::XNumberFormatsSupplier> xNFS( xChartDoc, uno::UNO_QUERY_THROW ); + Reference<util::XNumberFormats> xNumberFormats = xNFS->getNumberFormats(); + CPPUNIT_ASSERT( xNumberFormats.is() ); + lang::Locale aLocale{ "en", "US", "" }; + Sequence<sal_Int32> aNumFmts = xNumberFormats->queryKeys( nNumFmtTypeFlag, aLocale, false ); + CPPUNIT_ASSERT( aNumFmts.hasElements() ); + aAny <<= aNumFmts[0]; + xPS->setPropertyValue( CHART_UNONAME_NUMFMT, aAny ); + } + } + + } aTest; + + load( "/chart2/qa/extras/data/xls/", "axis_sourceformatting.xls" ); + + Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet( 0, mxComponent ); + aTest.check( xChartDoc, true, util::NumberFormat::PERCENT ); + + aTest.change( xChartDoc, false, util::NumberFormat::NUMBER ); + // Write the document(xls) with changes made close it, load it and check if changes are intact + reload( "MS Excel 97" ); + xChartDoc = getChartDocFromSheet( 0, mxComponent ); + aTest.check( xChartDoc, false, util::NumberFormat::NUMBER ); +} + void Chart2ExportTest::testDataLabelBordersDOCX() { struct Check diff --git a/chart2/qa/extras/data/xls/axis_sourceformatting.xls b/chart2/qa/extras/data/xls/axis_sourceformatting.xls Binary files differnew file mode 100644 index 000000000000..2ee38b720857 --- /dev/null +++ b/chart2/qa/extras/data/xls/axis_sourceformatting.xls diff --git a/sc/source/filter/excel/xechart.cxx b/sc/source/filter/excel/xechart.cxx index 3cdbd6e5006c..4d250593c33f 100644 --- a/sc/source/filter/excel/xechart.cxx +++ b/sc/source/filter/excel/xechart.cxx @@ -3002,7 +3002,11 @@ void XclExpChAxis::Convert( Reference< XAxis > const & xAxis, Reference< XAxis > // axis number format sal_Int32 nApiNumFmt = 0; if( !bCategoryAxis && aAxisProp.GetProperty( nApiNumFmt, EXC_CHPROP_NUMBERFORMAT ) ) - mnNumFmtIdx = GetNumFmtBuffer().Insert( static_cast< sal_uInt32 >( nApiNumFmt ) ); + { + bool bLinkNumberFmtToSource = false; + if ( !aAxisProp.GetProperty( bLinkNumberFmtToSource, EXC_CHPROP_NUMBERFORMAT_LINKSRC ) || !bLinkNumberFmtToSource ) + mnNumFmtIdx = GetNumFmtBuffer().Insert( static_cast< sal_uInt32 >( nApiNumFmt ) ); + } // grid ------------------------------------------------------------------- diff --git a/sc/source/filter/excel/xichart.cxx b/sc/source/filter/excel/xichart.cxx index cb04ee83c429..6e51af689c1a 100644 --- a/sc/source/filter/excel/xichart.cxx +++ b/sc/source/filter/excel/xichart.cxx @@ -3323,9 +3323,18 @@ Reference< XAxis > XclImpChAxis::CreateAxis( const XclImpChTypeGroup& rTypeGroup // label text rotation ConvertRotationBase( aAxisProp, true ); // number format - sal_uInt32 nScNumFmt = GetNumFmtBuffer().GetScFormat( mnNumFmtIdx ); - if( nScNumFmt != NUMBERFORMAT_ENTRY_NOT_FOUND ) - aAxisProp.SetProperty( EXC_CHPROP_NUMBERFORMAT, static_cast< sal_Int32 >( nScNumFmt ) ); + bool bLinkNumberFmtToSource = true; + if ( mnNumFmtIdx != EXC_FORMAT_NOTFOUND ) + { + sal_uInt32 nScNumFmt = GetNumFmtBuffer().GetScFormat( mnNumFmtIdx ); + if( nScNumFmt != NUMBERFORMAT_ENTRY_NOT_FOUND ) + { + aAxisProp.SetProperty( EXC_CHPROP_NUMBERFORMAT, static_cast< sal_Int32 >( nScNumFmt ) ); + bLinkNumberFmtToSource = false; + } + } + + aAxisProp.SetProperty( EXC_CHPROP_NUMBERFORMAT_LINKSRC, bLinkNumberFmtToSource ); } // axis scaling and increment ----------------------------------------- diff --git a/sc/source/filter/inc/xlchart.hxx b/sc/source/filter/inc/xlchart.hxx index 32bbc177e926..67cc3646e379 100644 --- a/sc/source/filter/inc/xlchart.hxx +++ b/sc/source/filter/inc/xlchart.hxx @@ -96,6 +96,7 @@ class XclRoot; #define EXC_CHPROP_MOVING_AVERAGE_PERIOD "MovingAveragePeriod" #define EXC_CHPROP_NEGATIVEERROR "NegativeError" #define EXC_CHPROP_NUMBERFORMAT "NumberFormat" +#define EXC_CHPROP_NUMBERFORMAT_LINKSRC "LinkNumberFormatToSource" #define EXC_CHPROP_OFFSET "Offset" #define EXC_CHPROP_OVERLAPSEQ "OverlapSequence" #define EXC_CHPROP_PERCENTAGENUMFMT "PercentageNumberFormat" |