1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "imoptdlg.hxx"
21 #include "asciiopt.hxx"
22 #include "scresid.hxx"
23 #include <comphelper/string.hxx>
24 #include <osl/thread.h>
25 #include <rtl/tencinfo.h>
27 static const sal_Char pStrFix
[] = "FIX";
30 // Der Options-String darf kein Semikolon mehr enthalten (wegen Pickliste)
31 // darum ab Version 336 Komma stattdessen
34 ScImportOptions::ScImportOptions( const OUString
& rStr
)
36 // Use the same string format as ScAsciiOptions,
37 // because the import options string is passed here when a CSV file is loaded and saved again.
38 // The old format is still supported because it might be used in macros.
43 eCharSet
= RTL_TEXTENCODING_DONTKNOW
;
44 bSaveAsShown
= true; // "true" if not in string (after CSV import)
45 bQuoteAllText
= false;
46 bSaveFormulas
= false;
47 sal_Int32 nTokenCount
= comphelper::string::getTokenCount(rStr
, ',');
48 if ( nTokenCount
>= 3 )
50 // first 3 tokens: common
51 OUString
aToken( rStr
.getToken( 0, ',' ) );
52 if( aToken
.equalsIgnoreAsciiCase( pStrFix
) )
55 nFieldSepCode
= ScAsciiOptions::GetWeightedFieldSep( aToken
, true);
56 nTextSepCode
= (sal_Unicode
) rStr
.getToken(1,',').toInt32();
57 aStrFont
= rStr
.getToken(2,',');
58 eCharSet
= ScGlobal::GetCharsetValue(aStrFont
);
60 if ( nTokenCount
== 4 )
62 // compatibility with old options string: "Save as shown" as 4th token, numeric
63 bSaveAsShown
= (rStr
.getToken( 3, ',' ).toInt32() ? true : false);
64 bQuoteAllText
= true; // use old default then
68 // look at the same positions as in ScAsciiOptions
69 if ( nTokenCount
>= 7 )
70 bQuoteAllText
= rStr
.getToken(6, ',').equalsAscii("true");
71 if ( nTokenCount
>= 9 )
72 bSaveAsShown
= rStr
.getToken(8, ',').equalsAscii("true");
73 if ( nTokenCount
>= 10 )
74 bSaveFormulas
= rStr
.getToken(9, ',').equalsAscii("true");
79 OUString
ScImportOptions::BuildString() const
86 aResult
+= OUString::number(nFieldSepCode
);
87 aResult
+= "," + OUString::number(nTextSepCode
) + "," + aStrFont
+
88 // use the same string format as ScAsciiOptions:
89 ",1,,0," + // first row, no column info, default language
90 OUString::boolean( bQuoteAllText
) + // same as "quoted field as text" in ScAsciiOptions
91 ",true," + // "detect special numbers"
92 OUString::boolean( bSaveAsShown
) + // "save as shown": not in ScAsciiOptions
94 OUString::boolean( bSaveFormulas
); // "save formulas": not in ScAsciiOptions
99 void ScImportOptions::SetTextEncoding( rtl_TextEncoding nEnc
)
101 eCharSet
= (nEnc
== RTL_TEXTENCODING_DONTKNOW
?
102 osl_getThreadTextEncoding() : nEnc
);
103 aStrFont
= ScGlobal::GetCharsetString( nEnc
);
106 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */