summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvo Hinkelmann <ihi@openoffice.org>2011-02-16 14:51:50 +0100
committerIvo Hinkelmann <ihi@openoffice.org>2011-02-16 14:51:50 +0100
commit7df435ceb05aa42e240a992de5d1720a96a46862 (patch)
treeabe8f32e305967910540581d6339ce5d040296a7
parent0eb12dbec57938d9c418ead57c403983af033650 (diff)
parentdf33be33ef8135647bf965ee457928cec5d85fe8 (diff)
CWS-TOOLING: integrate CWS csvexport
-rw-r--r--sc/source/ui/dbgui/asciiopt.cxx6
-rw-r--r--sc/source/ui/dbgui/imoptdlg.cxx35
-rw-r--r--sc/source/ui/dbgui/imoptdlg.hrc1
-rw-r--r--sc/source/ui/dbgui/imoptdlg.src12
-rw-r--r--sc/source/ui/dbgui/scuiasciiopt.cxx2
-rw-r--r--sc/source/ui/dbgui/scuiimoptdlg.cxx10
-rw-r--r--sc/source/ui/docshell/docsh.cxx41
-rw-r--r--sc/source/ui/inc/imoptdlg.hxx18
-rw-r--r--sc/source/ui/inc/scuiimoptdlg.hxx3
-rw-r--r--sc/source/ui/src/globstr.src2
10 files changed, 104 insertions, 26 deletions
diff --git a/sc/source/ui/dbgui/asciiopt.cxx b/sc/source/ui/dbgui/asciiopt.cxx
index 3b7ef5b22..bb05bb8f1 100644
--- a/sc/source/ui/dbgui/asciiopt.cxx
+++ b/sc/source/ui/dbgui/asciiopt.cxx
@@ -312,6 +312,10 @@ void ScAsciiOptions::ReadFromString( const String& rString )
aToken = rString.GetToken(7, ',');
bDetectSpecialNumber = aToken.EqualsAscii("true") ? true : false;
}
+ else
+ bDetectSpecialNumber = sal_True; // default of versions that didn't add the parameter
+
+ // 9th token is used for "Save as shown" in export options
}
@@ -399,6 +403,8 @@ String ScAsciiOptions::WriteToString() const
// Detect special nubmers.
aOutStr += String::CreateFromAscii(bDetectSpecialNumber ? "true" : "false");
+ // 9th token is used for "Save as shown" in export options
+
return aOutStr;
}
diff --git a/sc/source/ui/dbgui/imoptdlg.cxx b/sc/source/ui/dbgui/imoptdlg.cxx
index 23ece03b2..2a8bcde7d 100644
--- a/sc/source/ui/dbgui/imoptdlg.cxx
+++ b/sc/source/ui/dbgui/imoptdlg.cxx
@@ -44,10 +44,20 @@ static const sal_Char pStrFix[] = "FIX";
ScImportOptions::ScImportOptions( const String& rStr )
{
+ // Use the same string format as ScAsciiOptions,
+ // because the import options string is passed here when a CSV file is loaded and saved again.
+ // The old format is still supported because it might be used in macros.
+
bFixedWidth = sal_False;
nFieldSepCode = 0;
- if ( rStr.GetTokenCount(',') >= 3 )
+ nTextSepCode = 0;
+ eCharSet = RTL_TEXTENCODING_DONTKNOW;
+ bSaveAsShown = sal_True; // "true" if not in string (after CSV import)
+ bQuoteAllText = sal_False;
+ xub_StrLen nTokenCount = rStr.GetTokenCount(',');
+ if ( nTokenCount >= 3 )
{
+ // first 3 tokens: common
String aToken( rStr.GetToken( 0, ',' ) );
if( aToken.EqualsIgnoreCaseAscii( pStrFix ) )
bFixedWidth = sal_True;
@@ -56,7 +66,21 @@ ScImportOptions::ScImportOptions( const String& rStr )
nTextSepCode = (sal_Unicode) rStr.GetToken(1,',').ToInt32();
aStrFont = rStr.GetToken(2,',');
eCharSet = ScGlobal::GetCharsetValue(aStrFont);
- bSaveAsShown = (rStr.GetToken( 3, ',' ).ToInt32() ? sal_True : sal_False);
+
+ if ( nTokenCount == 4 )
+ {
+ // compatibility with old options string: "Save as shown" as 4th token, numeric
+ bSaveAsShown = (rStr.GetToken( 3, ',' ).ToInt32() ? sal_True : sal_False);
+ bQuoteAllText = sal_True; // use old default then
+ }
+ else
+ {
+ // look at the same positions as in ScAsciiOptions
+ if ( nTokenCount >= 7 )
+ bQuoteAllText = rStr.GetToken(6, ',').EqualsAscii("true");
+ if ( nTokenCount >= 9 )
+ bSaveAsShown = rStr.GetToken(8, ',').EqualsAscii("true");
+ }
}
}
@@ -74,8 +98,11 @@ String ScImportOptions::BuildString() const
aResult += String::CreateFromInt32(nTextSepCode);
aResult += ',';
aResult += aStrFont;
- aResult += ',';
- aResult += String::CreateFromInt32( bSaveAsShown ? 1 : 0 );
+ // use the same string format as ScAsciiOptions:
+ aResult.AppendAscii( ",1,,0," ); // first row, no column info, default language
+ aResult.AppendAscii(bQuoteAllText ? "true" : "false"); // same as "quoted field as text" in ScAsciiOptions
+ aResult.AppendAscii( ",true," ); // "detect special numbers"
+ aResult.AppendAscii(bSaveAsShown ? "true" : "false"); // "save as shown": not in ScAsciiOptions
return aResult;
}
diff --git a/sc/source/ui/dbgui/imoptdlg.hrc b/sc/source/ui/dbgui/imoptdlg.hrc
index b6f1bf555..6d67abb70 100644
--- a/sc/source/ui/dbgui/imoptdlg.hrc
+++ b/sc/source/ui/dbgui/imoptdlg.hrc
@@ -41,4 +41,5 @@
#define FL_FIELDOPT 11
#define CB_FIXEDWIDTH 12
#define CB_SAVESHOWN 13
+#define CB_QUOTEALL 14
diff --git a/sc/source/ui/dbgui/imoptdlg.src b/sc/source/ui/dbgui/imoptdlg.src
index 7c5af149f..06b3af2e8 100644
--- a/sc/source/ui/dbgui/imoptdlg.src
+++ b/sc/source/ui/dbgui/imoptdlg.src
@@ -96,7 +96,7 @@ ModalDialog RID_SCDLG_IMPORTOPT
CheckBox CB_FIXEDWIDTH
{
HelpID = "sc:CheckBox:RID_SCDLG_IMPORTOPT:CB_FIXEDWIDTH";
- Pos = MAP_APPFONT( 12, 80 );
+ Pos = MAP_APPFONT( 12, 92 );
Size = MAP_APPFONT( 172, 10 );
Hide = TRUE;
Text [ en-US ] = "Fixed column ~width";
@@ -104,12 +104,20 @@ ModalDialog RID_SCDLG_IMPORTOPT
CheckBox CB_SAVESHOWN
{
HelpID = "sc:CheckBox:RID_SCDLG_IMPORTOPT:CB_SAVESHOWN";
- Pos = MAP_APPFONT( 12, 66 );
+ Pos = MAP_APPFONT( 12, 78 );
Size = MAP_APPFONT( 172, 10 );
TabStop = TRUE;
Hide = TRUE;
Text [ en-US ] = "Save cell content as ~shown";
};
+ CheckBox CB_QUOTEALL
+ {
+ HelpID = "sc:CheckBox:RID_SCDLG_IMPORTOPT:CB_QUOTEALL";
+ Pos = MAP_APPFONT( 20, 64 );
+ Size = MAP_APPFONT( 164, 10 );
+ Hide = TRUE;
+ Text [ en-US ] = "~Quote all text cells";
+ };
OKButton BTN_OK
{
Pos = MAP_APPFONT ( 202 , 6 ) ;
diff --git a/sc/source/ui/dbgui/scuiasciiopt.cxx b/sc/source/ui/dbgui/scuiasciiopt.cxx
index dcd7fb40c..95b384f9a 100644
--- a/sc/source/ui/dbgui/scuiasciiopt.cxx
+++ b/sc/source/ui/dbgui/scuiasciiopt.cxx
@@ -273,7 +273,7 @@ ScImportAsciiDlg::ScImportAsciiDlg( Window* pParent,String aDatName,
OUString sTextSeparators;
bool bMergeDelimiters = false;
bool bFixedWidth = false;
- bool bQuotedFieldAsText = true;
+ bool bQuotedFieldAsText = false;
bool bDetectSpecialNum = false;
sal_Int32 nFromRow = 1;
sal_Int32 nCharSet = -1;
diff --git a/sc/source/ui/dbgui/scuiimoptdlg.cxx b/sc/source/ui/dbgui/scuiimoptdlg.cxx
index 59df08a66..db73afc00 100644
--- a/sc/source/ui/dbgui/scuiimoptdlg.cxx
+++ b/sc/source/ui/dbgui/scuiimoptdlg.cxx
@@ -132,11 +132,12 @@ ScImportOptionsDlg::ScImportOptionsDlg(
aEdFieldSep ( this, ScResId( ED_FIELDSEP ) ),
aFtTextSep ( this, ScResId( FT_TEXTSEP ) ),
aEdTextSep ( this, ScResId( ED_TEXTSEP ) ),
+ aCbQuoteAll ( this, ScResId( CB_QUOTEALL ) ),
+ aCbShown ( this, ScResId( CB_SAVESHOWN ) ),
aCbFixed ( this, ScResId( CB_FIXEDWIDTH ) ),
aBtnOk ( this, ScResId( BTN_OK ) ),
aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
- aBtnHelp ( this, ScResId( BTN_HELP ) ),
- aCbShown ( this, ScResId( CB_SAVESHOWN ) )
+ aBtnHelp ( this, ScResId( BTN_HELP ) )
{
// im Ctor-Initializer nicht moeglich (MSC kann das nicht):
pFieldSepTab = new ScDelimiterTable( String(ScResId(SCSTR_FIELDSEP)) );
@@ -214,6 +215,8 @@ ScImportOptionsDlg::ScImportOptionsDlg(
aCbFixed.Check( sal_False );
aCbShown.Show();
aCbShown.Check( sal_True );
+ aCbQuoteAll.Show();
+ aCbQuoteAll.Check( sal_False );
}
else
{
@@ -225,6 +228,7 @@ ScImportOptionsDlg::ScImportOptionsDlg(
aEdTextSep.Hide();
aCbFixed.Hide();
aCbShown.Hide();
+ aCbQuoteAll.Hide();
aLbFont.GrabFocus();
aLbFont.SetDoubleClickHdl( LINK( this, ScImportOptionsDlg, DoubleClickHdl ) );
}
@@ -259,6 +263,7 @@ void ScImportOptionsDlg::GetImportOptions( ScImportOptions& rOptions ) const
rOptions.nTextSepCode = GetCodeFromCombo( aEdTextSep );
rOptions.bFixedWidth = aCbFixed.IsChecked();
rOptions.bSaveAsShown = aCbShown.IsChecked();
+ rOptions.bQuoteAllText = aCbQuoteAll.IsChecked();
}
}
@@ -302,6 +307,7 @@ IMPL_LINK( ScImportOptionsDlg, FixedWidthHdl, CheckBox*, pCheckBox )
aFtTextSep.Enable( bEnable );
aEdTextSep.Enable( bEnable );
aCbShown.Enable( bEnable );
+ aCbQuoteAll.Enable( bEnable );
}
return 0;
}
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 62b067249..e2b871488 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -1650,6 +1650,8 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
sal_uInt16 nOldNumberFormatInt = rStream.GetNumberFormatInt();
ByteString aStrDelimEncoded; // only used if not Unicode
UniString aStrDelimDecoded; // only used if context encoding
+ ByteString aDelimEncoded;
+ UniString aDelimDecoded;
sal_Bool bContextOrNotAsciiEncoding;
if ( eCharSet == RTL_TEXTENCODING_UNICODE )
{
@@ -1659,6 +1661,7 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
else
{
aStrDelimEncoded = ByteString( cStrDelim, eCharSet );
+ aDelimEncoded = ByteString( cDelim, eCharSet );
rtl_TextEncodingInfo aInfo;
aInfo.StructSize = sizeof(aInfo);
if ( rtl_getTextEncodingInfo( eCharSet, &aInfo ) )
@@ -1667,7 +1670,10 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
(((aInfo.Flags & RTL_TEXTENCODING_INFO_CONTEXT) != 0) ||
((aInfo.Flags & RTL_TEXTENCODING_INFO_ASCII) == 0));
if ( bContextOrNotAsciiEncoding )
+ {
aStrDelimDecoded = String( aStrDelimEncoded, eCharSet );
+ aDelimDecoded = String( aDelimEncoded, eCharSet );
+ }
}
else
bContextOrNotAsciiEncoding = sal_False;
@@ -1895,14 +1901,21 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
if ( eCharSet == RTL_TEXTENCODING_UNICODE )
{
xub_StrLen nPos = aString.Search( cStrDelim );
+ // #i116636# quotes are needed if text delimiter (quote), field delimiter, or LF is in the cell text
+ bool bNeedQuotes = rAsciiOpt.bQuoteAllText ||
+ ( nPos != STRING_NOTFOUND ) ||
+ ( aString.Search( cDelim ) != STRING_NOTFOUND ) ||
+ ( aString.Search( sal_Unicode(_LF) ) != STRING_NOTFOUND );
while ( nPos != STRING_NOTFOUND )
{
aString.Insert( cStrDelim, nPos );
nPos = aString.Search( cStrDelim, nPos+2 );
}
- rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
+ if ( bNeedQuotes )
+ rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
rStream.WriteUnicodeText( aString );
- rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
+ if ( bNeedQuotes )
+ rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
}
else
{
@@ -1928,6 +1941,10 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
UniString aStrDec( aStrEnc, eCharSet );
// search on re-decoded string
xub_StrLen nPos = aStrDec.Search( aStrDelimDecoded );
+ bool bNeedQuotes = rAsciiOpt.bQuoteAllText ||
+ ( nPos != STRING_NOTFOUND ) ||
+ ( aStrDec.Search( aDelimDecoded ) != STRING_NOTFOUND ) ||
+ ( aStrDec.Search( sal_Unicode(_LF) ) != STRING_NOTFOUND );
while ( nPos != STRING_NOTFOUND )
{
aStrDec.Insert( aStrDelimDecoded, nPos );
@@ -1935,15 +1952,21 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
nPos+1+aStrDelimDecoded.Len() );
}
// write byte re-encoded
- rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
+ if ( bNeedQuotes )
+ rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
rStream.WriteUnicodeOrByteText( aStrDec, eCharSet );
- rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
+ if ( bNeedQuotes )
+ rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
}
else
{
ByteString aStrEnc( aString, eCharSet );
// search on encoded string
xub_StrLen nPos = aStrEnc.Search( aStrDelimEncoded );
+ bool bNeedQuotes = rAsciiOpt.bQuoteAllText ||
+ ( nPos != STRING_NOTFOUND ) ||
+ ( aStrEnc.Search( aDelimEncoded ) != STRING_NOTFOUND ) ||
+ ( aStrEnc.Search( sal_Char(_LF) ) != STRING_NOTFOUND );
while ( nPos != STRING_NOTFOUND )
{
aStrEnc.Insert( aStrDelimEncoded, nPos );
@@ -1951,11 +1974,13 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
nPos+1+aStrDelimEncoded.Len() );
}
// write byte encoded
- rStream.Write( aStrDelimEncoded.GetBuffer(),
- aStrDelimEncoded.Len() );
+ if ( bNeedQuotes )
+ rStream.Write( aStrDelimEncoded.GetBuffer(),
+ aStrDelimEncoded.Len() );
rStream.Write( aStrEnc.GetBuffer(), aStrEnc.Len() );
- rStream.Write( aStrDelimEncoded.GetBuffer(),
- aStrDelimEncoded.Len() );
+ if ( bNeedQuotes )
+ rStream.Write( aStrDelimEncoded.GetBuffer(),
+ aStrDelimEncoded.Len() );
}
}
}
diff --git a/sc/source/ui/inc/imoptdlg.hxx b/sc/source/ui/inc/imoptdlg.hxx
index b212f497c..16b3feefc 100644
--- a/sc/source/ui/inc/imoptdlg.hxx
+++ b/sc/source/ui/inc/imoptdlg.hxx
@@ -45,18 +45,18 @@ public:
ScImportOptions()
: nFieldSepCode(0), nTextSepCode(0),
eCharSet(RTL_TEXTENCODING_DONTKNOW), bFixedWidth(sal_False),
- bSaveAsShown(sal_False)
+ bSaveAsShown(sal_False), bQuoteAllText(sal_False)
{}
ScImportOptions( const String& rStr );
ScImportOptions( sal_Unicode nFieldSep, sal_Unicode nTextSep, const String& rStr )
: nFieldSepCode(nFieldSep), nTextSepCode(nTextSep), aStrFont(rStr),
- bFixedWidth(sal_False), bSaveAsShown(sal_False)
+ bFixedWidth(sal_False), bSaveAsShown(sal_False), bQuoteAllText(sal_False)
{ eCharSet = ScGlobal::GetCharsetValue(aStrFont); }
ScImportOptions( sal_Unicode nFieldSep, sal_Unicode nTextSep, rtl_TextEncoding nEnc )
: nFieldSepCode(nFieldSep), nTextSepCode(nTextSep),
- bFixedWidth(sal_False), bSaveAsShown(sal_False)
+ bFixedWidth(sal_False), bSaveAsShown(sal_False), bQuoteAllText(sal_False)
{ SetTextEncoding( nEnc ); }
ScImportOptions( const ScImportOptions& rCpy )
@@ -65,7 +65,8 @@ public:
aStrFont (rCpy.aStrFont),
eCharSet (rCpy.eCharSet),
bFixedWidth (rCpy.bFixedWidth),
- bSaveAsShown (rCpy.bSaveAsShown)
+ bSaveAsShown (rCpy.bSaveAsShown),
+ bQuoteAllText (rCpy.bQuoteAllText)
{}
ScImportOptions& operator=( const ScImportOptions& rCpy )
@@ -76,6 +77,7 @@ public:
eCharSet = rCpy.eCharSet;
bFixedWidth = rCpy.bFixedWidth;
bSaveAsShown = rCpy.bSaveAsShown;
+ bQuoteAllText = rCpy.bQuoteAllText;
return *this;
}
@@ -87,7 +89,8 @@ public:
&& eCharSet == rCmp.eCharSet
&& aStrFont == rCmp.aStrFont
&& bFixedWidth == rCmp.bFixedWidth
- && bSaveAsShown == rCmp.bSaveAsShown;
+ && bSaveAsShown == rCmp.bSaveAsShown
+ && bQuoteAllText == rCmp.bQuoteAllText;
}
String BuildString() const;
@@ -97,8 +100,9 @@ public:
sal_Unicode nTextSepCode;
String aStrFont;
CharSet eCharSet;
- sal_Bool bFixedWidth;
- sal_Bool bSaveAsShown;
+ sal_Bool bFixedWidth;
+ sal_Bool bSaveAsShown;
+ sal_Bool bQuoteAllText;
};
diff --git a/sc/source/ui/inc/scuiimoptdlg.hxx b/sc/source/ui/inc/scuiimoptdlg.hxx
index fe304da78..4dee78c09 100644
--- a/sc/source/ui/inc/scuiimoptdlg.hxx
+++ b/sc/source/ui/inc/scuiimoptdlg.hxx
@@ -58,11 +58,12 @@ private:
ComboBox aEdFieldSep;
FixedText aFtTextSep;
ComboBox aEdTextSep;
+ CheckBox aCbQuoteAll;
+ CheckBox aCbShown;
CheckBox aCbFixed;
OKButton aBtnOk;
CancelButton aBtnCancel;
HelpButton aBtnHelp;
- CheckBox aCbShown;
ScDelimiterTable* pFieldSepTab;
ScDelimiterTable* pTextSepTab;
diff --git a/sc/source/ui/src/globstr.src b/sc/source/ui/src/globstr.src
index 585aa288f..0229288ef 100644
--- a/sc/source/ui/src/globstr.src
+++ b/sc/source/ui/src/globstr.src
@@ -1037,7 +1037,7 @@ Resource RID_GLOBSTR
};
String STR_EXPORT_ASCII
{
- Text [ en-US ] = "Export of text files" ;
+ Text [ en-US ] = "Export Text File" ;
};
String STR_IMPORT_LOTUS
{