[Libreoffice-commits] core.git: sw/qa writerfilter/source

László Németh (via logerrit) logerrit at kemper.freedesktop.org
Sun Aug 23 11:07:46 UTC 2020


 sw/qa/extras/ooxmlexport/data/tdf123356.docx      |binary
 sw/qa/extras/ooxmlexport/ooxmlexport15.cxx        |   20 ++++++++++++++++++++
 writerfilter/source/dmapper/DomainMapper_Impl.cxx |    4 ++++
 3 files changed, 24 insertions(+)

New commits:
commit f1f27b2487ccfb7a03190ff68eadbfb611dd9749
Author:     László Németh <nemeth at numbertext.org>
AuthorDate: Sat Aug 22 17:22:04 2020 +0200
Commit:     László Németh <nemeth at numbertext.org>
CommitDate: Sun Aug 23 13:07:03 2020 +0200

    tdf#123356 DOCX import: fix COUNT formula
    
    Convert COUNT(x) to the equivalent, but
    portable Writer formula SUM(x)/MEAN(x).
    
    Note: this is a temporary conversion, which
    supports only 1-level nesting of function calls.
    Adding COUNT to Writer core, it will be possible
    to remove portable conversion later.
    
    Change-Id: I4b4019aadad52e6d1cf3b2d18d80b1d2c7485c6a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101185
    Tested-by: Jenkins
    Reviewed-by: László Németh <nemeth at numbertext.org>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf123356.docx b/sw/qa/extras/ooxmlexport/data/tdf123356.docx
new file mode 100644
index 000000000000..9432ca2dbb06
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf123356.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
index ad96c19673c3..638a43761c76 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
@@ -113,6 +113,26 @@ DECLARE_OOXMLEXPORT_TEST(testTdf123390, "tdf123390.docx")
     CPPUNIT_ASSERT_EQUAL(OUString("1"), xEnumerationAccess2->getPresentation(false).trim());
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf123356, "tdf123356.docx")
+{
+    uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
+    uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
+
+    uno::Reference<text::XTextField> xEnumerationAccess1(xFields->nextElement(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("-11"), xEnumerationAccess1->getPresentation(true).trim());
+    CPPUNIT_ASSERT_EQUAL(OUString("-11"), xEnumerationAccess1->getPresentation(false).trim());
+
+    // Tests cell formula COUNT(x) to SUM(x)/MEAN(x) conversion
+    uno::Reference<text::XTextField> xEnumerationAccess4(xFields->nextElement(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("(SUM(<A1:C1>|<A2:B2>)/MEAN(<A1:C1>|<A2:B2>))"), xEnumerationAccess4->getPresentation(true).trim());
+    CPPUNIT_ASSERT_EQUAL(OUString("5"), xEnumerationAccess4->getPresentation(false).trim());
+
+    uno::Reference<text::XTextField> xEnumerationAccess3(xFields->nextElement(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("(SUM(<A1:C1>)/MEAN(<A1:C1>))"), xEnumerationAccess3->getPresentation(true).trim());
+    CPPUNIT_ASSERT_EQUAL(OUString("3"), xEnumerationAccess3->getPresentation(false).trim());
+}
+
 DECLARE_OOXMLEXPORT_TEST(testTdf98000_changePageStyle, "tdf98000_changePageStyle.odt")
 {
     uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index b5a8f124c142..a482a3231551 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -4272,6 +4272,10 @@ OUString DomainMapper_Impl::convertFieldFormula(const OUString& input) {
     icu::RegexMatcher rmatch7("\\bSIGN\\s*(\\(([^()]*|([^()])*\\([^()]*\\)[^()]*)*\\))", usInput, rMatcherFlags, status);
     usInput = rmatch7.replaceAll(icu::UnicodeString("((0 L $1) - ($1 L 0))"), status);
 
+    /* Fix up COUNT(x) using SUM(x)/MEAN(x) (it supports only 1-level nesting) */
+    icu::RegexMatcher rmatch8("\\bCOUNT\\s*(\\(([^()]*|([^()])*\\([^()]*\\)[^()]*)*\\))", usInput, rMatcherFlags, status);
+    usInput = rmatch8.replaceAll(icu::UnicodeString("(SUM$1/MEAN$1)"), status);
+
     return OUString(usInput.getTerminatedBuffer());
 }
 


More information about the Libreoffice-commits mailing list