From c83746be5baf73df9c0f44bd5c46fa87d3e912a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bayram=20=C3=87i=C3=A7ek?= Date: Thu, 19 Mar 2026 13:55:10 +0300 Subject: [PATCH] tdf#169326: ignore line breaks in ODS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit if ODS file saved from XLSX - follow-up for 992a07788b18e5eb5cce33bc1a340b60116cde4e - added a unittest. Signed-off-by: Bayram Çiçek Change-Id: Ie896399ac09d6823586b2327e48a90c5e62593c4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/202167 Tested-by: Jenkins Reviewed-by: Caolán McNamara --- sc/qa/unit/subsequent_export_test.cxx | 33 +++++++++++++++++++++++++-- sc/source/ui/unoobj/defltuno.cxx | 25 ++++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/sc/qa/unit/subsequent_export_test.cxx b/sc/qa/unit/subsequent_export_test.cxx index 3fda647a81e0..2c26c3290ea9 100644 --- a/sc/qa/unit/subsequent_export_test.cxx +++ b/sc/qa/unit/subsequent_export_test.cxx @@ -1841,13 +1841,42 @@ CPPUNIT_TEST_FIXTURE(ScExportTest, testTdf169326_ignoreLineBreaksInReferencedCel createScDoc("xlsx/tdf169326_ignore_line_breaks_in_referenced_cells.xlsx"); ScDocument* pDoc = getScDoc(); - // A1 contains "Hello\nWorld" (with a line break), and B1 contains the formula "=A1". - // The formula in B1 (which references A1) should evaluate to "HelloWorld", ignoring the line break in A1. + // A1 contains "Hello\nWorld" (with a line break), and B2 contains the formula "=A1". + // The formula in B2 (which references A1) should evaluate to "HelloWorld", ignoring the line break in A1. CPPUNIT_ASSERT_EQUAL(u"HelloWorld"_ustr, pDoc->GetString(ScAddress(1, 1, 0))); // Set formula in C3 to reference A1 as well. pDoc->SetString(ScAddress(2, 2, 0), u"=A1"_ustr); CPPUNIT_ASSERT_EQUAL(u"HelloWorld"_ustr, pDoc->GetString(ScAddress(2, 2, 0))); + + // save as ODS and reload. + saveAndReload(TestFilter::ODS); + ScDocument* pOdsDoc = getScDoc(); + + // ODS documents saved from XLSX, should also ignore line breaks in referenced cells. + CPPUNIT_ASSERT_EQUAL(u"HelloWorld"_ustr, pOdsDoc->GetString(ScAddress(1, 1, 0))); // B2 + CPPUNIT_ASSERT_EQUAL(u"HelloWorld"_ustr, pOdsDoc->GetString(ScAddress(2, 2, 0))); // C3 + + // Set formula in D4 to reference A1. + pOdsDoc->SetString(ScAddress(3, 3, 0), u"=A1"_ustr); + CPPUNIT_ASSERT_EQUAL(u"HelloWorld"_ustr, pOdsDoc->GetString(ScAddress(3, 3, 0))); +} + +CPPUNIT_TEST_FIXTURE(ScExportTest, testTdf169326_testLineBreaksInODS) +{ + // create an empty ODS document. + createScDoc(); + ScDocument* pDoc = getScDoc(); + + // Set a string with line break in A1. + pDoc->SetString(ScAddress(0, 0, 0), u"Hello\nWorld"_ustr); + + // set a formula in B2 to reference A1. + pDoc->SetString(ScAddress(1, 1, 0), u"=A1"_ustr); + + // The formula in B2 should evaluate to "Hello\nWorld", preserving the line break in A1. + // Because, newly created ODS documents should not ignore line breaks. + CPPUNIT_ASSERT_EQUAL(u"Hello\nWorld"_ustr, pDoc->GetString(ScAddress(1, 1, 0))); } CPPUNIT_TEST_FIXTURE(ScExportTest, testCellValuesExportODS) diff --git a/sc/source/ui/unoobj/defltuno.cxx b/sc/source/ui/unoobj/defltuno.cxx index 7b4655f3c080..ac635699ecd4 100644 --- a/sc/source/ui/unoobj/defltuno.cxx +++ b/sc/source/ui/unoobj/defltuno.cxx @@ -63,6 +63,7 @@ static std::span lcl_GetDocDefaultsMap() { SC_UNO_CTL_CHEIGHT, ATTR_CTL_FONT_HEIGHT, cppu::UnoType::get(), 0, MID_FONTHEIGHT | CONVERT_TWIPS }, { SC_UNO_STANDARDDEC, 0, cppu::UnoType::get(), 0, 0 }, { SC_UNO_TABSTOPDIS, 0, cppu::UnoType::get(), 0, 0 }, + { SC_UNONAME_WRAP, 0, cppu::UnoType::get(), 0, 0 }, }; return aDocDefaultsMap_Impl; } @@ -138,6 +139,22 @@ void SAL_CALL ScDocDefaultsObj::setPropertyValue( rDoc.SetDocOptions(aDocOpt); } } + else if(aPropertyName == SC_UNONAME_WRAP) + { + ScDocument& rDoc = pDocShell->GetDocument(); + ScDocOptions aDocOpt(rDoc.GetDocOptions()); + bool bValue = false; + + aValue >>= bValue; + if (bValue) + { + // ODS documents converted from XLSX: + // if wrap option is enabled, it means the original XLSX document had some cells with line breaks. + // we need to keep the same behavior in ODS documents too. + aDocOpt.SetIgnoreLineBreaks(true); + rDoc.SetDocOptions(aDocOpt); + } + } else if (aPropertyName == SC_UNO_TABSTOPDIS) { ScDocument& rDoc = pDocShell->GetDocument(); @@ -221,6 +238,14 @@ uno::Any SAL_CALL ScDocDefaultsObj::getPropertyValue( const OUString& aPropertyN if (nPrec <= ::std::numeric_limits::max()) aRet <<= static_cast (nPrec); } + else if(aPropertyName == SC_UNONAME_WRAP) + { + ScDocument& rDoc = pDocShell->GetDocument(); + const ScDocOptions& aDocOpt = rDoc.GetDocOptions(); + + bool bWrap = aDocOpt.IsIgnoreLineBreaks(); + aRet <<= bWrap; + } else if (aPropertyName == SC_UNO_TABSTOPDIS) { ScDocument& rDoc = pDocShell->GetDocument();