Lines 44-49
Link Here
|
44 |
// ause |
44 |
// ause |
45 |
#include "editutil.hxx" |
45 |
#include "editutil.hxx" |
46 |
|
46 |
|
|
|
47 |
#include <optutil.hxx> |
48 |
#include <com/sun/star/uno/Any.hxx> |
49 |
#include <com/sun/star/uno/Sequence.hxx> |
50 |
#include "miscuno.hxx" |
51 |
|
52 |
|
47 |
//! TODO make dynamic |
53 |
//! TODO make dynamic |
48 |
#ifdef WIN |
54 |
#ifdef WIN |
49 |
const SCSIZE ASCIIDLG_MAXROWS = 10000; |
55 |
const SCSIZE ASCIIDLG_MAXROWS = 10000; |
Lines 51-56
const SCSIZE ASCIIDLG_MAXROWS = 10000;
Link Here
|
51 |
const SCSIZE ASCIIDLG_MAXROWS = MAXROWCOUNT; |
57 |
const SCSIZE ASCIIDLG_MAXROWS = MAXROWCOUNT; |
52 |
#endif |
58 |
#endif |
53 |
|
59 |
|
|
|
60 |
|
61 |
using namespace rtl; |
62 |
using namespace com::sun::star::uno; |
63 |
|
64 |
// Defines - CSV Import Preserve Options |
65 |
#define FIXED_WIDTH "FixedWidth" |
66 |
#define FROM_ROW "FromRow" |
67 |
#define CHAR_SET "CharSet" |
68 |
#define SEPARATORS "Separators" |
69 |
#define TEXT_SEPARATORS "TextSeparators" |
70 |
#define MERGE_DELIMITERS "MergeDelimiters" |
71 |
#define QUOTED_AS_TEXT "QuotedFieldAsText" |
72 |
#define SEP_PATH "Office.Calc/Dialogs/CSVImport" |
73 |
|
54 |
// ============================================================================ |
74 |
// ============================================================================ |
55 |
|
75 |
|
56 |
void lcl_FillCombo( ComboBox& rCombo, const String& rList, sal_Unicode cSelect ) |
76 |
void lcl_FillCombo( ComboBox& rCombo, const String& rList, sal_Unicode cSelect ) |
Lines 98-108
sal_Unicode lcl_CharFromCombo( ComboBox& rCombo, const String& rList )
Link Here
|
98 |
return c; |
118 |
return c; |
99 |
} |
119 |
} |
100 |
|
120 |
|
|
|
121 |
static void load_Separators( OUString &sFieldSeparators, OUString &sTextSeparators, |
122 |
bool &bMergeDelimiters, bool& bQuotedAsText, bool &bFixedWidth, |
123 |
sal_Int32 &nFromRow, sal_Int32 &nCharSet ) |
124 |
{ |
125 |
Sequence<Any>aValues; |
126 |
const Any *pProperties; |
127 |
Sequence<OUString> aNames(7); |
128 |
OUString* pNames = aNames.getArray(); |
129 |
ScLinkConfigItem aItem( OUString::createFromAscii( SEP_PATH ) ); |
130 |
|
131 |
pNames[0] = OUString::createFromAscii( MERGE_DELIMITERS ); |
132 |
pNames[1] = OUString::createFromAscii( SEPARATORS ); |
133 |
pNames[2] = OUString::createFromAscii( TEXT_SEPARATORS ); |
134 |
pNames[3] = OUString::createFromAscii( FIXED_WIDTH ); |
135 |
pNames[4] = OUString::createFromAscii( FROM_ROW ); |
136 |
pNames[5] = OUString::createFromAscii( CHAR_SET ); |
137 |
pNames[6] = OUString::createFromAscii( QUOTED_AS_TEXT ); |
138 |
aValues = aItem.GetProperties( aNames ); |
139 |
pProperties = aValues.getConstArray(); |
140 |
if( pProperties[1].hasValue() ) |
141 |
pProperties[1] >>= sFieldSeparators; |
142 |
|
143 |
if( pProperties[2].hasValue() ) |
144 |
pProperties[2] >>= sTextSeparators; |
145 |
|
146 |
if( pProperties[0].hasValue() ) |
147 |
bMergeDelimiters = ScUnoHelpFunctions::GetBoolFromAny( pProperties[0] ); |
148 |
|
149 |
if( pProperties[3].hasValue() ) |
150 |
bFixedWidth = ScUnoHelpFunctions::GetBoolFromAny( pProperties[3] ); |
151 |
|
152 |
if( pProperties[4].hasValue() ) |
153 |
pProperties[4] >>= nFromRow; |
154 |
|
155 |
if( pProperties[5].hasValue() ) |
156 |
pProperties[5] >>= nCharSet; |
157 |
|
158 |
if ( pProperties[6].hasValue() ) |
159 |
pProperties[6] >>= bQuotedAsText; |
160 |
} |
161 |
|
162 |
static void save_Separators( String maSeparators, String maTxtSep, bool bMergeDelimiters, bool bQuotedAsText, |
163 |
bool bFixedWidth, sal_Int32 nFromRow, sal_Int32 nCharSet ) |
164 |
{ |
165 |
OUString sFieldSeparators = OUString( maSeparators ); |
166 |
OUString sTextSeparators = OUString( maTxtSep ); |
167 |
Sequence<Any> aValues; |
168 |
Any *pProperties; |
169 |
Sequence<OUString> aNames(7); |
170 |
OUString* pNames = aNames.getArray(); |
171 |
ScLinkConfigItem aItem( OUString::createFromAscii( SEP_PATH ) ); |
172 |
|
173 |
pNames[0] = OUString::createFromAscii( MERGE_DELIMITERS ); |
174 |
pNames[1] = OUString::createFromAscii( SEPARATORS ); |
175 |
pNames[2] = OUString::createFromAscii( TEXT_SEPARATORS ); |
176 |
pNames[3] = OUString::createFromAscii( FIXED_WIDTH ); |
177 |
pNames[4] = OUString::createFromAscii( FROM_ROW ); |
178 |
pNames[5] = OUString::createFromAscii( CHAR_SET ); |
179 |
pNames[6] = OUString::createFromAscii( QUOTED_AS_TEXT ); |
180 |
aValues = aItem.GetProperties( aNames ); |
181 |
pProperties = aValues.getArray(); |
182 |
pProperties[1] <<= sFieldSeparators; |
183 |
pProperties[2] <<= sTextSeparators; |
184 |
ScUnoHelpFunctions::SetBoolInAny( pProperties[0], bMergeDelimiters ); |
185 |
ScUnoHelpFunctions::SetBoolInAny( pProperties[3], bFixedWidth ); |
186 |
pProperties[4] <<= nFromRow; |
187 |
pProperties[5] <<= nCharSet; |
188 |
pProperties[6] <<= static_cast<sal_Bool>(bQuotedAsText); |
189 |
|
190 |
aItem.PutProperties(aNames, aValues); |
191 |
} |
101 |
|
192 |
|
102 |
// ---------------------------------------------------------------------------- |
193 |
// ---------------------------------------------------------------------------- |
103 |
|
194 |
|
104 |
ScImportAsciiDlg::ScImportAsciiDlg( Window* pParent,String aDatName, |
195 |
ScImportAsciiDlg::ScImportAsciiDlg( Window* pParent,String aDatName, |
105 |
SvStream* pInStream, sal_Unicode cSep ) : |
196 |
SvStream* pInStream, sal_Unicode /*cSep*/ ) : |
106 |
ModalDialog ( pParent, ScResId( RID_SCDLG_ASCII ) ), |
197 |
ModalDialog ( pParent, ScResId( RID_SCDLG_ASCII ) ), |
107 |
mpDatStream ( pInStream ), |
198 |
mpDatStream ( pInStream ), |
108 |
mnStreamPos( pInStream ? pInStream->Tell() : 0 ), |
199 |
mnStreamPos( pInStream ? pInStream->Tell() : 0 ), |
Lines 128-133
ScImportAsciiDlg::ScImportAsciiDlg( Window* pParent,String aDatName,
Link Here
|
128 |
aCkbOther ( this, ScResId( CKB_OTHER ) ), |
215 |
aCkbOther ( this, ScResId( CKB_OTHER ) ), |
129 |
aEdOther ( this, ScResId( ED_OTHER ) ), |
216 |
aEdOther ( this, ScResId( ED_OTHER ) ), |
130 |
aCkbAsOnce ( this, ScResId( CB_ASONCE) ), |
217 |
aCkbAsOnce ( this, ScResId( CB_ASONCE) ), |
|
|
218 |
aCkbQuotedAsText( this, ScResId(CB_QUOTED_AS_TEXT) ), |
131 |
aFtTextSep ( this, ScResId( FT_TEXTSEP ) ), |
219 |
aFtTextSep ( this, ScResId( FT_TEXTSEP ) ), |
132 |
aCbTextSep ( this, ScResId( CB_TEXTSEP ) ), |
220 |
aCbTextSep ( this, ScResId( CB_TEXTSEP ) ), |
133 |
|
221 |
|
Lines 146-159
ScImportAsciiDlg::ScImportAsciiDlg( Window* pParent,String aDatName,
Link Here
|
146 |
aFldSepList ( ScResId( SCSTR_FIELDSEP ) ), |
234 |
aFldSepList ( ScResId( SCSTR_FIELDSEP ) ), |
147 |
aTextSepList( ScResId( SCSTR_TEXTSEP ) ), |
235 |
aTextSepList( ScResId( SCSTR_TEXTSEP ) ), |
148 |
mcTextSep ( ScAsciiOptions::cDefaultTextSep ), |
236 |
mcTextSep ( ScAsciiOptions::cDefaultTextSep ), |
149 |
maStrTextToColumns( ScResId( STR_TEXTTOCOLUMNS ) ) |
237 |
maStrTextToColumns( ScResId( STR_TEXTTOCOLUMNS ) ), |
|
|
238 |
mbFileImport(true) |
150 |
{ |
239 |
{ |
151 |
FreeResource(); |
240 |
FreeResource(); |
|
|
241 |
mbFileImport = aDatName.Len() > 0; |
152 |
|
242 |
|
153 |
String aName = GetText(); |
243 |
String aName = GetText(); |
154 |
// aDatName is empty if invoked during paste from clipboard. |
244 |
// aDatName is empty if invoked during paste from clipboard. |
155 |
BOOL bClipboard = (aDatName.Len() == 0); |
245 |
if (mbFileImport) |
156 |
if (!bClipboard) |
|
|
157 |
{ |
246 |
{ |
158 |
aName.AppendAscii(RTL_CONSTASCII_STRINGPARAM(" - [")); |
247 |
aName.AppendAscii(RTL_CONSTASCII_STRINGPARAM(" - [")); |
159 |
aName += aDatName; |
248 |
aName += aDatName; |
Lines 161-180
ScImportAsciiDlg::ScImportAsciiDlg( Window* pParent,String aDatName,
Link Here
|
161 |
} |
250 |
} |
162 |
SetText( aName ); |
251 |
SetText( aName ); |
163 |
|
252 |
|
164 |
switch(cSep) |
253 |
|
|
|
254 |
OUString sFieldSeparators; |
255 |
OUString sTextSeparators; |
256 |
bool bMergeDelimiters = false; |
257 |
bool bFixedWidth = false; |
258 |
bool bQuotedFieldAsText = false; |
259 |
sal_Int32 nFromRow = 1; |
260 |
sal_Int32 nCharSet = -1; |
261 |
if (mbFileImport) |
262 |
// load separators only when importing csv files. |
263 |
load_Separators (sFieldSeparators, sTextSeparators, bMergeDelimiters, |
264 |
bQuotedFieldAsText, bFixedWidth, nFromRow, nCharSet); |
265 |
maFieldSeparators = String(sFieldSeparators); |
266 |
|
267 |
if( bMergeDelimiters ) |
268 |
aCkbAsOnce.Check(); |
269 |
if (bQuotedFieldAsText) |
270 |
aCkbQuotedAsText.Check(); |
271 |
if( bFixedWidth ) |
272 |
aRbFixed.Check(); |
273 |
if( nFromRow != 1 ) |
274 |
aNfRow.SetValue( nFromRow ); |
275 |
|
276 |
ByteString bString(maFieldSeparators,RTL_TEXTENCODING_MS_1252); |
277 |
const sal_Char *aSep = bString.GetBuffer(); |
278 |
int len = maFieldSeparators.Len(); |
279 |
for (int i = 0; i < len; ++i) |
165 |
{ |
280 |
{ |
166 |
case '\t': aCkbTab.Check(); break; |
281 |
switch( aSep[i] ) |
167 |
case ';': aCkbSemicolon.Check(); break; |
282 |
{ |
168 |
case ',': aCkbComma.Check(); break; |
283 |
case '\t': aCkbTab.Check(); break; |
169 |
case ' ': aCkbSpace.Check(); break; |
284 |
case ';': aCkbSemicolon.Check(); break; |
170 |
default: |
285 |
case ',': aCkbComma.Check(); break; |
171 |
aCkbOther.Check(); |
286 |
case ' ': aCkbSpace.Check(); break; |
172 |
aEdOther.SetText( cSep ); |
287 |
default: |
|
|
288 |
aCkbOther.Check(); |
289 |
aEdOther.SetText( aEdOther.GetText() + OUString( aSep[i] ) ); |
290 |
} |
173 |
} |
291 |
} |
|
|
292 |
|
293 |
// Get Separators from the dialog |
174 |
maFieldSeparators = GetSeparators(); |
294 |
maFieldSeparators = GetSeparators(); |
175 |
|
295 |
|
176 |
// Clipboard is always Unicode, else detect. |
296 |
// Clipboard is always Unicode, else detect. |
177 |
BOOL bPreselectUnicode = bClipboard; |
297 |
bool bPreselectUnicode = !mbFileImport; |
178 |
// Sniff for Unicode / not |
298 |
// Sniff for Unicode / not |
179 |
if( !bPreselectUnicode && mpDatStream ) |
299 |
if( !bPreselectUnicode && mpDatStream ) |
180 |
{ |
300 |
{ |
Lines 210-215
ScImportAsciiDlg::ScImportAsciiDlg( Window* pParent,String aDatName,
Link Here
|
210 |
|
330 |
|
211 |
// *** Separator characters *** |
331 |
// *** Separator characters *** |
212 |
lcl_FillCombo( aCbTextSep, aTextSepList, mcTextSep ); |
332 |
lcl_FillCombo( aCbTextSep, aTextSepList, mcTextSep ); |
|
|
333 |
aCbTextSep.SetText( sTextSeparators ); |
213 |
|
334 |
|
214 |
Link aSeparatorHdl =LINK( this, ScImportAsciiDlg, SeparatorHdl ); |
335 |
Link aSeparatorHdl =LINK( this, ScImportAsciiDlg, SeparatorHdl ); |
215 |
aCbTextSep.SetSelectHdl( aSeparatorHdl ); |
336 |
aCbTextSep.SetSelectHdl( aSeparatorHdl ); |
Lines 218-223
ScImportAsciiDlg::ScImportAsciiDlg( Window* pParent,String aDatName,
Link Here
|
218 |
aCkbSemicolon.SetClickHdl( aSeparatorHdl ); |
339 |
aCkbSemicolon.SetClickHdl( aSeparatorHdl ); |
219 |
aCkbComma.SetClickHdl( aSeparatorHdl ); |
340 |
aCkbComma.SetClickHdl( aSeparatorHdl ); |
220 |
aCkbAsOnce.SetClickHdl( aSeparatorHdl ); |
341 |
aCkbAsOnce.SetClickHdl( aSeparatorHdl ); |
|
|
342 |
aCkbQuotedAsText.SetClickHdl( aSeparatorHdl ); |
221 |
aCkbSpace.SetClickHdl( aSeparatorHdl ); |
343 |
aCkbSpace.SetClickHdl( aSeparatorHdl ); |
222 |
aCkbOther.SetClickHdl( aSeparatorHdl ); |
344 |
aCkbOther.SetClickHdl( aSeparatorHdl ); |
223 |
aEdOther.SetModifyHdl( aSeparatorHdl ); |
345 |
aEdOther.SetModifyHdl( aSeparatorHdl ); |
Lines 230-235
ScImportAsciiDlg::ScImportAsciiDlg( Window* pParent,String aDatName,
Link Here
|
230 |
aLbCharSet.InsertTextEncoding( RTL_TEXTENCODING_DONTKNOW, aCharSetUser ); |
352 |
aLbCharSet.InsertTextEncoding( RTL_TEXTENCODING_DONTKNOW, aCharSetUser ); |
231 |
aLbCharSet.SelectTextEncoding( bPreselectUnicode ? |
353 |
aLbCharSet.SelectTextEncoding( bPreselectUnicode ? |
232 |
RTL_TEXTENCODING_UNICODE : gsl_getSystemTextEncoding() ); |
354 |
RTL_TEXTENCODING_UNICODE : gsl_getSystemTextEncoding() ); |
|
|
355 |
|
356 |
if( nCharSet >= 0 ) |
357 |
aLbCharSet.SelectEntryPos( nCharSet ); |
358 |
|
233 |
SetSelectedCharSet(); |
359 |
SetSelectedCharSet(); |
234 |
aLbCharSet.SetSelectHdl( LINK( this, ScImportAsciiDlg, CharSetHdl ) ); |
360 |
aLbCharSet.SetSelectHdl( LINK( this, ScImportAsciiDlg, CharSetHdl ) ); |
235 |
|
361 |
|
Lines 261-266
ScImportAsciiDlg::ScImportAsciiDlg( Window* pParent,String aDatName,
Link Here
|
261 |
|
387 |
|
262 |
ScImportAsciiDlg::~ScImportAsciiDlg() |
388 |
ScImportAsciiDlg::~ScImportAsciiDlg() |
263 |
{ |
389 |
{ |
|
|
390 |
if (mbFileImport) |
391 |
save_Separators( maFieldSeparators, aCbTextSep.GetText(), aCkbAsOnce.IsChecked(), |
392 |
aCkbQuotedAsText.IsChecked(), aRbFixed.IsChecked(), |
393 |
aNfRow.GetValue(), aLbCharSet.GetSelectEntryPos()); |
264 |
delete[] mpRowPosArray; |
394 |
delete[] mpRowPosArray; |
265 |
} |
395 |
} |
266 |
|
396 |
|
Lines 346-351
void ScImportAsciiDlg::GetOptions( ScAsciiOptions& rOpt )
Link Here
|
346 |
{ |
476 |
{ |
347 |
rOpt.SetFieldSeps( GetSeparators() ); |
477 |
rOpt.SetFieldSeps( GetSeparators() ); |
348 |
rOpt.SetMergeSeps( aCkbAsOnce.IsChecked() ); |
478 |
rOpt.SetMergeSeps( aCkbAsOnce.IsChecked() ); |
|
|
479 |
rOpt.SetQuotedAsText(aCkbQuotedAsText.IsChecked()); |
349 |
rOpt.SetTextSep( lcl_CharFromCombo( aCbTextSep, aTextSepList ) ); |
480 |
rOpt.SetTextSep( lcl_CharFromCombo( aCbTextSep, aTextSepList ) ); |
350 |
} |
481 |
} |
351 |
} |
482 |
} |
Lines 357-362
void ScImportAsciiDlg::SetTextToColumnsMode()
Link Here
|
357 |
aLbCharSet.Disable(); |
488 |
aLbCharSet.Disable(); |
358 |
aFtRow.Disable(); |
489 |
aFtRow.Disable(); |
359 |
aNfRow.Disable(); |
490 |
aNfRow.Disable(); |
|
|
491 |
|
492 |
// Quoted field as text option is not used for text to columns mode. |
493 |
aCkbQuotedAsText.Check(false); |
494 |
aCkbQuotedAsText.Disable(); |
360 |
} |
495 |
} |
361 |
|
496 |
|
362 |
void ScImportAsciiDlg::SetSelectedCharSet() |
497 |
void ScImportAsciiDlg::SetSelectedCharSet() |
Lines 393-398
void ScImportAsciiDlg::SetupSeparatorCtrls()
Link Here
|
393 |
aCkbOther.Enable( bEnable ); |
528 |
aCkbOther.Enable( bEnable ); |
394 |
aEdOther.Enable( bEnable ); |
529 |
aEdOther.Enable( bEnable ); |
395 |
aCkbAsOnce.Enable( bEnable ); |
530 |
aCkbAsOnce.Enable( bEnable ); |
|
|
531 |
aCkbQuotedAsText.Enable( bEnable ); |
396 |
aFtTextSep.Enable( bEnable ); |
532 |
aFtTextSep.Enable( bEnable ); |
397 |
aCbTextSep.Enable( bEnable ); |
533 |
aCbTextSep.Enable( bEnable ); |
398 |
} |
534 |
} |