tdf#169326: ignore line breaks in ODS

if ODS file saved from XLSX

- follow-up for 992a07788b
- added a unittest.

Signed-off-by: Bayram Çiçek <bayram.cicek@collabora.com>
Change-Id: Ie896399ac09d6823586b2327e48a90c5e62593c4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/202167
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
This commit is contained in:
Bayram Çiçek
2026-03-20 21:01:31 +01:00
committed by Caolán McNamara
parent 5e01dd364b
commit c83746be5b
2 changed files with 56 additions and 2 deletions
+31 -2
View File
@@ -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)
+25
View File
@@ -63,6 +63,7 @@ static std::span<const SfxItemPropertyMapEntry> lcl_GetDocDefaultsMap()
{ SC_UNO_CTL_CHEIGHT, ATTR_CTL_FONT_HEIGHT, cppu::UnoType<float>::get(), 0, MID_FONTHEIGHT | CONVERT_TWIPS },
{ SC_UNO_STANDARDDEC, 0, cppu::UnoType<sal_Int16>::get(), 0, 0 },
{ SC_UNO_TABSTOPDIS, 0, cppu::UnoType<sal_Int32>::get(), 0, 0 },
{ SC_UNONAME_WRAP, 0, cppu::UnoType<sal_Int16>::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<sal_Int16>::max())
aRet <<= static_cast<sal_Int16> (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();