sc/source/ui/docshell/impex.cxx |   73 ++++++++++++++++++++++++----------------
 1 file changed, 44 insertions(+), 29 deletions(-)

New commits:
commit 6b768542ddd52573bbdb0e7b5b85ce5a9dd4551d
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Thu Mar 17 22:44:26 2022 +0100
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Fri Mar 18 11:07:26 2022 +0100

    Resolves: tdf#148054 Advance offset for all columns, tdf#104927 regression
    
    Regression from
    
        commit 621c189173b35ac7f5ce4c578f57045479c63ab6
        CommitDate: Sat Jan 9 05:13:55 2021 +0100
    
            tdf#104927 consider character width for CSV import
    
    that for fixed width introduced a visual count of character widths
    for CJK IVS characters but did not advance the character offset
    for skipped hidden columns.
    
    Instead of having to ask bDetermineRange three times in the loop,
    split off an extra loop for bDetermineRange, advancing the offset
    then is straight forward and just only non-skipped columns are
    extracted and written to document.
    
    Change-Id: Ib6ab6b68c5fc0f6ff854d629d75742c39ed6ddf5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131722
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins

diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx
index c6760535ef30..5efa54703d73 100644
--- a/sc/source/ui/docshell/impex.cxx
+++ b/sc/source/ui/docshell/impex.cxx
@@ -1620,40 +1620,55 @@ bool ScImportExport::ExtText2Doc( SvStream& rStrm )
             bool bMultiLine = false;
             if ( bFixed ) //  Fixed line length
             {
-                sal_Int32 nStartIdx = 0;
-                // 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.
-                for ( i=0; i<nInfoCount && nCol <= rDoc.MaxCol()+1; i++ )
+                if (bDetermineRange)
                 {
-                    sal_uInt8 nFmt = pColFormat[i];
-                    if (nFmt != SC_COL_SKIP)        // otherwise don't 
increment nCol either
+                    // 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.
+                    for (i=0; i < nInfoCount && nCol <= rDoc.MaxCol()+1; ++i)
                     {
-                        if (nCol > rDoc.MaxCol())
-                            bOverflowCol = true;    // display warning on 
import
-                        else if (!bDetermineRange)
+                        const sal_uInt8 nFmt = pColFormat[i];
+                        if (nFmt != SC_COL_SKIP)        // otherwise don't 
increment nCol either
+                        {
+                            if (nCol > rDoc.MaxCol())
+                                bOverflowCol = true;    // display warning on 
import
+                            ++nCol;
+                        }
+                    }
+                }
+                else
+                {
+                    sal_Int32 nStartIdx = 0;
+                    // Same maxcol+1 check reason as above.
+                    for (i=0; i < nInfoCount && nCol <= rDoc.MaxCol()+1; ++i)
+                    {
+                        sal_Int32 nNextIdx = nStartIdx;
+                        if (i + 1 < nInfoCount)
+                            CountVisualWidth( aLine, nNextIdx, pColStart[i+1] 
- pColStart[i] );
+                        else
+                            nNextIdx = nLineLen;
+                        sal_uInt8 nFmt = pColFormat[i];
+                        if (nFmt != SC_COL_SKIP)        // otherwise don't 
increment nCol either
                         {
-                            sal_Int32 nNextIdx = nStartIdx;
-                            if ( i + 1 < nInfoCount )
-                                CountVisualWidth( aLine, nNextIdx, 
pColStart[i+1] - pColStart[i] );
+                            if (nCol > rDoc.MaxCol())
+                                bOverflowCol = true;    // display warning on 
import
                             else
-                                nNextIdx = nLineLen;
-
-                            bool bIsQuoted = false;
-                            aCell = lcl_GetFixed( aLine, nStartIdx, nNextIdx, 
bIsQuoted, bOverflowCell );
-                            if (bIsQuoted && bQuotedAsText)
-                                nFmt = SC_COL_TEXT;
-
-                            bMultiLine |= lcl_PutString(
-                                aDocImport, !mbOverwriting, nCol, nRow, nTab, 
aCell, nFmt,
-                                &aNumFormatter, bDetectNumFormat, 
bEvaluateFormulas, bSkipEmptyCells,
-                                aTransliteration, aCalendar,
-                                pEnglishTransliteration.get(), 
pEnglishCalendar.get());
-
-                            nStartIdx = nNextIdx;
+                            {
+                                bool bIsQuoted = false;
+                                aCell = lcl_GetFixed( aLine, nStartIdx, 
nNextIdx, bIsQuoted, bOverflowCell );
+                                if (bIsQuoted && bQuotedAsText)
+                                    nFmt = SC_COL_TEXT;
+
+                                bMultiLine |= lcl_PutString(
+                                        aDocImport, !mbOverwriting, nCol, 
nRow, nTab, aCell, nFmt,
+                                        &aNumFormatter, bDetectNumFormat, 
bEvaluateFormulas, bSkipEmptyCells,
+                                        aTransliteration, aCalendar,
+                                        pEnglishTransliteration.get(), 
pEnglishCalendar.get());
+                            }
+                            ++nCol;
                         }
-                        ++nCol;
+                        nStartIdx = nNextIdx;
                     }
                 }
             }

Reply via email to