oox/source/export/chartexport.cxx                      |    4 ++--
 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(+), 2 deletions(-)

New commits:
commit f9d0ff9662fbc45e7ef9840ff1d046fa131a8dae
Author:     Justin Luth <[email protected]>
AuthorDate: Thu Mar 5 16:08:19 2026 -0500
Commit:     Miklos Vajna <[email protected]>
CommitDate: Fri Mar 6 16:00:48 2026 +0100

    tdf#143269 docx export: skip charts without a c:plotArea
    
    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
    (cherry picked from commit aa2453b7573798943d055449d57a1e37b22fc8e9)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/201125
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>

diff --git a/oox/source/export/chartexport.cxx 
b/oox/source/export/chartexport.cxx
index a07f8cb4282a..a0fa933928ca 100644
--- a/oox/source/export/chartexport.cxx
+++ b/oox/source/export/chartexport.cxx
@@ -2537,8 +2537,8 @@ void ChartExport::exportPlotArea(const Reference< 
css::chart::XChartDocument >&
         bool bIsChartex)
 {
     Reference< chart2::XCoordinateSystemContainer > xBCooSysCnt( mxNewDiagram, 
uno::UNO_QUERY );
-    if( ! xBCooSysCnt.is())
-        return;
+    // MS Word considers a chart corrupt if it doesn't have a c:plotArea
+    assert(xBCooSysCnt.is());
 
     // plot-area element
 
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 7000f0919fb5..f8b27ba0512d 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
@@ -791,6 +791,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 6d405f05272b..6fb4a56a1213 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -149,6 +149,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>
@@ -5834,6 +5835,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);

Reply via email to