[Libreoffice-commits] .: 2 commits - sc/inc sc/qa sc/source
Kohei Yoshida
kohei at kemper.freedesktop.org
Mon Aug 13 11:22:48 PDT 2012
sc/inc/stringutil.hxx | 26 +++++++++++++++++++----
sc/qa/unit/data/html/numberformat.html | 8 +++++++
sc/qa/unit/subsequent_filters-test.cxx | 37 +++++++++++++++++++++++++++++++--
sc/qa/unit/ucalc.cxx | 2 -
sc/source/core/data/column3.cxx | 4 +--
sc/source/core/data/dpoutput.cxx | 6 ++---
sc/source/core/tool/stringutil.cxx | 2 -
sc/source/filter/rtf/eeimpars.cxx | 2 -
sc/source/ui/docshell/impex.cxx | 4 +--
9 files changed, 75 insertions(+), 16 deletions(-)
New commits:
commit 51f1fc69aa539dec8035195b98e0b128026388e9
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Mon Aug 13 14:20:13 2012 -0400
fdo#53089: Avoid setting valid numbers as text during html import.
Change-Id: I5fa9a54f70e8e4d8aac42687f2a204b2925d4619
diff --git a/sc/inc/stringutil.hxx b/sc/inc/stringutil.hxx
index a178beb..75c378c 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 e8b959b..8a401e2 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 61edb03..1d2e21c 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 b57d639..a3c3a99 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 6465c8e..60ba286 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 de102d9..ba7fa11 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 3e1026c..09da442 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;
commit f97a3a7f51a7de9c2170953ee3969ef48d914e25
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Mon Aug 13 13:02:41 2012 -0400
New HTML file to test number format on import.
Change-Id: I74e831e5ede01dfe2954314be6b64b19a551dc6b
diff --git a/sc/qa/unit/data/html/numberformat.html b/sc/qa/unit/data/html/numberformat.html
new file mode 100644
index 0000000..f5fdc02
--- /dev/null
+++ b/sc/qa/unit/data/html/numberformat.html
@@ -0,0 +1,8 @@
+<html lang="en">
+<body>
+<table>
+ <tr><td>Product</td><td>Price</td><td>Note</td></tr>
+ <tr><td>Google Nexus 7 (8GB)</td><td>199.98</td><td>This should be imported as a number, not text.</td></tr>
+</table>
+</body>
+</html>
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index 5667348..4f7a23b 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -60,12 +60,14 @@
#define ODS_FORMAT_TYPE 50331943
#define XLS_FORMAT_TYPE 318767171
#define XLSX_FORMAT_TYPE 268959811
-#define CSV_FORMAT_TYPE 195
+#define CSV_FORMAT_TYPE (SFX_FILTER_IMPORT | SFX_FILTER_EXPORT | SFX_FILTER_ALIEN | SFX_FILTER_USESOPTIONS)
+#define HTML_FORMAT_TYPE (SFX_FILTER_IMPORT | SFX_FILTER_EXPORT | SFX_FILTER_ALIEN | SFX_FILTER_USESOPTIONS)
#define ODS 0
#define XLS 1
#define XLSX 2
#define CSV 3
+#define HTML 4
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
@@ -80,7 +82,8 @@ FileFormat aFileFormats[] = {
{ "ods" , "calc8", "", ODS_FORMAT_TYPE },
{ "xls" , "MS Excel 97", "calc_MS_EXCEL_97", XLS_FORMAT_TYPE },
{ "xlsx", "Calc MS Excel 2007 XML" , "MS Excel 2007 XML", XLSX_FORMAT_TYPE },
- { "csv" , "Text - txt - csv (StarCalc)", "generic_Text", CSV_FORMAT_TYPE }
+ { "csv" , "Text - txt - csv (StarCalc)", "generic_Text", CSV_FORMAT_TYPE },
+ { "html" , "calc_HTML_WebQuery", "generic_HTML", HTML_FORMAT_TYPE }
};
}
@@ -145,6 +148,8 @@ public:
//test shape import
void testControlImport();
+ void testNumberFormatHTML();
+
CPPUNIT_TEST_SUITE(ScFiltersTest);
CPPUNIT_TEST(testRangeNameXLS);
CPPUNIT_TEST(testRangeNameXLSX);
@@ -178,6 +183,8 @@ public:
CPPUNIT_TEST(testDataBar);
CPPUNIT_TEST(testCondFormat);
+ CPPUNIT_TEST(testNumberFormatHTML);
+
//disable testPassword on MacOSX due to problems with libsqlite3
//also crashes on DragonFly due to problems with nss/nspr headers
#if !defined(MACOSX) && !defined(DRAGONFLY) && !defined(WNT)
@@ -1180,6 +1187,32 @@ void ScFiltersTest::testControlImport()
xDocSh->DoClose();
}
+void ScFiltersTest::testNumberFormatHTML()
+{
+ OUString aFileNameBase("numberformat.");
+ OUString aFileExt = OUString::createFromAscii(aFileFormats[HTML].pName);
+ OUString aFilterName = OUString::createFromAscii(aFileFormats[HTML].pFilterName);
+ OUString aFilterType = OUString::createFromAscii(aFileFormats[HTML].pTypeName);
+
+ rtl::OUString aFileName;
+ createFileURL(aFileNameBase, aFileExt, aFileName);
+ ScDocShellRef xDocSh = load (aFilterName, aFileName, rtl::OUString(), aFilterType, aFileFormats[HTML].nFormatType);
+ CPPUNIT_ASSERT_MESSAGE("Failed to load numberformat.html", xDocSh.Is());
+
+ ScDocument* pDoc = xDocSh->GetDocument();
+
+ // Check the header just in case.
+ CPPUNIT_ASSERT_MESSAGE("Cell value is not as expected", pDoc->GetString(0, 0, 0) == "Product");
+ CPPUNIT_ASSERT_MESSAGE("Cell value is not as expected", pDoc->GetString(1, 0, 0) == "Price");
+ CPPUNIT_ASSERT_MESSAGE("Cell value is not as expected", pDoc->GetString(2, 0, 0) == "Note");
+
+ // B2 should be imported as a value cell.
+ bool bHasValue = pDoc->HasValueData(1, 1, 0);
+ CPPUNIT_ASSERT_MESSAGE("Fail to import number as a value cell.", bHasValue);
+
+ xDocSh->DoClose();
+}
+
void ScFiltersTest::testColorScale()
{
const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("colorScale."));
More information about the Libreoffice-commits
mailing list