From c6688def010fcb6854c6d896efe7186ff6c63475 Mon Sep 17 00:00:00 2001 From: László Németh Date: Sat, 12 Nov 2022 11:37:23 +0100 Subject: tdf#151993 DOCX import: convert decimal comma only if needed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit E.g. convert en_US document with decimal comma, but not de_DE document with decimal comma. Regression from commit 94bf4908a6661101c270ef647e33dde09f16ac08 "tdf#148799 DOCX import: fix invalid formulas with comma". DOCX allows to set decimal symbol independently from the locale of the document, so if the DOCX document uses comma, but its locale ("language") has got a default decimal point in Writer, 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, if document language has a default decimal point in Writer. Note: not only document language, but area setting of LibreOffice installation modifies formula handling. I.e. plain numbers recognized with comma only if area setting is modified to a language, which uses decimal comma (but formulas still need decimal points, if the language of the document is a locale with default decimal point). E.g. an en_US DOCX document with decimal comma, or a de_DE document with decimal comma loaded correctly now, but recognizing cell content with a single number with comma needs to set also the correct area setting. Change-Id: I16dba1e10bf4271a44c435b5b09345d8d698b91d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142611 Tested-by: Jenkins Reviewed-by: László Németh --- sw/qa/extras/uiwriter/uiwriter8.cxx | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'sw/qa/extras/uiwriter/uiwriter8.cxx') diff --git a/sw/qa/extras/uiwriter/uiwriter8.cxx b/sw/qa/extras/uiwriter/uiwriter8.cxx index 83698fa36a18..e6b5d0dad60c 100644 --- a/sw/qa/extras/uiwriter/uiwriter8.cxx +++ b/sw/qa/extras/uiwriter/uiwriter8.cxx @@ -1400,7 +1400,8 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf146573) CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf148799) { - // load a document with table formulas with comma delimiter + // load a document with table formulas with comma delimiter, + // but with a document language with default point delimiter createSwDoc("tdf148799.docx"); SwDoc* pDoc = getSwDoc(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); @@ -1430,6 +1431,34 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf148799) CPPUNIT_ASSERT_EQUAL(OUString("23684.5"), xCellA4->getString()); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf151993) +{ + // load a document with table formulas with comma delimiter + // (with a document language with default comma delimiter) + createSwDoc("tdf151993.docx"); + SwDoc* pDoc = getSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + + // check formula update + + // put cursor in the first table row + pWrtShell->Down(/*bSelect=*/false, /*nCount=*/1); + + uno::Reference xTextTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xTables(xTextTablesSupplier->getTextTables(), + uno::UNO_QUERY); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); + + uno::Reference xTextTable(xTables->getByIndex(0), uno::UNO_QUERY); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTextTable->getRows()->getCount()); + + // This was 0 + uno::Reference xCellA1(xTextTable->getCellByName("A2"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("30"), xCellA1->getString()); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf148849) { // load a document with a table and an empty paragraph before the table -- cgit