sc/qa/uitest/data/tdf129701.ods                        |binary
 sc/qa/uitest/pasteSpecial/tdf129701-PasteUnformated.py |   70 +++++++++++++++++
 sc/source/ui/docshell/impex.cxx                        |   19 +++-
 3 files changed, 86 insertions(+), 3 deletions(-)

New commits:
commit 60e0ebe633b1dee8bb2a66b9d133f5303749d8d5
Author:     Laurent Balland <laurent.ball...@mailo.fr>
AuthorDate: Thu Dec 7 19:38:54 2023 +0100
Commit:     Christian Lohmaier <lohmaier+libreoff...@googlemail.com>
CommitDate: Thu Mar 7 11:59:46 2024 +0100

    tdf#129701 Skip empty cell: treat last column
    
    When pasting data as text, with "Skip empty cells" not checked, empty
    cells in the last column of the source do not empty cells in
    destination, because there is nothing anymore to paste and while loop
    stops.
    This commit adds a flag to check if the last cell of each line is empty,
    and treat it if "Skip empty cells" is not checked.
    
    Add UITest to Copy data with empty cells;
    Paste Unformatted text, without "Skip empty cells";
    Check data with empty cells in last column.
    
    Change-Id: Idec823fb1c27b803f49c6d13d6c757ef0f41e437
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160951
    Tested-by: Jenkins
    Reviewed-by: Laurent Balland <laurent.ball...@mailo.fr>
    (cherry picked from commit e66ffda7c7f1e78dbca082ff7549ded121dc7356)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163536
    Reviewed-by: Christian Lohmaier <lohmaier+libreoff...@googlemail.com>

diff --git a/sc/qa/uitest/data/tdf129701.ods b/sc/qa/uitest/data/tdf129701.ods
new file mode 100644
index 000000000000..94407fcd566e
Binary files /dev/null and b/sc/qa/uitest/data/tdf129701.ods differ
diff --git a/sc/qa/uitest/pasteSpecial/tdf129701-PasteUnformated.py 
b/sc/qa/uitest/pasteSpecial/tdf129701-PasteUnformated.py
new file mode 100644
index 000000000000..596cd62f8bc1
--- /dev/null
+++ b/sc/qa/uitest/pasteSpecial/tdf129701-PasteUnformated.py
@@ -0,0 +1,70 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+from uitest.framework import UITestCase
+from libreoffice.uno.propertyvalue import mkPropertyValues
+from uitest.uihelper.common import get_url_for_data_file
+from uitest.uihelper.common import get_state_as_dict
+from libreoffice.calc.document import get_cell_by_position
+
+class tdf129701(UITestCase):
+
+    def test_tdf129701(self):
+
+        with self.ui_test.load_file(get_url_for_data_file("tdf129701.ods")):
+            xCalcDoc = self.xUITest.getTopFocusWindow()
+            gridwin = xCalcDoc.getChild("grid_window")
+            gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": 
"D21:F25"}))
+            self.xUITest.executeCommand(".uno:Copy")
+
+            gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "J4"}))
+            with 
self.ui_test.execute_dialog_through_command(".uno:PasteUnformatted", 
close_button="ok") as xDialog:
+
+                xSkipEmtyCells   = xDialog.getChild("skipemptycells")
+                xSeparatedBy     = xDialog.getChild("toseparatedby")
+                xTab             = xDialog.getChild("tab")
+                xMergeDelimiters = xDialog.getChild("mergedelimiters")
+
+                xSeparatedBy.executeAction("CLICK", tuple())
+                if get_state_as_dict(xTab)['Selected'] == 'false':
+                    xTab.executeAction("CLICK", tuple())
+                if get_state_as_dict(xMergeDelimiters)['Selected'] == 'true':
+                    xMergeDelimiters.executeAction("CLICK", tuple())
+                if get_state_as_dict(xSkipEmtyCells)['Selected'] == 'true':
+                    xSkipEmtyCells.executeAction("CLICK", tuple())
+                # Check wether Skip empty cells is unselected
+                self.assertEqual('false', 
get_state_as_dict(xSkipEmtyCells)['Selected'])
+
+            document = self.ui_test.get_component()
+            # Without the fix in place, this test would have failed with
+            # non empty cells in column 11
+
+            self.assertEqual( "x1", get_cell_by_position(document, 0, 9, 
3).getString())
+            self.assertEqual( ""  , get_cell_by_position(document, 0,10, 
3).getString())
+            self.assertEqual( ""  , get_cell_by_position(document, 0,11, 
3).getString())
+            self.assertEqual("A16", get_cell_by_position(document, 0,12, 
3).getString())
+            self.assertEqual( ""  , get_cell_by_position(document, 0, 9, 
4).getString())
+            self.assertEqual( "x2", get_cell_by_position(document, 0,10, 
4).getString())
+            self.assertEqual( ""  , get_cell_by_position(document, 0,11, 
4).getString())
+            self.assertEqual("A17", get_cell_by_position(document, 0,12, 
4).getString())
+            self.assertEqual( ""  , get_cell_by_position(document, 0, 9, 
5).getString())
+            self.assertEqual( ""  , get_cell_by_position(document, 0,10, 
5).getString())
+            self.assertEqual( "x3", get_cell_by_position(document, 0,11, 
5).getString())
+            self.assertEqual("A18", get_cell_by_position(document, 0,12, 
5).getString())
+            self.assertEqual( ""  , get_cell_by_position(document, 0, 9, 
6).getString())
+            self.assertEqual( "x4", get_cell_by_position(document, 0,10, 
6).getString())
+            self.assertEqual( ""  , get_cell_by_position(document, 0,11, 
6).getString())
+            self.assertEqual("A19", get_cell_by_position(document, 0,12, 
6).getString())
+            self.assertEqual( "x5", get_cell_by_position(document, 0, 9, 
7).getString())
+            self.assertEqual( "x6", get_cell_by_position(document, 0,10, 
7).getString())
+            self.assertEqual( "x7", get_cell_by_position(document, 0,11, 
7).getString())
+            self.assertEqual("A20", get_cell_by_position(document, 0,12, 
7).getString())
+
+            self.ui_test.close_doc()
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx
index 4a585657de1a..8e6315db9419 100644
--- a/sc/source/ui/docshell/impex.cxx
+++ b/sc/source/ui/docshell/impex.cxx
@@ -1662,6 +1662,7 @@ bool ScImportExport::ExtText2Doc( SvStream& rStrm )
     ScDocumentImport aDocImport(rDoc);
     do
     {
+        SCCOL nLastCol = nEndCol; // tdf#129701 preserve value of nEndCol
         for( ;; )
         {
             aLine = ReadCsvLine(rStrm, !bFixed, aSeps, cStr, cDetectSep);
@@ -1745,11 +1746,14 @@ bool ScImportExport::ExtText2Doc( SvStream& rStrm )
                 SCCOL nSourceCol = 0;
                 sal_uInt16 nInfoStart = 0;
                 const sal_Unicode* p = aLine.getStr();
+                // tdf#129701 if there is only one column, and user wants to 
treat empty cells,
+                // we need to detect *p = null
+                bool bIsLastColEmpty = !(*p) && !bSkipEmptyCells && 
!bDetermineRange;
                 // Yes, the check is nCol<=rDoc.MaxCol()+1, +1 because it is 
only an
                 // overflow if there is really data following to be put behind
                 // the last column, which doesn't happen if info is
                 // SC_COL_SKIP.
-                while (*p && nCol <= rDoc.MaxCol()+1)
+                while ( (*p || bIsLastColEmpty) && nCol <= rDoc.MaxCol()+1)
                 {
                     bool bIsQuoted = false;
                     p = ScImportExport::ScanNextFieldFromString( p, aCell,
@@ -1780,9 +1784,18 @@ bool ScImportExport::ExtText2Doc( SvStream& rStrm )
                                 aTransliteration, aCalendar,
                                 pEnglishTransliteration.get(), 
pEnglishCalendar.get());
                         }
-                        ++nCol;
-                    }
+                        if (bIsLastColEmpty)
+                        {
+                            bIsLastColEmpty = false; // toggle to stop
+                        }
+                        else
+                        {
+                            ++nCol;
+                            // tdf#129701 detect if there is a last empty 
column when we need it
+                            bIsLastColEmpty = !(*p) && !bSkipEmptyCells && 
!bDetermineRange && nCol == nLastCol;
+                        }
 
+                    }
                     ++nSourceCol;
                 }
             }

Reply via email to