diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2022-05-11 12:26:11 +0900 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2022-06-01 10:03:53 +0200 |
commit | 38d00152374e3df465fff78e379cecb4b0be2985 (patch) | |
tree | 6c00b8fff3b6930b0f8132e4ef44f2decdc5ab34 /sc | |
parent | d236341c6aab90d7d4097d6ff535e1bbeb656f3a (diff) |
tdf#148835 don't write any sparkline xml elements if none exists
Change-Id: Idd4058a88639cebceded13110dc367e74b6f7097
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134141
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
(cherry picked from commit 2c4330b3570f16d6668936fd05e1ab2ade597bae)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135171
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/qa/unit/SparklineImportExportTest.cxx | 22 | ||||
-rw-r--r-- | sc/source/filter/excel/export/SparklineExt.cxx | 7 |
2 files changed, 28 insertions, 1 deletions
diff --git a/sc/qa/unit/SparklineImportExportTest.cxx b/sc/qa/unit/SparklineImportExportTest.cxx index 7060a120c49a..19765bd67016 100644 --- a/sc/qa/unit/SparklineImportExportTest.cxx +++ b/sc/qa/unit/SparklineImportExportTest.cxx @@ -47,17 +47,20 @@ public: virtual void registerNamespaces(xmlXPathContextPtr& pXmlXPathContextPtr) override { + XmlTestTools::registerOOXMLNamespaces(pXmlXPathContextPtr); XmlTestTools::registerODFNamespaces(pXmlXPathContextPtr); } void testSparklinesRoundtripXLSX(); void testSparklinesExportODS(); void testSparklinesRoundtripODS(); + void testNoSparklinesInDocumentXLSX(); CPPUNIT_TEST_SUITE(SparklineImportExportTest); CPPUNIT_TEST(testSparklinesRoundtripXLSX); CPPUNIT_TEST(testSparklinesExportODS); CPPUNIT_TEST(testSparklinesRoundtripODS); + CPPUNIT_TEST(testNoSparklinesInDocumentXLSX); CPPUNIT_TEST_SUITE_END(); }; @@ -241,6 +244,25 @@ void SparklineImportExportTest::testSparklinesRoundtripODS() xDocSh->DoClose(); } +void SparklineImportExportTest::testNoSparklinesInDocumentXLSX() +{ + // tdf#148835 + // Check no sparkline elements are written when there is none in the document + + // Load the document containing NO sparklines + ScDocShellRef xDocSh = loadDoc(u"empty.", FORMAT_XLSX); + + std::shared_ptr<utl::TempFile> pXPathFile = ScBootstrapFixture::exportTo(*xDocSh, FORMAT_XLSX); + xmlDocUniquePtr pXmlDoc + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + CPPUNIT_ASSERT(pXmlDoc); + + assertXPath(pXmlDoc, "/x:worksheet", 1); + assertXPath(pXmlDoc, "/x:worksheet/x:extLst/x:ext/x14:sparklineGroups", 0); + assertXPath(pXmlDoc, "/x:worksheet/x:extLst/x:ext", 0); + assertXPath(pXmlDoc, "/x:worksheet/x:extLst", 0); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SparklineImportExportTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sc/source/filter/excel/export/SparklineExt.cxx b/sc/source/filter/excel/export/SparklineExt.cxx index 5202c3e92449..487698e19ba1 100644 --- a/sc/source/filter/excel/export/SparklineExt.cxx +++ b/sc/source/filter/excel/export/SparklineExt.cxx @@ -230,7 +230,12 @@ void SparklineExt::addSparklineGroup(XclExpXmlStream& rStream, sc::SparklineGrou SparklineBuffer::SparklineBuffer(const XclExpRoot& rRoot, XclExtLstRef const& xExtLst) : XclExpRoot(rRoot) { - xExtLst->AddRecord(new xcl::exp::SparklineExt(GetRoot())); + auto& rDocument = GetDoc(); + auto* pSparklineList = rDocument.GetSparklineList(GetCurrScTab()); + if (pSparklineList && !pSparklineList->getSparklineGroups().empty()) + { + xExtLst->AddRecord(new xcl::exp::SparklineExt(GetRoot())); + } } } // end namespace xcl::exp |