oox/source/export/chartexport.cxx | 2 ++ sw/qa/extras/ooxmlexport/data/tdf143269_emptyChart.odt |binary sw/qa/extras/ooxmlexport/ooxmlexport10.cxx | 12 ++++++++++++ sw/source/filter/ww8/docxattributeoutput.cxx | 7 +++++++ 4 files changed, 21 insertions(+)
New commits: commit 3c4723abfc779ce0dc02d9ada35d5c6c78c19615 Author: Justin Luth <[email protected]> AuthorDate: Thu Mar 5 16:08:19 2026 -0500 Commit: Miklos Vajna <[email protected]> CommitDate: Mon Mar 9 08:41:06 2026 +0100 tdf#143269 docx export: skip charts without a c:plotArea This backport includes the fixes for the original commit. MS Word considers documents as corrupt if they don't have at least a c:plotArea. An empty c:chart or an empty c:chartSpace is not enough. Well, actually I don't know WHAT the minimum is, but certainly a c:plotArea does not seem to be optional, and everything less that I tried also reported as corrupt. make CppunitTest_sw_ooxmlexport10 \ CPPUNIT_TEST_NAME=testTdf143269_emptyChart Change-Id: I7b6a10160fdf99ca984185a59c1c2ecc1aa6e3fd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/201086 Reviewed-by: Justin Luth <[email protected]> Tested-by: Jenkins Reviewed-on: https://gerrit.libreoffice.org/c/core/+/201166 Reviewed-by: Miklos Vajna <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx index 1abbf4ff7930..3768b6deb1b8 100644 --- a/oox/source/export/chartexport.cxx +++ b/oox/source/export/chartexport.cxx @@ -1686,6 +1686,8 @@ namespace { void ChartExport::exportPlotArea(const Reference< css::chart::XChartDocument >& xChartDoc) { Reference< chart2::XCoordinateSystemContainer > xBCooSysCnt( mxNewDiagram, uno::UNO_QUERY ); + // MS Word considers a chart corrupt if it doesn't have a c:plotArea + assert(xBCooSysCnt.is()); if( ! xBCooSysCnt.is()) return; diff --git a/sw/qa/extras/ooxmlexport/data/tdf143269_emptyChart.odt b/sw/qa/extras/ooxmlexport/data/tdf143269_emptyChart.odt new file mode 100755 index 000000000000..f9d757308858 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf143269_emptyChart.odt differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx index 2f585635ef04..91f52686254f 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx @@ -775,6 +775,18 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf143269_missingEmbeddings) assertXPath(pXmlChart1, "//c:externalData", 0); } +CPPUNIT_TEST_FIXTURE(Test, testTdf143269_emptyChart) +{ + // Given a LO-authored chart that is completely empty + + createSwDoc("tdf143269_emptyChart.odt"); + save(TestFilter::DOCX); + + // MS Word reports corrupt if a chart is empty - it needs to be skipped + xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); + assertXPath(pXmlDoc, "//c:chart", 0); +} + DECLARE_OOXMLEXPORT_TEST(testChartSize, "chart-size.docx") { // When chart was in a TextFrame, its size was too large. diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index cf83999358fa..a21f0d549be8 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -148,6 +148,7 @@ #include <com/sun/star/i18n/ScriptType.hpp> #include <com/sun/star/i18n/XBreakIterator.hpp> #include <com/sun/star/chart2/XChartDocument.hpp> +#include <com/sun/star/chart2/XCoordinateSystemContainer.hpp> #include <com/sun/star/drawing/ShadingPattern.hpp> #include <com/sun/star/text/GraphicCrop.hpp> #include <com/sun/star/embed/EmbedStates.hpp> @@ -5740,6 +5741,12 @@ void DocxAttributeOutput::WritePostponedChart() if( xChartDoc.is() ) { + // At minimum, a PlotArea is needed or else MS Word complains about an invalid file + uno::Reference<chart2::XCoordinateSystemContainer> + xBCooSysCnt(xChartDoc->getFirstDiagram(), uno::UNO_QUERY); + if (!xBCooSysCnt.is()) + continue; + SAL_INFO("sw.ww8", "DocxAttributeOutput::WriteOLE2Obj: export chart "); m_rExport.SdrExporter().startDMLAnchorInline(rChart.frame, rChart.size);
