diff options
-rw-r--r-- | sc/inc/column.hxx | 4 | ||||
-rw-r--r-- | sc/inc/document.hxx | 3 | ||||
-rw-r--r-- | sc/inc/stringutil.hxx | 35 | ||||
-rw-r--r-- | sc/inc/table.hxx | 4 | ||||
-rw-r--r-- | sc/source/core/data/column3.cxx | 55 | ||||
-rw-r--r-- | sc/source/core/data/document.cxx | 4 | ||||
-rw-r--r-- | sc/source/core/data/table2.cxx | 4 | ||||
-rw-r--r-- | sc/source/core/tool/stringutil.cxx | 9 | ||||
-rw-r--r-- | sc/source/filter/rtf/eeimpars.cxx | 13 | ||||
-rw-r--r-- | sc/source/ui/docshell/impex.cxx | 23 |
10 files changed, 118 insertions, 36 deletions
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index 2fa63eb91d74..668d64bb4289 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -66,6 +66,7 @@ struct ScFunctionData; struct ScLineFlags; struct ScMergePatternState; class ScFlatBoolRowSegments; +struct ScSetStringParam; #define COLUMN_DELTA 4 @@ -236,8 +237,7 @@ public: // TRUE = Zahlformat gesetzt BOOL SetString( SCROW nRow, SCTAB nTab, const String& rString, formula::FormulaGrammar::AddressConvention conv = formula::FormulaGrammar::CONV_OOO, - SvNumberFormatter* pFormatter = NULL, - bool bDetectNumberFormat = true ); + ScSetStringParam* pParam = NULL ); void SetValue( SCROW nRow, const double& rVal); void SetError( SCROW nRow, const USHORT nError); diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index b643023d3840..42928b56160a 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -146,6 +146,7 @@ class ScFormulaParserPool; struct ScClipParam; struct ScClipRangeNameData; class ScRowBreakIterator; +struct ScSetStringParam; namespace com { namespace sun { namespace star { namespace lang { @@ -773,7 +774,7 @@ public: // return TRUE = Zahlformat gesetzt SC_DLLPUBLIC BOOL SetString( SCCOL nCol, SCROW nRow, SCTAB nTab, const String& rString, - SvNumberFormatter* pFormatter = NULL, bool bDetectNumberFormat = true ); + ScSetStringParam* pParam = NULL ); SC_DLLPUBLIC void SetValue( SCCOL nCol, SCROW nRow, SCTAB nTab, const double& rVal ); void SetError( SCCOL nCol, SCROW nRow, SCTAB nTab, const USHORT nError); diff --git a/sc/inc/stringutil.hxx b/sc/inc/stringutil.hxx index c50c0d8cf156..c6433ebb1d04 100644 --- a/sc/inc/stringutil.hxx +++ b/sc/inc/stringutil.hxx @@ -32,6 +32,41 @@ #define SC_STRINGUTIL_HXX #include "rtl/ustring.hxx" +#include "scdllapi.h" + +class SvNumberFormatter; + +/** + * Store parameters used in the ScDocument::SetString() method. Various + * options for string-setting operation are specified herein. + */ +struct SC_DLLPUBLIC ScSetStringParam +{ + /** + * Stores the pointer to the number formatter instance to be used during + * number format detection. The caller must manage the life cycle of the + * instance. + */ + SvNumberFormatter* mpNumFormatter; + + /** + * When true, we try to detect special number format (dates etc) from the + * input string, when false, we only try to detect a basic decimal number + * format. + */ + 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). + */ + bool mbSetTextCellFormat; + + ScSetStringParam(); +}; + +// ============================================================================ class ScStringUtil { diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 7f3b0097abbb..0ddce1f139f4 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -85,7 +85,7 @@ class CollatorWrapper; class ScFlatUInt16RowSegments; class ScFlatBoolRowSegments; class ScFlatBoolColSegments; - +struct ScSetStringParam; class ScTable { @@ -301,7 +301,7 @@ public: void PutCell(SCCOL nCol, SCROW nRow, ULONG nFormatIndex, ScBaseCell* pCell); // TRUE = Zahlformat gesetzt BOOL SetString( SCCOL nCol, SCROW nRow, SCTAB nTab, const String& rString, - SvNumberFormatter* pFormatter = NULL, bool bDetectNumberFormat = true ); + ScSetStringParam* pParam = NULL ); void SetValue( SCCOL nCol, SCROW nRow, const double& rVal ); void SetError( SCCOL nCol, SCROW nRow, USHORT nError); diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx index 29d1da889484..bf437cf62ccd 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -52,6 +52,7 @@ #include "detfunc.hxx" // fuer Notizen bei DeleteRange #include "postit.hxx" #include "stringutil.hxx" +#include "docpool.hxx" #include <com/sun/star/i18n/LocaleDataItem.hpp> @@ -1249,7 +1250,7 @@ void ScColumn::StartListeningInArea( SCROW nRow1, SCROW nRow2 ) // TRUE = Zahlformat gesetzt BOOL ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString, formula::FormulaGrammar::AddressConvention eConv, - SvNumberFormatter* pLangFormatter, bool bDetectNumberFormat ) + ScSetStringParam* pParam ) { BOOL bNumFmtSet = FALSE; if (VALIDROW(nRow)) @@ -1258,14 +1259,15 @@ BOOL ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString, BOOL bIsLoading = FALSE; if (rString.Len() > 0) { + ScSetStringParam aParam; + if (pParam) + aParam = *pParam; + double nVal; sal_uInt32 nIndex, nOldIndex = 0; sal_Unicode cFirstChar; - // #i110979# If a different NumberFormatter is passed in (pLangFormatter), - // its formats aren't valid in the document. - // Only use the language / LocaleDataWrapper from pLangFormatter, - // always the document's number formatter for IsNumberFormat. - SvNumberFormatter* pFormatter = pDocument->GetFormatTable(); + if (!aParam.mpNumFormatter) + aParam.mpNumFormatter = pDocument->GetFormatTable(); SfxObjectShell* pDocSh = pDocument->GetDocumentShell(); if ( pDocSh ) bIsLoading = pDocSh->IsLoading(); @@ -1274,7 +1276,7 @@ BOOL ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString, { nIndex = nOldIndex = GetNumberFormat( nRow ); if ( rString.Len() > 1 - && pFormatter->GetType(nIndex) != NUMBERFORMAT_TEXT ) + && aParam.mpNumFormatter->GetType(nIndex) != NUMBERFORMAT_TEXT ) cFirstChar = rString.GetChar(0); else cFirstChar = 0; // Text @@ -1330,7 +1332,7 @@ BOOL ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString, } // nIndex fuer IsNumberFormat vorbelegen if ( !bIsText ) - nIndex = nOldIndex = pFormatter->GetStandardIndex(); + nIndex = nOldIndex = aParam.mpNumFormatter->GetStandardIndex(); } do @@ -1338,23 +1340,17 @@ BOOL ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString, if (bIsText) break; - if (bDetectNumberFormat) + if (aParam.mbDetectNumberFormat) { - if ( pLangFormatter ) - { - // for number detection: valid format index for selected language - nIndex = pFormatter->GetStandardIndex( pLangFormatter->GetLanguage() ); - } - - if (!pFormatter->IsNumberFormat(rString, nIndex, nVal)) + if (!aParam.mpNumFormatter->IsNumberFormat(rString, nIndex, nVal)) break; - if ( pLangFormatter ) + if ( aParam.mpNumFormatter ) { // convert back to the original language if a built-in format was detected - const SvNumberformat* pOldFormat = pFormatter->GetEntry( nOldIndex ); + const SvNumberformat* pOldFormat = aParam.mpNumFormatter->GetEntry( nOldIndex ); if ( pOldFormat ) - nIndex = pFormatter->GetFormatForLanguageIfBuiltIn( nIndex, pOldFormat->GetLanguage() ); + nIndex = aParam.mpNumFormatter->GetFormatForLanguageIfBuiltIn( nIndex, pOldFormat->GetLanguage() ); } pNewCell = new ScValueCell( nVal ); @@ -1365,21 +1361,21 @@ BOOL ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString, // Exception: If the new format is boolean, always apply it. BOOL bOverwrite = FALSE; - const SvNumberformat* pOldFormat = pFormatter->GetEntry( nOldIndex ); + const SvNumberformat* pOldFormat = aParam.mpNumFormatter->GetEntry( nOldIndex ); if ( pOldFormat ) { short nOldType = pOldFormat->GetType() & ~NUMBERFORMAT_DEFINED; if ( nOldType == NUMBERFORMAT_NUMBER || nOldType == NUMBERFORMAT_DATE || nOldType == NUMBERFORMAT_TIME || nOldType == NUMBERFORMAT_LOGICAL ) { - if ( nOldIndex == pFormatter->GetStandardFormat( + if ( nOldIndex == aParam.mpNumFormatter->GetStandardFormat( nOldType, pOldFormat->GetLanguage() ) ) { bOverwrite = TRUE; // default of these types can be overwritten } } } - if ( !bOverwrite && pFormatter->GetType( nIndex ) == NUMBERFORMAT_LOGICAL ) + if ( !bOverwrite && aParam.mpNumFormatter->GetType( nIndex ) == NUMBERFORMAT_LOGICAL ) { bOverwrite = TRUE; // overwrite anything if boolean was detected } @@ -1395,8 +1391,7 @@ BOOL ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString, else { // Only check if the string is a regular number. - SvNumberFormatter* pLocaleSource = pLangFormatter ? pLangFormatter : pFormatter; - const LocaleDataWrapper* pLocale = pLocaleSource->GetLocaleData(); + const LocaleDataWrapper* pLocale = aParam.mpNumFormatter->GetLocaleData(); if (!pLocale) break; @@ -1418,7 +1413,19 @@ BOOL ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString, while (false); if (!pNewCell) + { + if (aParam.mbSetTextCellFormat && aParam.mpNumFormatter->IsNumberFormat(rString, nIndex, nVal)) + { + // Set the cell format type to Text. + sal_uInt32 nFormat = aParam.mpNumFormatter->GetStandardFormat(NUMBERFORMAT_TEXT); + ScPatternAttr aNewAttrs(pDocument->GetPool()); + SfxItemSet& rSet = aNewAttrs.GetItemSet(); + rSet.Put( SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat) ); + ApplyPattern(nRow, aNewAttrs); + } + pNewCell = new ScStringCell(rString); + } } } diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index f4e45f738356..f9e033ef164c 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -2658,10 +2658,10 @@ void ScDocument::PutCell( const ScAddress& rPos, ScBaseCell* pCell, BOOL bForceT BOOL ScDocument::SetString( SCCOL nCol, SCROW nRow, SCTAB nTab, const String& rString, - SvNumberFormatter* pFormatter, bool bDetectNumberFormat ) + ScSetStringParam* pParam ) { if ( ValidTab(nTab) && pTab[nTab] ) - return pTab[nTab]->SetString( nCol, nRow, nTab, rString, pFormatter, bDetectNumberFormat ); + return pTab[nTab]->SetString( nCol, nRow, nTab, rString, pParam ); else return FALSE; } diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index eee6e6e72bb8..db3298ba374a 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -1015,11 +1015,11 @@ void ScTable::PutCell( const ScAddress& rPos, ScBaseCell* pCell ) BOOL ScTable::SetString( SCCOL nCol, SCROW nRow, SCTAB nTabP, const String& rString, - SvNumberFormatter* pFormatter, bool bDetectNumberFormat ) + ScSetStringParam* pParam ) { if (ValidColRow(nCol,nRow)) return aCol[nCol].SetString( - nRow, nTabP, rString, pDocument->GetAddressConvention(), pFormatter, bDetectNumberFormat ); + nRow, nTabP, rString, pDocument->GetAddressConvention(), pParam ); else return FALSE; } diff --git a/sc/source/core/tool/stringutil.cxx b/sc/source/core/tool/stringutil.cxx index 28a4bc6755c2..f8be97e22449 100644 --- a/sc/source/core/tool/stringutil.cxx +++ b/sc/source/core/tool/stringutil.cxx @@ -40,6 +40,15 @@ using ::rtl::OUString; using ::rtl::OUStringBuffer; +ScSetStringParam::ScSetStringParam() : + mpNumFormatter(NULL), + mbDetectNumberFormat(true), + mbSetTextCellFormat(false) +{ +} + +// ============================================================================- + bool ScStringUtil::parseSimpleNumber( const OUString& rStr, sal_Unicode dsep, sal_Unicode gsep, double& rVal) { diff --git a/sc/source/filter/rtf/eeimpars.cxx b/sc/source/filter/rtf/eeimpars.cxx index 7fb3d16c6c8d..05fdc294fc37 100644 --- a/sc/source/filter/rtf/eeimpars.cxx +++ b/sc/source/filter/rtf/eeimpars.cxx @@ -66,6 +66,7 @@ #include "drwlayer.hxx" #include "rangenam.hxx" #include "progress.hxx" +#include "stringutil.hxx" #include "globstr.hrc" @@ -329,12 +330,17 @@ void ScEEImport::WriteToDocument( BOOL bSizeColsRows, double nOutputFactor, SvNu // Daten eintragen if (bSimple) { + ScSetStringParam aParam; + aParam.mpNumFormatter = pFormatter; + aParam.mbDetectNumberFormat = true; + aParam.mbSetTextCellFormat = true; + if ( aValStr.Len() ) mpDoc->SetValue( nCol, nRow, nTab, fVal ); else if ( !pE->aSel.HasRange() ) { // maybe ALT text of IMG or similar - mpDoc->SetString( nCol, nRow, nTab, pE->aAltText, pFormatter ); + mpDoc->SetString( nCol, nRow, nTab, pE->aAltText, &aParam ); // wenn SelRange komplett leer kann nachfolgender Text im gleichen Absatz liegen! } else @@ -379,7 +385,10 @@ void ScEEImport::WriteToDocument( BOOL bSizeColsRows, double nOutputFactor, SvNu if (bNumbersEnglishUS && !bEnUsRecognized) mpDoc->PutCell( nCol, nRow, nTab, new ScStringCell( aStr)); else - mpDoc->SetString( nCol, nRow, nTab, aStr, pFormatter, bConvertDate ); + { + aParam.mbDetectNumberFormat = bConvertDate; + mpDoc->SetString( nCol, nRow, nTab, aStr, &aParam ); + } } } else diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx index a17279f409a9..981cfa7afc5e 100644 --- a/sc/source/ui/docshell/impex.cxx +++ b/sc/source/ui/docshell/impex.cxx @@ -82,6 +82,9 @@ class StarBASIC; // ause #include "editutil.hxx" +#include "patattr.hxx" +#include "docpool.hxx" +#include "stringutil.hxx" #include "globstr.hrc" #include <vcl/msgbox.hxx> @@ -914,6 +917,18 @@ static bool lcl_PutString( if ( nColFormat == SC_COL_TEXT ) { + double fDummy; + sal_uInt32 nIndex; + if (pFormatter->IsNumberFormat(rStr, nIndex, fDummy)) + { + // Set the format of this cell to Text. + sal_uInt32 nFormat = pFormatter->GetStandardFormat(NUMBERFORMAT_TEXT); + ScPatternAttr aNewAttrs(pDoc->GetPool()); + SfxItemSet& rSet = aNewAttrs.GetItemSet(); + rSet.Put( SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat) ); + pDoc->ApplyPattern(nCol, nRow, nTab, aNewAttrs); + + } pDoc->PutCell( nCol, nRow, nTab, ScBaseCell::CreateTextCell( rStr, pDoc ) ); return bMultiLine; } @@ -1126,7 +1141,13 @@ static bool lcl_PutString( // Standard or date not determined -> SetString / EditCell if( rStr.Search( _LF ) == STRING_NOTFOUND ) - pDoc->SetString( nCol, nRow, nTab, rStr, pFormatter, bDetectNumFormat ); + { + ScSetStringParam aParam; + aParam.mpNumFormatter = pFormatter; + aParam.mbDetectNumberFormat = bDetectNumFormat; + aParam.mbSetTextCellFormat = true; + pDoc->SetString( nCol, nRow, nTab, rStr, &aParam ); + } else { bMultiLine = true; |