sw/qa/extras/ooxmlexport/data/tdf123382.docx |binary sw/qa/extras/ooxmlexport/ooxmlexport15.cxx | 52 +++++++++++++++ writerfilter/source/dmapper/DomainMapperTableHandler.cxx | 6 + writerfilter/source/dmapper/DomainMapper_Impl.cxx | 2 4 files changed, 57 insertions(+), 3 deletions(-)
New commits: commit d676d2c22f1d092c9978ffc1595b8356d8db1f7a Author: László Németh <nem...@numbertext.org> AuthorDate: Wed Sep 16 13:06:32 2020 +0200 Commit: László Németh <nem...@numbertext.org> CommitDate: Fri Sep 18 11:40:19 2020 +0200 tdf#123382 DOCX import: fix range IDs in column A Range IDs ABOVE, BELOW, LEFT and RIGHT weren't recognized in the first table column. Also the original formula was not grab-bagged in the first table cell (A1), according to the limitation of isInTable(). Follow-up of commit 436cf6d31deb7f9594a5da52ec7883d7e3d34344 (tdf#123355 DOCX import: fix cell range ABOVE, BELOW) and commit 82189fdc93ac337e1de3379d678eca6b7654e6fc (tdf133647 tdf123386 tdf123389 fix DOCX table formula export). Change-Id: Ic7d9c63a5ca989328f7ed33e25e1eda45296b3a4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102849 Tested-by: Jenkins Reviewed-by: László Németh <nem...@numbertext.org> diff --git a/sw/qa/extras/ooxmlexport/data/tdf123382.docx b/sw/qa/extras/ooxmlexport/data/tdf123382.docx new file mode 100644 index 000000000000..cac27ef51832 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf123382.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx index 39a9b103308a..d83e670dab58 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx @@ -302,6 +302,58 @@ DECLARE_OOXMLEXPORT_TEST(testTdf123355, "tdf123355.docx") assertXPathContent(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[6]/w:tc[4]/w:p/w:r[2]/w:instrText", " =SUM(LEFT)"); } +DECLARE_OOXMLEXPORT_TEST(testTdf123382, "tdf123382.docx") +{ + uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); + + // Tests conversion of range IDs ABOVE, BELOW, LEFT and RIGHT + uno::Reference<text::XTextField> xEnumerationAccess1(xFields->nextElement(), uno::UNO_QUERY); + // Note: range ends at B4 here, which is a cell with text content + CPPUNIT_ASSERT_EQUAL(OUString("MAX(<B1:D1>)"), xEnumerationAccess1->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("12"), xEnumerationAccess1->getPresentation(false).trim()); + + // range ends at the end of the empty cells + uno::Reference<text::XTextField> xEnumerationAccess6(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("MAX(<C4:D4>)"), xEnumerationAccess6->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("9"), xEnumerationAccess6->getPresentation(false).trim()); + + // range starts at the first cell above D5 + uno::Reference<text::XTextField> xEnumerationAccess2(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("SUM(<B3:D3>)"), xEnumerationAccess2->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("30"), xEnumerationAccess2->getPresentation(false).trim()); + + uno::Reference<text::XTextField> xEnumerationAccess3(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("MAX(<C2:A2>)"), xEnumerationAccess3->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("7"), xEnumerationAccess3->getPresentation(false).trim()); + + uno::Reference<text::XTextField> xEnumerationAccess4(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("MAX(<B2:D2>)"), xEnumerationAccess4->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("7"), xEnumerationAccess4->getPresentation(false).trim()); + + uno::Reference<text::XTextField> xEnumerationAccess5(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("MAX(<D2:D4>)"), xEnumerationAccess5->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("12"), xEnumerationAccess5->getPresentation(false).trim()); + + uno::Reference<text::XTextField> xEnumerationAccess7(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("MAX(<B2:B4>)"), xEnumerationAccess7->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("10"), xEnumerationAccess7->getPresentation(false).trim()); + + xmlDocUniquePtr pXmlDoc = parseExport(); + if (!pXmlDoc) + return; + + // keep original formula IDs + assertXPathContent(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[1]/w:tc[1]/w:p/w:r[2]/w:instrText", " =MAX(RIGHT)"); + assertXPathContent(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[1]/w:p/w:r[2]/w:instrText", " =MAX(RIGHT)"); + assertXPathContent(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[3]/w:tc[1]/w:p/w:r[2]/w:instrText", " =SUM(RIGHT)"); + assertXPathContent(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[1]/w:tc[2]/w:p/w:r[2]/w:instrText", " =MAX(BELOW)"); + assertXPathContent(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[4]/w:tc[2]/w:p/w:r[2]/w:instrText", " =MAX(RIGHT)"); + assertXPathContent(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[1]/w:tc[4]/w:p/w:r[2]/w:instrText", " =MAX(BELOW)"); + assertXPathContent(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[4]/w:p/w:r[2]/w:instrText", " =MAX(LEFT)"); +} + DECLARE_OOXMLEXPORT_TEST(testTdf98000_changePageStyle, "tdf98000_changePageStyle.odt") { uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx index 8b4d9dd2b51e..42024b048c45 100644 --- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx +++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx @@ -75,6 +75,9 @@ using namespace ::std; #define CNF_LAST_ROW_FIRST_COLUMN 0x001 #define CNF_ALL 0xFFF +// total number of table columns +#define MAXTABLECELLS 63 + DomainMapperTableHandler::DomainMapperTableHandler( css::uno::Reference<css::text::XTextAppendAndConvert> const& xText, DomainMapper_Impl& rDMapper_Impl) @@ -1229,8 +1232,7 @@ static void lcl_convertFormulaRanges(const uno::Reference<text::XTextTable> & xT sal_Int32 nRows = xTableRows->getCount(); for (sal_Int32 nRow = 0; nRow < nRows; ++nRow) { - sal_Int16 nCol = 0; - while (++nCol) + for (sal_Int16 nCol = 0; nCol < MAXTABLECELLS; ++nCol) { try { diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 4e5b17863d41..000a0f50a238 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -4334,7 +4334,7 @@ void DomainMapper_Impl::handleFieldFormula xFieldProperties->setPropertyValue("IsShowFormula", uno::makeAny(false)); // grab-bag the original and converted formula - if (getTableManager().isInTable()) + if (hasTableManager()) { TablePropertyMapPtr pPropMap(new TablePropertyMap()); pPropMap->Insert(PROP_CELL_FORMULA, uno::makeAny(command.copy(1)), true, CELL_GRAB_BAG); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits