[Libreoffice-commits] .: sc/inc sc/source

Eike Rathke erack at kemper.freedesktop.org
Sun Apr 15 05:57:16 PDT 2012


 sc/inc/stringutil.hxx              |   10 ++++++++++
 sc/source/core/data/column3.cxx    |   21 +++++++++++++--------
 sc/source/core/data/dpoutput.cxx   |    3 +++
 sc/source/core/tool/stringutil.cxx |    3 ++-
 sc/source/filter/rtf/eeimpars.cxx  |    1 +
 sc/source/ui/docshell/impex.cxx    |    1 +
 6 files changed, 30 insertions(+), 9 deletions(-)

New commits:
commit 5a560e4300295629592716697f13bc803bdeba3c
Author: Eike Rathke <erack at redhat.com>
Date:   Sun Apr 15 14:56:55 2012 +0200

    resolved fdo#48731 in CSV import do not strip leading apostrophe

diff --git a/sc/inc/stringutil.hxx b/sc/inc/stringutil.hxx
index 66b68a2..245714f 100644
--- a/sc/inc/stringutil.hxx
+++ b/sc/inc/stringutil.hxx
@@ -61,6 +61,16 @@ struct SC_DLLPUBLIC ScSetStringParam
      */
     bool mbSetTextCellFormat;
 
+    /**
+     * When true, treat input with a leading apostrophe / single quote special
+     * in that it escapes numeric or date/time input such that it is not
+     * interpreted and the input string is taken instead. This can be used
+     * during text file import so the leading apostrophe is not lost if it
+     * precedes a numeric value.
+     * Usually set mbHandleApostrophe = !mbSetTextCellFormat
+     */
+    bool mbHandleApostrophe;
+
     ScSetStringParam();
 };
 
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 8f6397e..0e48e9b 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -1234,14 +1234,19 @@ bool ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString,
         }
         else if ( cFirstChar == '\'')                       // 'Text
         {
-            // Cell format is not 'Text', and the first char
-            // is an apostrophe.  Check if the input is considered a number.
-            String aTest = rString.Copy(1);
-            double fTest;
-            if (aParam.mpNumFormatter->IsNumberFormat(aTest, nIndex, fTest))
-                // This is a number.  Strip out the first char.
-                pNewCell = new ScStringCell(aTest);
-            else
+            bool bNumeric = false;
+            if (aParam.mbHandleApostrophe)
+            {
+                // Cell format is not 'Text', and the first char
+                // is an apostrophe.  Check if the input is considered a number.
+                String aTest = rString.Copy(1);
+                double fTest;
+                bNumeric = aParam.mpNumFormatter->IsNumberFormat(aTest, nIndex, fTest);
+                if (bNumeric)
+                    // This is a number.  Strip out the first char.
+                    pNewCell = new ScStringCell(aTest);
+            }
+            if (!bNumeric)
                 // This is a normal text. Take it as-is.
                 pNewCell = new ScStringCell(rString);
         }
diff --git a/sc/source/core/data/dpoutput.cxx b/sc/source/core/data/dpoutput.cxx
index f903f0d..875371f 100644
--- a/sc/source/core/data/dpoutput.cxx
+++ b/sc/source/core/data/dpoutput.cxx
@@ -794,11 +794,13 @@ void ScDPOutput::HeaderCell( SCCOL nCol, SCROW nRow, SCTAB nTab,
         {
             aParam.mbDetectNumberFormat = true;
             aParam.mbSetTextCellFormat = false;
+            aParam.mbHandleApostrophe = true;
         }
         else
         {
             aParam.mbDetectNumberFormat = false;
             aParam.mbSetTextCellFormat = true;
+            aParam.mbHandleApostrophe = false;
         }
         pDoc->SetString(nCol, nRow, nTab, rData.Caption, &aParam);
     }
@@ -836,6 +838,7 @@ void ScDPOutput::FieldCell(
     ScSetStringParam aParam;
     aParam.mbDetectNumberFormat = false;
     aParam.mbSetTextCellFormat = true;
+    aParam.mbHandleApostrophe = false;
     pDoc->SetString(nCol, nRow, nTab, rData.maCaption, &aParam);
 
     if (bInTable)
diff --git a/sc/source/core/tool/stringutil.cxx b/sc/source/core/tool/stringutil.cxx
index 263e22c..a4cb4b3 100644
--- a/sc/source/core/tool/stringutil.cxx
+++ b/sc/source/core/tool/stringutil.cxx
@@ -39,7 +39,8 @@ using ::rtl::OUStringBuffer;
 ScSetStringParam::ScSetStringParam() :
     mpNumFormatter(NULL),
     mbDetectNumberFormat(true),
-    mbSetTextCellFormat(false)
+    mbSetTextCellFormat(false),
+    mbHandleApostrophe(true)
 {
 }
 
diff --git a/sc/source/filter/rtf/eeimpars.cxx b/sc/source/filter/rtf/eeimpars.cxx
index 36ece2b..2ecf7dd 100644
--- a/sc/source/filter/rtf/eeimpars.cxx
+++ b/sc/source/filter/rtf/eeimpars.cxx
@@ -337,6 +337,7 @@ void ScEEImport::WriteToDocument( bool bSizeColsRows, double nOutputFactor, SvNu
                 aParam.mpNumFormatter = pFormatter;
                 aParam.mbDetectNumberFormat = true;
                 aParam.mbSetTextCellFormat = true;
+                aParam.mbHandleApostrophe = false;
 
                 if (!aValStr.isEmpty())
                     mpDoc->SetValue( nCol, nRow, nTab, fVal );
diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx
index cf51c07..f9d00ab 100644
--- a/sc/source/ui/docshell/impex.cxx
+++ b/sc/source/ui/docshell/impex.cxx
@@ -1228,6 +1228,7 @@ static bool lcl_PutString(
         aParam.mpNumFormatter = pFormatter;
         aParam.mbDetectNumberFormat = bDetectNumFormat;
         aParam.mbSetTextCellFormat = true;
+        aParam.mbHandleApostrophe = false;
         pDoc->SetString( nCol, nRow, nTab, rStr, &aParam );
     }
     else


More information about the Libreoffice-commits mailing list