sw/qa/extras/uiwriter/data/tdf148799.docx         |binary
 sw/qa/extras/uiwriter/uiwriter8.cxx               |   31 ++++++++++++++++++++++
 writerfilter/source/dmapper/DomainMapper_Impl.cxx |    7 ++++
 3 files changed, 38 insertions(+)

New commits:
commit 94bf4908a6661101c270ef647e33dde09f16ac08
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Wed Nov 9 13:35:11 2022 +0100
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Wed Nov 9 16:34:48 2022 +0100

    tdf#148799 DOCX import: fix invalid formulas with comma
    
    Writer formulas must contain decimal points instead of commas,
    otherwise automatic update of the formulas, e.g. moving text
    cursor in the table, results ** Expression is faulty ** instead
    of the recalculated value. The only way to get standard
    Writer formulas is to replace the commas with points in numbers
    in writerfilter.
    
    Note: only formula cells support comma localization,
    but not formula fields yet, so the recalculated values show
    decimal point instead of decimal comma.
    
    Follow-up to commit 1abf4e6d07ca0ac31bc54f812df84efc82d2af1b
    "DOCX import: don't throw away cached value of SwHiddenTextField ...",
    see also tdf#136106.
    
    Change-Id: Id5e6dc2b87afc4e8fda0d5c4347ba7942a8989b7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142488
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/sw/qa/extras/uiwriter/data/tdf148799.docx 
b/sw/qa/extras/uiwriter/data/tdf148799.docx
new file mode 100644
index 000000000000..280fa18c15b5
Binary files /dev/null and b/sw/qa/extras/uiwriter/data/tdf148799.docx differ
diff --git a/sw/qa/extras/uiwriter/uiwriter8.cxx 
b/sw/qa/extras/uiwriter/uiwriter8.cxx
index dbb1d4fda678..674747b6c0d7 100644
--- a/sw/qa/extras/uiwriter/uiwriter8.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter8.cxx
@@ -1382,6 +1382,37 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf146573)
     CPPUNIT_ASSERT_EQUAL(OUString("204"), xCellA4->getString());
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf148799)
+{
+    // load a document with table formulas with comman delimiter
+    SwDoc* pDoc = createSwDoc("tdf148799.docx");
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+
+    // check formula update
+
+    // put cursor in the first table row
+    pWrtShell->Down(/*bSelect=*/false, /*nCount=*/1);
+
+    uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> 
xTables(xTextTablesSupplier->getTextTables(),
+                                                    uno::UNO_QUERY);
+
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount());
+
+    uno::Reference<text::XTextTable> xTextTable(xTables->getByIndex(0), 
uno::UNO_QUERY);
+
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(5), xTextTable->getRows()->getCount());
+
+    // These were "** Expression is faulty **"
+
+    uno::Reference<text::XTextRange> xCellA1(xTextTable->getCellByName("D3"), 
uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("2.3"), xCellA1->getString());
+    uno::Reference<text::XTextRange> xCellA3(xTextTable->getCellByName("D4"), 
uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("2345"), xCellA3->getString());
+    uno::Reference<text::XTextRange> xCellA4(xTextTable->getCellByName("D5"), 
uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("23684.5"), xCellA4->getString());
+}
+
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf148849)
 {
     // load a document with a table and an empty paragraph before the table
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx 
b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index b5afddc7a494..0e436fe165b9 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -5552,6 +5552,13 @@ OUString DomainMapper_Impl::convertFieldFormula(const 
OUString& input) {
     icu::RegexMatcher rmatch6("\\b(ABOVE|BELOW|LEFT|RIGHT)\\b", usInput, 
rMatcherFlags, status);
     usInput = rmatch6.replaceAll(icu::UnicodeString(" $1 "), status);
 
+    /* fix decimal separator */
+    if ( m_pSettingsTable->GetDecimalSymbol() == "," )
+    {
+        icu::RegexMatcher rmatch7("\\b([0-9]+),([0-9]+([eE][-]?[0-9]+)?)\\b", 
usInput, rMatcherFlags, status);
+        usInput = rmatch7.replaceAll(icu::UnicodeString("$1.$2"), status);
+    }
+
     return OUString(usInput.getTerminatedBuffer());
 }
 

Reply via email to