diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-08-13 14:20:13 -0400 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2012-08-14 12:49:59 +0200 |
commit | 22571981cdae59bce508dfd2af4c873aa216d885 (patch) | |
tree | fa1f81241f90363e634c0a646bda548cb703cdd1 | |
parent | b5edfe152737650772504dc6464dbbb2f607f453 (diff) |
fdo#53089: Avoid setting valid numbers as text during html import.
(cherry picked from commit 51f1fc69aa539dec8035195b98e0b128026388e9)
Conflicts:
sc/qa/unit/ucalc.cxx
Change-Id: I5fa9a54f70e8e4d8aac42687f2a204b2925d4619
-rw-r--r-- | sc/inc/stringutil.hxx | 26 | ||||
-rw-r--r-- | sc/qa/unit/ucalc.cxx | 9 | ||||
-rw-r--r-- | sc/source/core/data/column3.cxx | 4 | ||||
-rw-r--r-- | sc/source/core/data/dpoutput.cxx | 6 | ||||
-rw-r--r-- | sc/source/core/tool/stringutil.cxx | 2 | ||||
-rw-r--r-- | sc/source/filter/rtf/eeimpars.cxx | 2 | ||||
-rw-r--r-- | sc/source/ui/docshell/impex.cxx | 4 |
7 files changed, 40 insertions, 13 deletions
diff --git a/sc/inc/stringutil.hxx b/sc/inc/stringutil.hxx index 954d4bc1b2bb..1932f5974724 100644 --- a/sc/inc/stringutil.hxx +++ b/sc/inc/stringutil.hxx @@ -40,6 +40,25 @@ class SvNumberFormatter; */ struct SC_DLLPUBLIC ScSetStringParam { + enum TextFormatPolicy + { + /** + * Set Text number format no matter what the input string is. + */ + Always, + + /** + * Set Text number format only when the input string is considered a + * special number but we only want to detect a simple number. + */ + SpecialNumberOnly, + + /** + * Never set Text number format. + */ + Never + }; + /** * Stores the pointer to the number formatter instance to be used during * number format detection. The caller must manage the life cycle of the @@ -55,11 +74,10 @@ struct SC_DLLPUBLIC ScSetStringParam bool mbDetectNumberFormat; /** - * When true, set the format of the cell to Text when a string cell is - * requested for a number input. We may want to do this during text file - * import (csv, html etc). + * Determine when to set the 'Text' number format to the cell where the + * input string is being set. */ - bool mbSetTextCellFormat; + TextFormatPolicy meSetTextNumFormat; /** * When true, treat input with a leading apostrophe / single quote special diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 8d9febe34f22..cab47a690fc6 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -360,6 +360,15 @@ void Test::testInput() bTest = test == "'apple'"; CPPUNIT_ASSERT_MESSAGE("Text content should have retained the first apostrophe.", bTest); + // Customized string handling policy. + ScSetStringParam aParam; + aParam.mbDetectNumberFormat = false; + aParam.meSetTextNumFormat = ScSetStringParam::Always; + aParam.mbHandleApostrophe = false; + m_pDoc->SetString(0, 0, 0, "000123", &aParam); + m_pDoc->GetString(0, 0, 0, test); + CPPUNIT_ASSERT_MESSAGE("Text content should have been treated as string, not number.", test == "000123"); + m_pDoc->DeleteTab(0); } diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx index 7e35fe6050c6..aab315c30029 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -1341,7 +1341,7 @@ bool ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString, } } } - else if (!aParam.mbSetTextCellFormat) + else if (aParam.meSetTextNumFormat != ScSetStringParam::Always) { // Only check if the string is a regular number. const LocaleDataWrapper* pLocale = aParam.mpNumFormatter->GetLocaleData(); @@ -1367,7 +1367,7 @@ bool ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString, if (!pNewCell) { - if (aParam.mbSetTextCellFormat && aParam.mpNumFormatter->IsNumberFormat(rString, nIndex, nVal)) + if (aParam.meSetTextNumFormat != ScSetStringParam::Never && aParam.mpNumFormatter->IsNumberFormat(rString, nIndex, nVal)) { // Set the cell format type to Text. sal_uInt32 nFormat = aParam.mpNumFormatter->GetStandardFormat(NUMBERFORMAT_TEXT); diff --git a/sc/source/core/data/dpoutput.cxx b/sc/source/core/data/dpoutput.cxx index 34ae9d6ef462..2b86a698c846 100644 --- a/sc/source/core/data/dpoutput.cxx +++ b/sc/source/core/data/dpoutput.cxx @@ -793,13 +793,13 @@ void ScDPOutput::HeaderCell( SCCOL nCol, SCROW nRow, SCTAB nTab, if (bNumeric) { aParam.mbDetectNumberFormat = true; - aParam.mbSetTextCellFormat = false; + aParam.meSetTextNumFormat = ScSetStringParam::Never; aParam.mbHandleApostrophe = true; } else { aParam.mbDetectNumberFormat = false; - aParam.mbSetTextCellFormat = true; + aParam.meSetTextNumFormat = ScSetStringParam::Always; aParam.mbHandleApostrophe = false; } pDoc->SetString(nCol, nRow, nTab, rData.Caption, &aParam); @@ -837,7 +837,7 @@ void ScDPOutput::FieldCell( // Avoid unwanted automatic format detection. ScSetStringParam aParam; aParam.mbDetectNumberFormat = false; - aParam.mbSetTextCellFormat = true; + aParam.meSetTextNumFormat = ScSetStringParam::Always; aParam.mbHandleApostrophe = false; pDoc->SetString(nCol, nRow, nTab, rData.maCaption, &aParam); diff --git a/sc/source/core/tool/stringutil.cxx b/sc/source/core/tool/stringutil.cxx index a4cb4b3940e3..124027b5bdb7 100644 --- a/sc/source/core/tool/stringutil.cxx +++ b/sc/source/core/tool/stringutil.cxx @@ -39,7 +39,7 @@ using ::rtl::OUStringBuffer; ScSetStringParam::ScSetStringParam() : mpNumFormatter(NULL), mbDetectNumberFormat(true), - mbSetTextCellFormat(false), + meSetTextNumFormat(Never), mbHandleApostrophe(true) { } diff --git a/sc/source/filter/rtf/eeimpars.cxx b/sc/source/filter/rtf/eeimpars.cxx index 2ecf7ddca91f..b3bbf8697449 100644 --- a/sc/source/filter/rtf/eeimpars.cxx +++ b/sc/source/filter/rtf/eeimpars.cxx @@ -336,7 +336,7 @@ void ScEEImport::WriteToDocument( bool bSizeColsRows, double nOutputFactor, SvNu ScSetStringParam aParam; aParam.mpNumFormatter = pFormatter; aParam.mbDetectNumberFormat = true; - aParam.mbSetTextCellFormat = true; + aParam.meSetTextNumFormat = ScSetStringParam::SpecialNumberOnly; aParam.mbHandleApostrophe = false; if (!aValStr.isEmpty()) diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx index 50333f834a59..ab2fc5ed59af 100644 --- a/sc/source/ui/docshell/impex.cxx +++ b/sc/source/ui/docshell/impex.cxx @@ -1227,7 +1227,7 @@ static bool lcl_PutString( ScSetStringParam aParam; aParam.mpNumFormatter = pFormatter; aParam.mbDetectNumberFormat = bDetectNumFormat; - aParam.mbSetTextCellFormat = false; + aParam.meSetTextNumFormat = ScSetStringParam::SpecialNumberOnly; aParam.mbHandleApostrophe = false; pDoc->SetString( nCol, nRow, nTab, rStr, &aParam ); } @@ -1519,7 +1519,7 @@ const sal_Unicode* ScImportExport::ScanNextFieldFromString( const sal_Unicode* p const sal_Unicode cBlank = ' '; if (!ScGlobal::UnicodeStrChr( pSeps, cBlank)) { - // Cope with broken generators that put leading blanks before a quoted + // Cope with broken generators that put leading blanks before a quoted // field, like "field1", "field2", "..." // NOTE: this is not in conformance with http://tools.ietf.org/html/rfc4180 const sal_Unicode* pb = p; |