sc/inc/dbdata.hxx | 1 + sc/qa/unit/data/xlsx/tdf167689_tableType.xlsx |binary sc/qa/unit/subsequent_export_test4.cxx | 17 +++++++++++++++++ sc/source/filter/excel/xedbdata.cxx | 25 +++++++++++++++++++------ sc/source/filter/oox/tablebuffer.cxx | 11 +++++++---- 5 files changed, 44 insertions(+), 10 deletions(-)
New commits: commit 07ab1c6810c069b887ce31677ae743110d13c440 Author: Bayram Çiçek <bayram.ci...@collabora.com> AuthorDate: Sat Aug 30 18:51:27 2025 +0300 Commit: Bayram Çiçek <bayram.ci...@collabora.com> CommitDate: Sat Sep 20 09:25:40 2025 +0200 tdf#167689: sc: don't export tableType if it does not exist - and if there is no tableType, there should not be any uniqueName attribute in <tableColumn> - add a unittest Signed-off-by: Bayram Çiçek <bayram.ci...@collabora.com> Change-Id: I425e9204a31646bd3d6f3986244d906ab4fea1a8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190439 Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> Tested-by: Jenkins (cherry picked from commit 8c5fd04f0bb5bf75192d1c4ddd4d80f608796d7c) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191212 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> diff --git a/sc/inc/dbdata.hxx b/sc/inc/dbdata.hxx index 9b74ae0c9de9..868c3c23f506 100644 --- a/sc/inc/dbdata.hxx +++ b/sc/inc/dbdata.hxx @@ -43,6 +43,7 @@ enum class ScDBDataPortion AREA ///< entire area }; +// TODO: this can be merged with struct TableColumnModel struct TableColumnAttributes { std::optional<OUString> maTotalsFunction = std::nullopt; diff --git a/sc/qa/unit/data/xlsx/tdf167689_tableType.xlsx b/sc/qa/unit/data/xlsx/tdf167689_tableType.xlsx new file mode 100644 index 000000000000..43acb82d0621 Binary files /dev/null and b/sc/qa/unit/data/xlsx/tdf167689_tableType.xlsx differ diff --git a/sc/qa/unit/subsequent_export_test4.cxx b/sc/qa/unit/subsequent_export_test4.cxx index edd0a0a35e51..90f2cffd5f81 100644 --- a/sc/qa/unit/subsequent_export_test4.cxx +++ b/sc/qa/unit/subsequent_export_test4.cxx @@ -1762,6 +1762,23 @@ CPPUNIT_TEST_FIXTURE(ScExportTest4, testTdf167689_xmlMaps_and_xmlColumnPr) u"Description"); } +CPPUNIT_TEST_FIXTURE(ScExportTest4, testTdf167689_tableType) +{ + createScDoc("xlsx/tdf167689_tableType.xlsx"); + save(u"Calc Office Open XML"_ustr); + + xmlDocUniquePtr pDocXmlTables = parseExport(u"xl/tables/table1.xml"_ustr); + CPPUNIT_ASSERT(pDocXmlTables); + + // if the source document does not have tableType attribute in <table> node, + // it shouldn't exist in the exported document either. + assertXPathNoAttribute(pDocXmlTables, "/x:table", "tableType"); + + // if there is no tableType, there should not be any uniqueName attribute in <tableColumn> + assertXPathNoAttribute(pDocXmlTables, "/x:table/x:tableColumns/x:tableColumn[1]", "uniqueName"); + assertXPathNoAttribute(pDocXmlTables, "/x:table/x:tableColumns/x:tableColumn[2]", "uniqueName"); +} + CPPUNIT_TEST_FIXTURE(ScExportTest4, testAutofilterHiddenButton) { createScDoc("xlsx/hiddenButton.xlsx"); diff --git a/sc/source/filter/excel/xedbdata.cxx b/sc/source/filter/excel/xedbdata.cxx index a2dbf1e96f8d..6b67bc28b836 100644 --- a/sc/source/filter/excel/xedbdata.cxx +++ b/sc/source/filter/excel/xedbdata.cxx @@ -181,13 +181,20 @@ void XclExpTables::SaveTableXml( XclExpXmlStream& rStrm, const Entry& rEntry ) ScRange aRange( ScAddress::UNINITIALIZED); rData.GetArea( aRange); sax_fastparser::FSHelperPtr& pTableStrm = rStrm.GetCurrentStream(); + + bool hasTableTypeAttr = !rData.GetTableType().isEmpty(); + std::optional<OUString> tableType = std::nullopt; + + if (hasTableTypeAttr) + tableType = rData.GetTableType(); + pTableStrm->startElement( XML_table, XML_xmlns, rStrm.getNamespaceURL(OOX_NS(xls)).toUtf8(), XML_id, OString::number( rEntry.mnTableId), XML_name, rData.GetName().toUtf8(), XML_displayName, rData.GetName().toUtf8(), XML_ref, XclXmlUtils::ToOString(rStrm.GetRoot().GetDoc(), aRange), - XML_tableType, rData.GetTableType().toUtf8(), + XML_tableType, tableType, XML_headerRowCount, ToPsz10(rData.HasHeader()), XML_totalsRowCount, ToPsz10(rData.HasTotals()), XML_totalsRowShown, ToPsz10(rData.HasTotals()) // we don't support that but if there are totals they are shown @@ -237,11 +244,17 @@ void XclExpTables::SaveTableXml( XclExpXmlStream& rStrm, const Entry& rEntry ) // OOXTODO: write <totalsRowFormula> once we support it. - OUString uniqueName; - if (i < rTableColumnModel.size() && !rTableColumnModel[i].maUniqueName.isEmpty()) - uniqueName = rTableColumnModel[i].maUniqueName; - else - uniqueName = rColNames[i]; // fallback to column name if no unique name. + std::optional<OUString> uniqueName = std::nullopt; + + // uniqueName should only be used when this table's tableType is queryTable or xml. + // in this implementation: if tableType attribute exists, it has either queryTable or xml value. + if (hasTableTypeAttr) + { + if (i < rTableColumnModel.size() && !rTableColumnModel[i].maUniqueName.isEmpty()) + uniqueName = rTableColumnModel[i].maUniqueName; + else + uniqueName = rColNames[i]; // fallback to column name if no unique name. + } pTableStrm->startElement( XML_tableColumn, XML_id, OString::number(i+1), diff --git a/sc/source/filter/oox/tablebuffer.cxx b/sc/source/filter/oox/tablebuffer.cxx index e2c8e273b50b..eb9244d9676a 100644 --- a/sc/source/filter/oox/tablebuffer.cxx +++ b/sc/source/filter/oox/tablebuffer.cxx @@ -131,11 +131,14 @@ void Table::finalizeImport() case XML_xml: sValue = "xml"; break; - case XML_queryTable: - sValue = "queryTable"; - break; + // TODO: activate this case when we support query tables. + // case XML_queryTable: + // sValue = "queryTable"; + // break; default: - sValue = "worksheet"; + // use="optional" default="worksheet". + // no need to export, set empty to prevent export. + sValue = OUString(); break; } aPropSet.setProperty(PROP_TableType, css::uno::Any(sValue));