update dev300-m58
[ooovba.git] / applied_patches / 0178-calc-html-csv-import-force-text-cell.diff
blob88d28fdb2c016e36cb496e6d3996802515580382
1 diff --git sc/inc/column.hxx sc/inc/column.hxx
2 index 606602c..a39a958 100644
3 --- sc/inc/column.hxx
4 +++ sc/inc/column.hxx
5 @@ -72,6 +72,7 @@ struct ScFunctionData;
6 struct ScFunctionData;
7 struct ScLineFlags;
8 struct ScMergePatternState;
9 +struct ScSetStringParam;
11 #define COLUMN_DELTA 4
13 @@ -244,8 +245,7 @@ public:
14 // TRUE = Zahlformat gesetzt
15 BOOL SetString( SCROW nRow, SCTAB nTab, const String& rString,
16 formula::FormulaGrammar::AddressConvention conv = formula::FormulaGrammar::CONV_OOO,
17 - SvNumberFormatter* pFormatter = NULL,
18 - bool bDetectNumberFormat = true );
19 + ScSetStringParam* pParam = NULL );
20 void SetValue( SCROW nRow, const double& rVal);
21 void SetError( SCROW nRow, const USHORT nError);
23 diff --git sc/inc/document.hxx sc/inc/document.hxx
24 index 862682c..8d28d82 100644
25 --- sc/inc/document.hxx
26 +++ sc/inc/document.hxx
27 @@ -142,6 +142,7 @@ class ScLookupCache;
28 struct ScLookupCacheMapImpl;
29 struct ScClipParam;
30 struct ScClipRangeNameData;
31 +struct ScSetStringParam;
33 namespace com { namespace sun { namespace star {
34 namespace lang {
35 @@ -736,8 +737,7 @@ public:
36 ULONG nFormatIndex, BOOL bForceTab = FALSE);
37 // return TRUE = Zahlformat gesetzt
38 SC_DLLPUBLIC BOOL SetString(
39 - SCCOL nCol, SCROW nRow, SCTAB nTab, const String& rString,
40 - SvNumberFormatter* pFormatter = NULL, bool bDetectNumberFormat = true );
41 + SCCOL nCol, SCROW nRow, SCTAB nTab, const String& rString, ScSetStringParam* pParam = NULL );
42 SC_DLLPUBLIC void SetValue( SCCOL nCol, SCROW nRow, SCTAB nTab, const double& rVal );
43 void SetError( SCCOL nCol, SCROW nRow, SCTAB nTab, const USHORT nError);
45 diff --git sc/inc/stringutil.hxx sc/inc/stringutil.hxx
46 index 4ca8629..fd2d7c3 100644
47 --- sc/inc/stringutil.hxx
48 +++ sc/inc/stringutil.hxx
49 @@ -32,6 +32,41 @@
50 #define SC_STRINGUTIL_HXX
52 #include "rtl/ustring.hxx"
53 +#include "scdllapi.h"
55 +class SvNumberFormatter;
57 +/**
58 + * Store parameters used in the ScDocument::SetString() method. Various
59 + * options for string-setting operation are specified herein.
60 + */
61 +struct SC_DLLPUBLIC ScSetStringParam
63 + /**
64 + * Stores the pointer to the number formatter instance to be used during
65 + * number format detection. The caller must manage the life cycle of the
66 + * instance.
67 + */
68 + SvNumberFormatter* mpNumFormatter;
70 + /**
71 + * When true, we try to detect special number format (dates etc) from the
72 + * input string, when false, we only try to detect a basic decimal number
73 + * format.
74 + */
75 + bool mbDetectNumberFormat;
77 + /**
78 + * When true, set the format of the cell to Text when a string cell is
79 + * requested for a number input. We may want to do this during text file
80 + * import (csv, html etc).
81 + */
82 + bool mbSetTextCellFormat;
84 + ScSetStringParam();
85 +};
87 +// ============================================================================
89 class ScStringUtil
91 diff --git sc/inc/table.hxx sc/inc/table.hxx
92 index 43163c4..7f8d968 100644
93 --- sc/inc/table.hxx
94 +++ sc/inc/table.hxx
95 @@ -85,7 +85,7 @@ struct ScLineFlags;
96 struct ScFunctionData;
97 struct ScLineFlags;
98 class CollatorWrapper;
100 +struct ScSetStringParam;
102 class ScTable
104 @@ -274,7 +274,7 @@ public:
105 void PutCell(SCCOL nCol, SCROW nRow, ULONG nFormatIndex, ScBaseCell* pCell);
106 // TRUE = Zahlformat gesetzt
107 BOOL SetString( SCCOL nCol, SCROW nRow, SCTAB nTab, const String& rString,
108 - SvNumberFormatter* pFormatter = NULL, bool bDetectNumberFormat = true );
109 + ScSetStringParam* pParam = NULL );
110 void SetValue( SCCOL nCol, SCROW nRow, const double& rVal );
111 void SetError( SCCOL nCol, SCROW nRow, USHORT nError);
113 diff --git sc/source/core/data/column3.cxx sc/source/core/data/column3.cxx
114 index 56e7c1a..a37a53e 100644
115 --- sc/source/core/data/column3.cxx
116 +++ sc/source/core/data/column3.cxx
117 @@ -55,6 +55,7 @@
118 #include "detfunc.hxx" // fuer Notizen bei DeleteRange
119 #include "postit.hxx"
120 #include "stringutil.hxx"
121 +#include "docpool.hxx"
123 #include <com/sun/star/i18n/LocaleDataItem.hpp>
125 @@ -1263,7 +1264,7 @@ void ScColumn::StartListeningInArea( SCROW nRow1, SCROW nRow2 )
126 // TRUE = Zahlformat gesetzt
127 BOOL ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString,
128 formula::FormulaGrammar::AddressConvention eConv,
129 - SvNumberFormatter* pFormatter, bool bDetectNumberFormat )
130 + ScSetStringParam* pParam )
132 BOOL bNumFmtSet = FALSE;
133 if (VALIDROW(nRow))
134 @@ -1272,11 +1273,15 @@ BOOL ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString,
135 BOOL bIsLoading = FALSE;
136 if (rString.Len() > 0)
138 + ScSetStringParam aParam;
139 + if (pParam)
140 + aParam = *pParam;
142 double nVal;
143 sal_uInt32 nIndex, nOldIndex = 0;
144 sal_Unicode cFirstChar;
145 - if (!pFormatter)
146 - pFormatter = pDocument->GetFormatTable();
147 + if (!aParam.mpNumFormatter)
148 + aParam.mpNumFormatter = pDocument->GetFormatTable();
149 SfxObjectShell* pDocSh = pDocument->GetDocumentShell();
150 if ( pDocSh )
151 bIsLoading = pDocSh->IsLoading();
152 @@ -1285,7 +1290,7 @@ BOOL ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString,
154 nIndex = nOldIndex = GetNumberFormat( nRow );
155 if ( rString.Len() > 1
156 - && pFormatter->GetType(nIndex) != NUMBERFORMAT_TEXT )
157 + && aParam.mpNumFormatter->GetType(nIndex) != NUMBERFORMAT_TEXT )
158 cFirstChar = rString.GetChar(0);
159 else
160 cFirstChar = 0; // Text
161 @@ -1341,7 +1346,7 @@ BOOL ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString,
163 // nIndex fuer IsNumberFormat vorbelegen
164 if ( !bIsText )
165 - nIndex = nOldIndex = pFormatter->GetStandardIndex();
166 + nIndex = nOldIndex = aParam.mpNumFormatter->GetStandardIndex();
170 @@ -1349,9 +1354,9 @@ BOOL ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString,
171 if (bIsText)
172 break;
174 - if (bDetectNumberFormat)
175 + if (aParam.mbDetectNumberFormat)
177 - if (!pFormatter->IsNumberFormat(rString, nIndex, nVal))
178 + if (!aParam.mpNumFormatter->IsNumberFormat(rString, nIndex, nVal))
179 break;
181 pNewCell = new ScValueCell( nVal );
182 @@ -1362,21 +1367,21 @@ BOOL ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString,
183 // Exception: If the new format is boolean, always apply it.
185 BOOL bOverwrite = FALSE;
186 - const SvNumberformat* pOldFormat = pFormatter->GetEntry( nOldIndex );
187 + const SvNumberformat* pOldFormat = aParam.mpNumFormatter->GetEntry( nOldIndex );
188 if ( pOldFormat )
190 short nOldType = pOldFormat->GetType() & ~NUMBERFORMAT_DEFINED;
191 if ( nOldType == NUMBERFORMAT_NUMBER || nOldType == NUMBERFORMAT_DATE ||
192 nOldType == NUMBERFORMAT_TIME || nOldType == NUMBERFORMAT_LOGICAL )
194 - if ( nOldIndex == pFormatter->GetStandardFormat(
195 + if ( nOldIndex == aParam.mpNumFormatter->GetStandardFormat(
196 nOldType, pOldFormat->GetLanguage() ) )
198 bOverwrite = TRUE; // default of these types can be overwritten
202 - if ( !bOverwrite && pFormatter->GetType( nIndex ) == NUMBERFORMAT_LOGICAL )
203 + if ( !bOverwrite && aParam.mpNumFormatter->GetType( nIndex ) == NUMBERFORMAT_LOGICAL )
205 bOverwrite = TRUE; // overwrite anything if boolean was detected
207 @@ -1392,7 +1397,7 @@ BOOL ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString,
208 else
210 // Only check if the string is a regular number.
211 - const LocaleDataWrapper* pLocale = pFormatter->GetLocaleData();
212 + const LocaleDataWrapper* pLocale = aParam.mpNumFormatter->GetLocaleData();
213 if (!pLocale)
214 break;
216 @@ -1414,7 +1419,19 @@ BOOL ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString,
217 while (false);
219 if (!pNewCell)
221 + if (aParam.mbSetTextCellFormat && aParam.mpNumFormatter->IsNumberFormat(rString, nIndex, nVal))
223 + // Set the cell format type to Text.
224 + sal_uInt32 nFormat = aParam.mpNumFormatter->GetStandardFormat(NUMBERFORMAT_TEXT);
225 + ScPatternAttr aNewAttrs(pDocument->GetPool());
226 + SfxItemSet& rSet = aNewAttrs.GetItemSet();
227 + rSet.Put( SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat) );
228 + ApplyPattern(nRow, aNewAttrs);
231 pNewCell = new ScStringCell(rString);
236 diff --git sc/source/core/data/document.cxx sc/source/core/data/document.cxx
237 index 3c50c24..56f2158 100644
238 --- sc/source/core/data/document.cxx
239 +++ sc/source/core/data/document.cxx
240 @@ -2512,10 +2512,10 @@ void ScDocument::PutCell( const ScAddress& rPos, ScBaseCell* pCell, BOOL bForceT
243 BOOL ScDocument::SetString( SCCOL nCol, SCROW nRow, SCTAB nTab, const String& rString,
244 - SvNumberFormatter* pFormatter, bool bDetectNumberFormat )
245 + ScSetStringParam* pParam )
247 if ( ValidTab(nTab) && pTab[nTab] )
248 - return pTab[nTab]->SetString( nCol, nRow, nTab, rString, pFormatter, bDetectNumberFormat );
249 + return pTab[nTab]->SetString( nCol, nRow, nTab, rString, pParam );
250 else
251 return FALSE;
253 diff --git sc/source/core/data/table2.cxx sc/source/core/data/table2.cxx
254 index 9505877..6a373e9 100644
255 --- sc/source/core/data/table2.cxx
256 +++ sc/source/core/data/table2.cxx
257 @@ -904,11 +904,11 @@ void ScTable::PutCell( const ScAddress& rPos, ULONG nFormatIndex, ScBaseCell* pC
260 BOOL ScTable::SetString( SCCOL nCol, SCROW nRow, SCTAB nTabP, const String& rString,
261 - SvNumberFormatter* pFormatter, bool bDetectNumberFormat )
262 + ScSetStringParam* pParam )
264 if (ValidColRow(nCol,nRow))
265 return aCol[nCol].SetString(
266 - nRow, nTabP, rString, pDocument->GetAddressConvention(), pFormatter, bDetectNumberFormat );
267 + nRow, nTabP, rString, pDocument->GetAddressConvention(), pParam );
268 else
269 return FALSE;
271 diff --git sc/source/core/tool/stringutil.cxx sc/source/core/tool/stringutil.cxx
272 index ae6247f..d5e09a6 100644
273 --- sc/source/core/tool/stringutil.cxx
274 +++ sc/source/core/tool/stringutil.cxx
275 @@ -40,6 +40,15 @@
276 using ::rtl::OUString;
277 using ::rtl::OUStringBuffer;
279 +ScSetStringParam::ScSetStringParam() :
280 + mpNumFormatter(NULL),
281 + mbDetectNumberFormat(true),
282 + mbSetTextCellFormat(false)
286 +// ============================================================================-
288 bool ScStringUtil::parseSimpleNumber(
289 const OUString& rStr, sal_Unicode dsep, sal_Unicode gsep, double& rVal)
291 diff --git sc/source/filter/rtf/eeimpars.cxx sc/source/filter/rtf/eeimpars.cxx
292 index e78e371..b25ad37 100644
293 --- sc/source/filter/rtf/eeimpars.cxx
294 +++ sc/source/filter/rtf/eeimpars.cxx
295 @@ -69,6 +69,7 @@
296 #include "drwlayer.hxx"
297 #include "rangenam.hxx"
298 #include "progress.hxx"
299 +#include "stringutil.hxx"
301 #include "globstr.hrc"
303 @@ -331,12 +332,17 @@ void ScEEImport::WriteToDocument( BOOL bSizeColsRows, double nOutputFactor, SvNu
304 // Daten eintragen
305 if (bSimple)
307 + ScSetStringParam aParam;
308 + aParam.mpNumFormatter = pFormatter;
309 + aParam.mbDetectNumberFormat = true;
310 + aParam.mbSetTextCellFormat = true;
312 if ( aValStr.Len() )
313 mpDoc->SetValue( nCol, nRow, nTab, fVal );
314 else if ( !pE->aSel.HasRange() )
316 // maybe ALT text of IMG or similar
317 - mpDoc->SetString( nCol, nRow, nTab, pE->aAltText, pFormatter );
318 + mpDoc->SetString( nCol, nRow, nTab, pE->aAltText, &aParam );
319 // wenn SelRange komplett leer kann nachfolgender Text im gleichen Absatz liegen!
321 else
322 @@ -381,7 +387,10 @@ void ScEEImport::WriteToDocument( BOOL bSizeColsRows, double nOutputFactor, SvNu
323 if (bNumbersEnglishUS && !bEnUsRecognized)
324 mpDoc->PutCell( nCol, nRow, nTab, new ScStringCell( aStr));
325 else
326 - mpDoc->SetString( nCol, nRow, nTab, aStr, pFormatter, bConvertDate );
328 + aParam.mbDetectNumberFormat = bConvertDate;
329 + mpDoc->SetString( nCol, nRow, nTab, aStr, &aParam );
333 else
334 diff --git sc/source/ui/docshell/impex.cxx sc/source/ui/docshell/impex.cxx
335 index d388887..573443d 100644
336 --- sc/source/ui/docshell/impex.cxx
337 +++ sc/source/ui/docshell/impex.cxx
338 @@ -85,6 +85,9 @@ class StarBASIC;
340 // ause
341 #include "editutil.hxx"
342 +#include "patattr.hxx"
343 +#include "docpool.hxx"
344 +#include "stringutil.hxx"
346 #include "globstr.hrc"
347 #include <vcl/msgbox.hxx>
348 @@ -804,6 +807,18 @@ static bool lcl_PutString(
350 if ( nColFormat == SC_COL_TEXT )
352 + double fDummy;
353 + sal_uInt32 nIndex;
354 + if (pFormatter->IsNumberFormat(rStr, nIndex, fDummy))
356 + // Set the format of this cell to Text.
357 + sal_uInt32 nFormat = pFormatter->GetStandardFormat(NUMBERFORMAT_TEXT);
358 + ScPatternAttr aNewAttrs(pDoc->GetPool());
359 + SfxItemSet& rSet = aNewAttrs.GetItemSet();
360 + rSet.Put( SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat) );
361 + pDoc->ApplyPattern(nCol, nRow, nTab, aNewAttrs);
364 pDoc->PutCell( nCol, nRow, nTab, ScBaseCell::CreateTextCell( rStr, pDoc ) );
365 return bMultiLine;
367 @@ -1016,7 +1031,13 @@ static bool lcl_PutString(
369 // Standard or date not determined -> SetString / EditCell
370 if( rStr.Search( _LF ) == STRING_NOTFOUND )
371 - pDoc->SetString( nCol, nRow, nTab, rStr, pFormatter, bDetectNumFormat );
373 + ScSetStringParam aParam;
374 + aParam.mpNumFormatter = pFormatter;
375 + aParam.mbDetectNumberFormat = bDetectNumFormat;
376 + aParam.mbSetTextCellFormat = true;
377 + pDoc->SetString( nCol, nRow, nTab, rStr, &aParam );
379 else
381 bMultiLine = true;