Kaydet (Commit) 5a560e43 authored tarafından Eike Rathke's avatar Eike Rathke

resolved fdo#48731 in CSV import do not strip leading apostrophe

üst 385017e0
...@@ -61,6 +61,16 @@ struct SC_DLLPUBLIC ScSetStringParam ...@@ -61,6 +61,16 @@ struct SC_DLLPUBLIC ScSetStringParam
*/ */
bool mbSetTextCellFormat; bool mbSetTextCellFormat;
/**
* When true, treat input with a leading apostrophe / single quote special
* in that it escapes numeric or date/time input such that it is not
* interpreted and the input string is taken instead. This can be used
* during text file import so the leading apostrophe is not lost if it
* precedes a numeric value.
* Usually set mbHandleApostrophe = !mbSetTextCellFormat
*/
bool mbHandleApostrophe;
ScSetStringParam(); ScSetStringParam();
}; };
......
...@@ -1234,14 +1234,19 @@ bool ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString, ...@@ -1234,14 +1234,19 @@ bool ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString,
} }
else if ( cFirstChar == '\'') // 'Text else if ( cFirstChar == '\'') // 'Text
{ {
// Cell format is not 'Text', and the first char bool bNumeric = false;
// is an apostrophe. Check if the input is considered a number. if (aParam.mbHandleApostrophe)
String aTest = rString.Copy(1); {
double fTest; // Cell format is not 'Text', and the first char
if (aParam.mpNumFormatter->IsNumberFormat(aTest, nIndex, fTest)) // is an apostrophe. Check if the input is considered a number.
// This is a number. Strip out the first char. String aTest = rString.Copy(1);
pNewCell = new ScStringCell(aTest); double fTest;
else bNumeric = aParam.mpNumFormatter->IsNumberFormat(aTest, nIndex, fTest);
if (bNumeric)
// This is a number. Strip out the first char.
pNewCell = new ScStringCell(aTest);
}
if (!bNumeric)
// This is a normal text. Take it as-is. // This is a normal text. Take it as-is.
pNewCell = new ScStringCell(rString); pNewCell = new ScStringCell(rString);
} }
......
...@@ -794,11 +794,13 @@ void ScDPOutput::HeaderCell( SCCOL nCol, SCROW nRow, SCTAB nTab, ...@@ -794,11 +794,13 @@ void ScDPOutput::HeaderCell( SCCOL nCol, SCROW nRow, SCTAB nTab,
{ {
aParam.mbDetectNumberFormat = true; aParam.mbDetectNumberFormat = true;
aParam.mbSetTextCellFormat = false; aParam.mbSetTextCellFormat = false;
aParam.mbHandleApostrophe = true;
} }
else else
{ {
aParam.mbDetectNumberFormat = false; aParam.mbDetectNumberFormat = false;
aParam.mbSetTextCellFormat = true; aParam.mbSetTextCellFormat = true;
aParam.mbHandleApostrophe = false;
} }
pDoc->SetString(nCol, nRow, nTab, rData.Caption, &aParam); pDoc->SetString(nCol, nRow, nTab, rData.Caption, &aParam);
} }
...@@ -836,6 +838,7 @@ void ScDPOutput::FieldCell( ...@@ -836,6 +838,7 @@ void ScDPOutput::FieldCell(
ScSetStringParam aParam; ScSetStringParam aParam;
aParam.mbDetectNumberFormat = false; aParam.mbDetectNumberFormat = false;
aParam.mbSetTextCellFormat = true; aParam.mbSetTextCellFormat = true;
aParam.mbHandleApostrophe = false;
pDoc->SetString(nCol, nRow, nTab, rData.maCaption, &aParam); pDoc->SetString(nCol, nRow, nTab, rData.maCaption, &aParam);
if (bInTable) if (bInTable)
......
...@@ -39,7 +39,8 @@ using ::rtl::OUStringBuffer; ...@@ -39,7 +39,8 @@ using ::rtl::OUStringBuffer;
ScSetStringParam::ScSetStringParam() : ScSetStringParam::ScSetStringParam() :
mpNumFormatter(NULL), mpNumFormatter(NULL),
mbDetectNumberFormat(true), mbDetectNumberFormat(true),
mbSetTextCellFormat(false) mbSetTextCellFormat(false),
mbHandleApostrophe(true)
{ {
} }
......
...@@ -337,6 +337,7 @@ void ScEEImport::WriteToDocument( bool bSizeColsRows, double nOutputFactor, SvNu ...@@ -337,6 +337,7 @@ void ScEEImport::WriteToDocument( bool bSizeColsRows, double nOutputFactor, SvNu
aParam.mpNumFormatter = pFormatter; aParam.mpNumFormatter = pFormatter;
aParam.mbDetectNumberFormat = true; aParam.mbDetectNumberFormat = true;
aParam.mbSetTextCellFormat = true; aParam.mbSetTextCellFormat = true;
aParam.mbHandleApostrophe = false;
if (!aValStr.isEmpty()) if (!aValStr.isEmpty())
mpDoc->SetValue( nCol, nRow, nTab, fVal ); mpDoc->SetValue( nCol, nRow, nTab, fVal );
......
...@@ -1228,6 +1228,7 @@ static bool lcl_PutString( ...@@ -1228,6 +1228,7 @@ static bool lcl_PutString(
aParam.mpNumFormatter = pFormatter; aParam.mpNumFormatter = pFormatter;
aParam.mbDetectNumberFormat = bDetectNumFormat; aParam.mbDetectNumberFormat = bDetectNumFormat;
aParam.mbSetTextCellFormat = true; aParam.mbSetTextCellFormat = true;
aParam.mbHandleApostrophe = false;
pDoc->SetString( nCol, nRow, nTab, rStr, &aParam ); pDoc->SetString( nCol, nRow, nTab, rStr, &aParam );
} }
else else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment