Kaydet (Commit) 86501f57 authored tarafından Takeshi Abe's avatar Takeshi Abe Kaydeden (comit) Eike Rathke

tdf#106678 Implement CSV filter option's 8th token

... which decides whether number cells are stored as numbers
or quoted like strings, as documented in
<https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Filter_Options#Token_8.2C_csv_export>
but long unimplemented.

Note that in this implementation the false value of the above token
is superseded and ignored if either "Fixed column width" (1st token)
or "Save cell content as shown" (9th token) option is on.

Change-Id: Ib4ff02a2be81a8590e1fc249725f02cd83e91118
Reviewed-on: https://gerrit.libreoffice.org/65604
Tested-by: Jenkins
Reviewed-by: 's avatarEike Rathke <erack@redhat.com>
üst 2cf3b170
......@@ -41,6 +41,7 @@ ScImportOptions::ScImportOptions( const OUString& rStr )
eCharSet = RTL_TEXTENCODING_DONTKNOW;
bSaveAsShown = true; // "true" if not in string (after CSV import)
bQuoteAllText = false;
bSaveNumberAsSuch = true;
bSaveFormulas = false;
bRemoveSpace = false;
sal_Int32 nTokenCount = comphelper::string::getTokenCount(rStr, ',');
......@@ -67,6 +68,8 @@ ScImportOptions::ScImportOptions( const OUString& rStr )
// look at the same positions as in ScAsciiOptions
if ( nTokenCount >= 7 )
bQuoteAllText = rStr.getToken(6, ',') == "true";
if ( nTokenCount >= 8 )
bSaveNumberAsSuch = rStr.getToken(7, ',') == "true";
if ( nTokenCount >= 9 )
bSaveAsShown = rStr.getToken(8, ',') == "true";
if ( nTokenCount >= 10 )
......@@ -89,7 +92,9 @@ OUString ScImportOptions::BuildString() const
// use the same string format as ScAsciiOptions:
",1,,0," + // first row, no column info, default language
OUString::boolean( bQuoteAllText ) + // same as "quoted field as text" in ScAsciiOptions
",true," + // "detect special numbers"
"," +
OUString::boolean( bSaveNumberAsSuch ) + // "save number as such": not in ScAsciiOptions
"," +
OUString::boolean( bSaveAsShown ) + // "save as shown": not in ScAsciiOptions
"," +
OUString::boolean( bSaveFormulas ) + // "save formulas": not in ScAsciiOptions
......
......@@ -1942,6 +1942,7 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
sal_Unicode cStrDelim = rAsciiOpt.nTextSepCode;
rtl_TextEncoding eCharSet = rAsciiOpt.eCharSet;
bool bFixedWidth = rAsciiOpt.bFixedWidth;
bool bSaveNumberAsSuch = rAsciiOpt.bSaveNumberAsSuch;
bool bSaveAsShown = rAsciiOpt.bSaveAsShown;
bool bShowFormulas = rAsciiOpt.bSaveFormulas;
......@@ -2072,6 +2073,7 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
pProtAttr->GetHideFormula() ) )
eType = CELLTYPE_NONE; // hide
}
bool bForceQuotes = false;
bool bString;
switch ( eType )
{
......@@ -2104,7 +2106,7 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
else
{
ScCellFormat::GetInputString(*pCell, nFormat, aString, rFormatter, &m_aDocument);
bString = false;
bString = bForceQuotes = !bSaveNumberAsSuch;
}
}
else
......@@ -2154,7 +2156,7 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
else
{
ScCellFormat::GetInputString(*pCell, nFormat, aString, rFormatter, &m_aDocument);
bString = false;
bString = bForceQuotes = !bSaveNumberAsSuch;
}
}
break;
......@@ -2197,10 +2199,10 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
escapeTextSep<OUString, OUStringBuffer>(
nPos, OUString(cStrDelim), aUniString);
if ( bNeedQuotes )
if ( bNeedQuotes || bForceQuotes )
rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
write_uInt16s_FromOUString(rStream, aUniString);
if ( bNeedQuotes )
if ( bNeedQuotes || bForceQuotes )
rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
}
else
......@@ -2235,10 +2237,10 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
nPos, aStrDelimDecoded, aStrDec);
// write byte re-encoded
if ( bNeedQuotes )
if ( bNeedQuotes || bForceQuotes )
rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
rStream.WriteUnicodeOrByteText( aStrDec, eCharSet );
if ( bNeedQuotes )
if ( bNeedQuotes || bForceQuotes )
rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
}
else
......@@ -2254,11 +2256,11 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
nPos, aStrDelimEncoded, aStrEnc);
// write byte encoded
if ( bNeedQuotes )
if ( bNeedQuotes || bForceQuotes )
rStream.WriteBytes(
aStrDelimEncoded.getStr(), aStrDelimEncoded.getLength());
rStream.WriteBytes(aStrEnc.getStr(), aStrEnc.getLength());
if ( bNeedQuotes )
if ( bNeedQuotes || bForceQuotes )
rStream.WriteBytes(
aStrDelimEncoded.getStr(), aStrDelimEncoded.getLength());
}
......
......@@ -31,23 +31,11 @@ public:
ScImportOptions( sal_Unicode nFieldSep, sal_Unicode nTextSep, rtl_TextEncoding nEnc )
: nFieldSepCode(nFieldSep), nTextSepCode(nTextSep),
bFixedWidth(false), bSaveAsShown(false), bQuoteAllText(false), bSaveFormulas(false),
bRemoveSpace(false)
bFixedWidth(false), bSaveAsShown(false), bQuoteAllText(false),
bSaveNumberAsSuch(true), bSaveFormulas(false), bRemoveSpace(false)
{ SetTextEncoding( nEnc ); }
ScImportOptions& operator=( const ScImportOptions& rCpy )
{
nFieldSepCode = rCpy.nFieldSepCode;
nTextSepCode = rCpy.nTextSepCode;
aStrFont = rCpy.aStrFont;
eCharSet = rCpy.eCharSet;
bFixedWidth = rCpy.bFixedWidth;
bSaveAsShown = rCpy.bSaveAsShown;
bQuoteAllText = rCpy.bQuoteAllText;
bSaveFormulas = rCpy.bSaveFormulas;
bRemoveSpace = rCpy.bRemoveSpace;
return *this;
}
ScImportOptions& operator=( const ScImportOptions& rCpy ) = default;
OUString BuildString() const;
......@@ -60,6 +48,7 @@ public:
bool bFixedWidth;
bool bSaveAsShown;
bool bQuoteAllText;
bool bSaveNumberAsSuch;
bool bSaveFormulas;
bool bRemoveSpace;
};
......
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