diff options
author | László Németh <nemeth@numbertext.org> | 2020-09-18 09:28:06 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-11-16 11:38:53 +0100 |
commit | 177f97d465feceb6663dd180b7dab51f945765aa (patch) | |
tree | f022d97100e6937c285f0fd8eb32abff9bb7eb3b /sw | |
parent | cd475b517abcace4ed79bfd129e4487d60513b30 (diff) |
tdf#122648 DOCX import: fix table formula in all tables
Table formula import worked only in the first table,
because of using bad fallback table for cell references
without table names during formula conversion to internal
formula.
Set table of the text field as the correct fallback table.
Follow-up of commit 68e74bdf63e992666016c790e8e4cfd5b28d6abe
(tdf133647 tdf123386 tdf123389 Improved .docx table formula import).
(cherry picked from commit 782700c6940341d489eabf00a531cb184941484e)
Conflicts:
sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
sw/source/core/doc/DocumentFieldsManager.cxx
writerfilter/source/dmapper/DomainMapper_Impl.cxx
Change-Id: Ib080f12426c57c8c74fe919eb45637a655875d1d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105917
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/tdf122648.docx | bin | 0 -> 4767 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport15.cxx | 36 | ||||
-rw-r--r-- | sw/source/core/doc/DocumentFieldsManager.cxx | 2 |
3 files changed, 37 insertions, 1 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/tdf122648.docx b/sw/qa/extras/ooxmlexport/data/tdf122648.docx Binary files differnew file mode 100644 index 000000000000..900a9f30b23b --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/tdf122648.docx diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx index a20a93c93637..a663e914db1e 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx @@ -11,6 +11,7 @@ #include <com/sun/star/beans/NamedValue.hpp> #include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/text/XTextField.hpp> char const DATA_DIRECTORY[] = "/sw/qa/extras/ooxmlexport/data/"; @@ -86,6 +87,41 @@ DECLARE_OOXMLIMPORT_TEST(testTdf131801, "tdf131801.docx") assertXPath(pXmlDocument, "/w:document/w:body/w:p[8]/w:pPr/w:rPr/w:rStyle", 0); } +DECLARE_OOXMLEXPORT_TEST(testTdf122648, "tdf122648.docx") +{ + uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); + + // table formula conversion worked only in the first table + uno::Reference<text::XTextField> xEnumerationAccess1(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("<A1>"), xEnumerationAccess1->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("1"), xEnumerationAccess1->getPresentation(false).trim()); + + uno::Reference<text::XTextField> xEnumerationAccess2(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("SUM(<A1:B1>)"), xEnumerationAccess2->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("2"), xEnumerationAccess2->getPresentation(false).trim()); + + // These were <?> and SUM(<?:?>) with zero values + uno::Reference<text::XTextField> xEnumerationAccess3(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("<A1>"), xEnumerationAccess3->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("1"), xEnumerationAccess3->getPresentation(false).trim()); + + uno::Reference<text::XTextField> xEnumerationAccess4(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("SUM(<A1:B1>)"), xEnumerationAccess4->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("2"), xEnumerationAccess4->getPresentation(false).trim()); + + xmlDocPtr pXmlDoc = parseExport(); + if (!pXmlDoc) + return; + + assertXPathContent(pXmlDoc, "/w:document/w:body/w:tbl[1]/w:tr[1]/w:tc[2]/w:p/w:r[2]/w:instrText", " = A1"); + assertXPathContent(pXmlDoc, "/w:document/w:body/w:tbl[1]/w:tr[2]/w:tc[2]/w:p/w:r[2]/w:instrText", " = SUM(A1:B1)"); + // These were =<?> and =SUM(<?:?>) + assertXPathContent(pXmlDoc, "/w:document/w:body/w:tbl[2]/w:tr[1]/w:tc[2]/w:p/w:r[2]/w:instrText", " = A1"); + assertXPathContent(pXmlDoc, "/w:document/w:body/w:tbl[2]/w:tr[2]/w:tc[2]/w:p/w:r[2]/w:instrText", " = SUM(A1:B1)"); +} + DECLARE_OOXMLEXPORT_TEST(testTdf135973, "tdf135973.odt") { CPPUNIT_ASSERT_EQUAL(1, getPages()); diff --git a/sw/source/core/doc/DocumentFieldsManager.cxx b/sw/source/core/doc/DocumentFieldsManager.cxx index 134d8cab9968..3efabd83ae29 100644 --- a/sw/source/core/doc/DocumentFieldsManager.cxx +++ b/sw/source/core/doc/DocumentFieldsManager.cxx @@ -675,7 +675,7 @@ void DocumentFieldsManager::UpdateTableFields( SfxPoolItem* pHt ) // to the internal representation // JP 17.06.96: internal representation on all formulas // (reference to other table!!!) - pField->BoxNmToPtr( pUpdateField->m_pTable ); + pField->BoxNmToPtr( &pTableNd->GetTable() ); break; case TBL_RELBOXNAME: // is this the wanted table? |