chart2/qa/extras/chart2export2.cxx | 11 +++++++ chart2/qa/extras/data/xlsx/column-style.xlsx |binary chart2/source/controller/chartapiwrapper/DiagramWrapper.cxx | 10 ++++++ chart2/source/model/main/Diagram.cxx | 7 ++++ oox/inc/drawingml/chart/chartspacemodel.hxx | 1 oox/source/drawingml/chart/chartspaceconverter.cxx | 7 ++++ oox/source/drawingml/chart/chartspacefragment.cxx | 1 oox/source/drawingml/chart/chartspacemodel.cxx | 1 oox/source/export/chartexport.cxx | 18 +++++++++++- oox/source/token/properties.txt | 1 10 files changed, 54 insertions(+), 3 deletions(-)
New commits: commit 38fb2f70fe833be87ca14a1cee653f40c37b7f9a Author: Kurt Nordback <kurt.nordb...@collabora.com> AuthorDate: Thu Jul 3 07:06:05 2025 -0600 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Mon Aug 18 21:47:52 2025 +0200 tdf#167368 - Chart style index is not exported to OOXML Add support for style index export, and a CI test for this. Change-Id: Idb109ef705a6bf8338e18040d447c2806c0781ee Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187425 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> (cherry picked from commit 4313451fc77f641dc63a8b32edb03c6aa2636ae9) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187751 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> diff --git a/chart2/qa/extras/chart2export2.cxx b/chart2/qa/extras/chart2export2.cxx index f369661c5441..93492645afc4 100644 --- a/chart2/qa/extras/chart2export2.cxx +++ b/chart2/qa/extras/chart2export2.cxx @@ -929,6 +929,17 @@ CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testTdf123206_customLabelText) u"kiscica"); } +CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, test_style) +{ + loadFromFile(u"xlsx/column-style.xlsx"); + + save(u"Calc Office Open XML"_ustr); + xmlDocUniquePtr pXmlDoc = parseExport(u"xl/charts/chart1.xml"_ustr); + CPPUNIT_ASSERT(pXmlDoc); + // workaround: use leave-gap instead of zero to show the original line chart + assertXPath(pXmlDoc, "/c:chartSpace/c:style", "val", u"23"); +} + CPPUNIT_TEST_FIXTURE(Chart2ExportTest2, testCustomLabelText) { loadFromFile(u"docx/testCustomlabeltext.docx"); diff --git a/chart2/qa/extras/data/xlsx/column-style.xlsx b/chart2/qa/extras/data/xlsx/column-style.xlsx new file mode 100644 index 000000000000..95da9c97caa8 Binary files /dev/null and b/chart2/qa/extras/data/xlsx/column-style.xlsx differ diff --git a/chart2/source/controller/chartapiwrapper/DiagramWrapper.cxx b/chart2/source/controller/chartapiwrapper/DiagramWrapper.cxx index ea38fcc87735..c7f6ef51ebfb 100644 --- a/chart2/source/controller/chartapiwrapper/DiagramWrapper.cxx +++ b/chart2/source/controller/chartapiwrapper/DiagramWrapper.cxx @@ -141,7 +141,8 @@ enum PROP_DIAGRAM_HAS_SECOND_Y_AXIS_TITLE, PROP_DIAGRAM_AUTOMATIC_SIZE, - PROP_DIAGRAM_EXTERNALDATA + PROP_DIAGRAM_EXTERNALDATA, + PROP_DIAGRAM_STYLE_INDEX }; void lcl_AddPropertiesToVector( @@ -393,11 +394,18 @@ void lcl_AddPropertiesToVector( beans::PropertyAttribute::BOUND | beans::PropertyAttribute::MAYBEDEFAULT ); + // chartSpace properties rOutProperties.emplace_back( "ExternalData", PROP_DIAGRAM_EXTERNALDATA, cppu::UnoType<OUString>::get(), beans::PropertyAttribute::BOUND | beans::PropertyAttribute::MAYBEVOID ); + + rOutProperties.emplace_back( "StyleIndex", + PROP_DIAGRAM_STYLE_INDEX, + cppu::UnoType<sal_Int32>::get(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID ); } const Sequence< Property >& StaticDiagramWrapperPropertyArray() diff --git a/chart2/source/model/main/Diagram.cxx b/chart2/source/model/main/Diagram.cxx index c3c4e0be9cc6..0dab2b29723f 100644 --- a/chart2/source/model/main/Diagram.cxx +++ b/chart2/source/model/main/Diagram.cxx @@ -101,7 +101,8 @@ enum PROP_DIAGRAM_SPLIT_POS, PROP_DIAGRAM_DATATABLEVBORDER, PROP_DIAGRAM_DATATABLEOUTLINE, - PROP_DIAGRAM_EXTERNALDATA + PROP_DIAGRAM_EXTERNALDATA, + PROP_DIAGRAM_STYLE_INDEX }; void lcl_AddPropertiesToVector( @@ -197,6 +198,10 @@ void lcl_AddPropertiesToVector( PROP_DIAGRAM_EXTERNALDATA, cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID ); + rOutProperties.emplace_back( "StyleIndex", + PROP_DIAGRAM_STYLE_INDEX, + cppu::UnoType<OUString>::get(), + beans::PropertyAttribute::MAYBEVOID ); } const ::chart::tPropertyValueMap& StaticDiagramDefaults() diff --git a/oox/inc/drawingml/chart/chartspacemodel.hxx b/oox/inc/drawingml/chart/chartspacemodel.hxx index dda0f577ae32..d66abb21f9d7 100644 --- a/oox/inc/drawingml/chart/chartspacemodel.hxx +++ b/oox/inc/drawingml/chart/chartspacemodel.hxx @@ -54,6 +54,7 @@ struct ChartSpaceModel OUString maSheetPath; /// Path to embedded charts. sal_Int32 mnDispBlanksAs; /// Mode how to display blank values. sal_Int32 mnStyle; /// Index to default formatting. + bool mbExplicitStyle; /// Is there a <c:style> tag? bool mbAutoTitleDel; /// True = automatic title deleted manually. bool mbPlotVisOnly; /// True = plot visible cells in a sheet only. bool mbShowLabelsOverMax;/// True = show labels over chart maximum. diff --git a/oox/source/drawingml/chart/chartspaceconverter.cxx b/oox/source/drawingml/chart/chartspaceconverter.cxx index b3bc7d4a8e21..d2d51fad3c43 100644 --- a/oox/source/drawingml/chart/chartspaceconverter.cxx +++ b/oox/source/drawingml/chart/chartspaceconverter.cxx @@ -240,6 +240,13 @@ void ChartSpaceConverter::convertFromModel( const Reference< XShapes >& rxExtern PropertySet aDiaProp( xDiagram ); aDiaProp.setProperty( PROP_MissingValueTreatment, nMissingValues ); + + if (mrModel.mbExplicitStyle) { + // The <c:style> value, now in mrModel.mnStyle, is handled in the + // ObjectFormatter code. Set it here as a property just so it can be + // stored for output. + aDiaProp.setProperty( PROP_StyleIndex, mrModel.mnStyle); + } } /* Following all conversions needing the old Chart1 API that involves full diff --git a/oox/source/drawingml/chart/chartspacefragment.cxx b/oox/source/drawingml/chart/chartspacefragment.cxx index 88ee3c5bdf41..29e77e4b5095 100644 --- a/oox/source/drawingml/chart/chartspacefragment.cxx +++ b/oox/source/drawingml/chart/chartspacefragment.cxx @@ -65,6 +65,7 @@ ContextHandlerRef ChartSpaceFragment::onCreateContext( sal_Int32 nElement, const return new ShapePropertiesContext( *this, mrModel.mxShapeProp.create() ); case C_TOKEN( style ): mrModel.mnStyle = rAttribs.getInteger( XML_val, 2 ); + mrModel.mbExplicitStyle = true; return nullptr; case C_TOKEN( txPr ): return new TextBodyContext( *this, mrModel.mxTextProp.create() ); diff --git a/oox/source/drawingml/chart/chartspacemodel.cxx b/oox/source/drawingml/chart/chartspacemodel.cxx index 3aa7366ff82e..06303b9a8e02 100644 --- a/oox/source/drawingml/chart/chartspacemodel.cxx +++ b/oox/source/drawingml/chart/chartspacemodel.cxx @@ -25,6 +25,7 @@ namespace oox::drawingml::chart { ChartSpaceModel::ChartSpaceModel(bool bMSO2007Doc) : mnDispBlanksAs( bMSO2007Doc ? XML_gap : XML_zero ), // difference between OOXML spec and MSO 2007 mnStyle( 2 ), + mbExplicitStyle(false), mbAutoTitleDel( !bMSO2007Doc ), // difference between OOXML spec and MSO 2007 mbPlotVisOnly( !bMSO2007Doc ), mbShowLabelsOverMax( !bMSO2007Doc ), diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx index 6239411e5054..c0179d033bc8 100644 --- a/oox/source/export/chartexport.cxx +++ b/oox/source/export/chartexport.cxx @@ -1281,11 +1281,27 @@ void ChartExport::exportChartSpace( const Reference< css::chart::XChartDocument pFS->singleElement(FSNS(XML_c, XML_roundedCorners), XML_val, "0"); } + // style + if (!bIsChartex) { + mxDiagram.set( xChartDoc->getDiagram() ); + Reference< XPropertySet > xPropSet(mxDiagram, uno::UNO_QUERY); + if (GetProperty(xPropSet, u"StyleIndex"_ustr)) { + sal_Int32 nStyleIdx = -1; + mAny >>= nStyleIdx; + assert(nStyleIdx >= 0); + pFS->singleElement(FSNS(XML_c, XML_style), XML_val, + OUString::number(nStyleIdx)); + } + } + + if( !bIncludeTable ) + { + // TODO:external data + } //XML_chart exportChart(xChartDoc, bIsChartex); // TODO: printSettings - // TODO: style // TODO: text properties Reference< XPropertySet > xPropSet = xChartDoc->getArea(); if( xPropSet.is() ) diff --git a/oox/source/token/properties.txt b/oox/source/token/properties.txt index 36e9a16991ef..96b1fc988f09 100644 --- a/oox/source/token/properties.txt +++ b/oox/source/token/properties.txt @@ -564,6 +564,7 @@ StartWith StartingAngle State StringItemList +StyleIndex SubPieType SubViewSize Subtotals