diff options
author | Eike Rathke <erack@redhat.com> | 2012-04-15 14:56:55 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2012-04-15 14:56:55 +0200 |
commit | 5a560e4300295629592716697f13bc803bdeba3c (patch) | |
tree | 064c8efca3e5815cd49e3586777e487c227e44be | |
parent | 385017e0f2147d2a49e36d6c44ae76a1e7600668 (diff) |
resolved fdo#48731 in CSV import do not strip leading apostrophe
-rw-r--r-- | sc/inc/stringutil.hxx | 10 | ||||
-rw-r--r-- | sc/source/core/data/column3.cxx | 21 | ||||
-rw-r--r-- | sc/source/core/data/dpoutput.cxx | 3 | ||||
-rw-r--r-- | sc/source/core/tool/stringutil.cxx | 3 | ||||
-rw-r--r-- | sc/source/filter/rtf/eeimpars.cxx | 1 | ||||
-rw-r--r-- | sc/source/ui/docshell/impex.cxx | 1 |
6 files changed, 30 insertions, 9 deletions
diff --git a/sc/inc/stringutil.hxx b/sc/inc/stringutil.hxx index 66b68a2dd7e8..245714f3cc2d 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 8f6397eebe6f..0e48e9b3a181 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 f903f0d9ba49..875371f94c9b 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 263e22c8b711..a4cb4b3940e3 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 36ece2bd12a8..2ecf7ddca91f 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 cf51c0703dd7..f9d00abea95f 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 |