summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2012-08-13 14:20:13 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2012-08-13 14:22:32 -0400
commit51f1fc69aa539dec8035195b98e0b128026388e9 (patch)
tree849dff14f3b2b3f5b259a233c06b4d74ca9335f8
parentf97a3a7f51a7de9c2170953ee3969ef48d914e25 (diff)
fdo#53089: Avoid setting valid numbers as text during html import.
Change-Id: I5fa9a54f70e8e4d8aac42687f2a204b2925d4619
-rw-r--r--sc/inc/stringutil.hxx26
-rw-r--r--sc/qa/unit/ucalc.cxx2
-rw-r--r--sc/source/core/data/column3.cxx4
-rw-r--r--sc/source/core/data/dpoutput.cxx6
-rw-r--r--sc/source/core/tool/stringutil.cxx2
-rw-r--r--sc/source/filter/rtf/eeimpars.cxx2
-rw-r--r--sc/source/ui/docshell/impex.cxx4
7 files changed, 32 insertions, 14 deletions
diff --git a/sc/inc/stringutil.hxx b/sc/inc/stringutil.hxx
index a178bebf7ca7..75c378cd2152 100644
--- a/sc/inc/stringutil.hxx
+++ b/sc/inc/stringutil.hxx
@@ -41,6 +41,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
@@ -56,11 +75,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 e8b959b1f36e..8a401e2a9719 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -370,7 +370,7 @@ void Test::testInput()
// Customized string handling policy.
ScSetStringParam aParam;
aParam.mbDetectNumberFormat = false;
- aParam.mbSetTextCellFormat = true;
+ aParam.meSetTextNumFormat = ScSetStringParam::Always;
aParam.mbHandleApostrophe = false;
m_pDoc->SetString(0, 0, 0, "000123", &aParam);
m_pDoc->GetString(0, 0, 0, test);
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 61edb03de984..1d2e21c285b4 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -1339,7 +1339,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();
@@ -1365,7 +1365,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 b57d639be7e9..a3c3a999ce82 100644
--- a/sc/source/core/data/dpoutput.cxx
+++ b/sc/source/core/data/dpoutput.cxx
@@ -790,13 +790,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);
@@ -834,7 +834,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 6465c8e282d5..60ba286034a1 100644
--- a/sc/source/core/tool/stringutil.cxx
+++ b/sc/source/core/tool/stringutil.cxx
@@ -36,7 +36,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 de102d99cb36..ba7fa11edbe7 100644
--- a/sc/source/filter/rtf/eeimpars.cxx
+++ b/sc/source/filter/rtf/eeimpars.cxx
@@ -331,7 +331,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 3e1026cbadd2..09da442ac90e 100644
--- a/sc/source/ui/docshell/impex.cxx
+++ b/sc/source/ui/docshell/impex.cxx
@@ -1202,7 +1202,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 );
}
@@ -1494,7 +1494,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;