sc/qa/extras/macros-test.cxx             |   40 +++++++++++++++++++++++++++++++
 sc/qa/extras/testdocuments/tdf104902.ods |binary
 sc/source/ui/view/viewfunc.cxx           |   17 ++++++++++++-
 3 files changed, 56 insertions(+), 1 deletion(-)

New commits:
commit 44d237c375b7ef9a5a61a2f752bd19b57649ffbd
Author:     Andreas Heinisch <andreas.heini...@yahoo.de>
AuthorDate: Thu Dec 30 19:57:10 2021 +0100
Commit:     Andreas Heinisch <andreas.heini...@yahoo.de>
CommitDate: Tue Feb 15 07:46:03 2022 +0100

    tdf#104902 - Handle embedded newline in Calc's .uno:EnterString
    
    Change-Id: I6377aebb06b6e6873ce61984a887d9e16eecd361
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127766
    Tested-by: Jenkins
    Reviewed-by: Andreas Heinisch <andreas.heini...@yahoo.de>

diff --git a/sc/qa/extras/macros-test.cxx b/sc/qa/extras/macros-test.cxx
index 802f44a0541c..6c41b269111e 100644
--- a/sc/qa/extras/macros-test.cxx
+++ b/sc/qa/extras/macros-test.cxx
@@ -44,6 +44,7 @@ public:
     void testPasswordProtectedStarBasic();
     void testTdf114427();
     void testRowColumn();
+    void testTdf104902();
     void testTdf142033();
     void testPasswordProtectedUnicodeString();
     void testPasswordProtectedArrayInUserType();
@@ -70,6 +71,7 @@ public:
     CPPUNIT_TEST(testPasswordProtectedStarBasic);
     CPPUNIT_TEST(testTdf114427);
     CPPUNIT_TEST(testRowColumn);
+    CPPUNIT_TEST(testTdf104902);
     CPPUNIT_TEST(testTdf142033);
     CPPUNIT_TEST(testPasswordProtectedUnicodeString);
     CPPUNIT_TEST(testPasswordProtectedArrayInUserType);
@@ -322,6 +324,44 @@ void ScMacrosTest::testMacroButtonFormControlXlsxExport()
     assertXPath(pWorkbookDoc, "//x:workbook/definedNames", 0);
 }
 
+void ScMacrosTest::testTdf104902()
+{
+    OUString aFileName;
+    createFileURL(u"tdf104902.ods", aFileName);
+    uno::Reference<css::lang::XComponent> xComponent = 
loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument");
+
+    Any aRet;
+    Sequence<sal_Int16> aOutParamIndex;
+    Sequence<Any> aOutParam;
+    Sequence<uno::Any> aParams;
+
+    SfxObjectShell::CallXScript(
+        xComponent,
+        
"vnd.sun.Star.script:Standard.Module1.display_bug?language=Basic&location=document",
+        aParams, aRet, aOutParamIndex, aOutParam);
+
+    // Export to ODS
+    saveAndReload(xComponent, "calc8");
+    CPPUNIT_ASSERT(xComponent);
+
+    SfxObjectShell* pFoundShell = 
SfxObjectShell::GetShellFromComponent(xComponent);
+
+    CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell);
+    ScDocShell* pDocSh = static_cast<ScDocShell*>(pFoundShell);
+    ScDocument& rDoc = pDocSh->GetDocument();
+
+    CPPUNIT_ASSERT_EQUAL(OUString("string no newlines"), 
rDoc.GetString(ScAddress(0, 0, 0)));
+
+    // Without the fix in place, this test would have failed with
+    // - Expected: string with
+    // newlines
+    // - Actual  : string withnewlines
+    CPPUNIT_ASSERT_EQUAL(OUString(u"string with" + OUStringChar(u'\xA') + 
u"newlines"), rDoc.GetString(ScAddress(0, 1, 0)));
+
+    css::uno::Reference<css::util::XCloseable> xCloseable(xComponent, 
css::uno::UNO_QUERY_THROW);
+    xCloseable->close(true);
+}
+
 void ScMacrosTest::testTdf142033()
 {
     OUString aFileName;
diff --git a/sc/qa/extras/testdocuments/tdf104902.ods 
b/sc/qa/extras/testdocuments/tdf104902.ods
new file mode 100644
index 000000000000..8524522fdcd3
Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf104902.ods differ
diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx
index 26aa7907779a..a1a5083205b8 100644
--- a/sc/source/ui/view/viewfunc.cxx
+++ b/sc/source/ui/view/viewfunc.cxx
@@ -75,6 +75,7 @@
 #include <comphelper/lok.hxx>
 #include <conditio.hxx>
 #include <columnspanset.hxx>
+#include <stringutil.hxx>
 
 #include <memory>
 
@@ -575,10 +576,24 @@ void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB 
nTab,
     }
     else
     {
+        ScFieldEditEngine& rEngine = rDoc.GetEditEngine();
         for (const auto& rTab : rMark)
         {
             bool bNumFmtSet = false;
-            rFunc.SetNormalString( bNumFmtSet, ScAddress( nCol, nRow, rTab ), 
rString, false );
+            const ScAddress aScAddress(nCol, nRow, rTab);
+
+            // tdf#104902 - handle embedded newline
+            if (ScStringUtil::isMultiline(rString))
+            {
+                rEngine.SetTextCurrentDefaults(rString);
+                rDoc.SetEditText(aScAddress, rEngine.CreateTextObject());
+                pDocSh->AdjustRowHeight(nRow, nRow, rTab);
+            }
+            else
+            {
+                rFunc.SetNormalString(bNumFmtSet, aScAddress, rString, false);
+            }
+
             if (bNumFmtSet)
             {
                 /* FIXME: if set on any sheet results in changed only on

Reply via email to