sw/qa/extras/ooxmlexport/data/tdf122648.docx      |binary
 sw/qa/extras/ooxmlexport/ooxmlexport15.cxx        |   36 ++++++++++++++++++++++
 sw/source/core/doc/DocumentFieldsManager.cxx      |    2 -
 writerfilter/source/dmapper/DomainMapper_Impl.cxx |    4 +-
 4 files changed, 40 insertions(+), 2 deletions(-)

New commits:
commit 177f97d465feceb6663dd180b7dab51f945765aa
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Fri Sep 18 09:28:06 2020 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Nov 16 11:38:53 2020 +0100

    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 <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf122648.docx 
b/sw/qa/extras/ooxmlexport/data/tdf122648.docx
new file mode 100644
index 000000000000..900a9f30b23b
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf122648.docx differ
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?
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx 
b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index bbe5af129ae6..22eb91ea9020 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -4073,7 +4073,9 @@ OUString DomainMapper_Impl::convertFieldFormula(const 
OUString& input) {
     icu::RegexMatcher rmatch2("\\b([A-Z]{1,3}[0-9]+)\\b(?![(])", usInput, 
rMatcherFlags, status);
     usInput = rmatch2.replaceAll(icu::UnicodeString("<$1>"), status);
 
-    /* Cell references must be upper case */
+    /* Cell references must be upper case
+     * TODO: convert reference to other tables, e.g. SUM(Table1 A1:B2), where 
"Table1" is a bookmark of the table,
+     * TODO: also column range A:A */
     icu::RegexMatcher rmatch3("<[a-z]{1,3}[0-9]+>", usInput, rMatcherFlags, 
status);
     icu::UnicodeString replacedCellRefs;
     while (rmatch3.find(status) && status.isSuccess()) {
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to