1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 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/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 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 . 18 */ 19 20 #include <imoptdlg.hxx> 21 #include <asciiopt.hxx> 22 #include <comphelper/string.hxx> 23 #include <osl/thread.h> 24 #include <rtl/tencinfo.h> 25 #include <global.hxx> 26 27 static const sal_Char pStrFix[] = "FIX"; 28 29 // The option string can no longer contain a semicolon (because of pick list), 30 // therefore, starting with version 336 comma instead 31 32 ScImportOptions::ScImportOptions( const OUString& rStr ) 33 { 34 // Use the same string format as ScAsciiOptions, 35 // because the import options string is passed here when a CSV file is loaded and saved again. 36 // The old format is still supported because it might be used in macros. 37 38 bFixedWidth = false; 39 nFieldSepCode = 0; 40 nTextSepCode = 0; 41 eCharSet = RTL_TEXTENCODING_DONTKNOW; 42 bSaveAsShown = true; // "true" if not in string (after CSV import) 43 bQuoteAllText = false; 44 bSaveFormulas = false; 45 bRemoveSpace = false; 46 sal_Int32 nTokenCount = comphelper::string::getTokenCount(rStr, ','); 47 if ( nTokenCount >= 3 ) 48 { 49 // first 3 tokens: common 50 OUString aToken( rStr.getToken( 0, ',' ) ); 51 if( aToken.equalsIgnoreAsciiCase( pStrFix ) ) 52 bFixedWidth = true; 53 else 54 nFieldSepCode = ScAsciiOptions::GetWeightedFieldSep( aToken, true); 55 nTextSepCode = static_cast<sal_Unicode>(rStr.getToken(1,',').toInt32()); 56 aStrFont = rStr.getToken(2,','); 57 eCharSet = ScGlobal::GetCharsetValue(aStrFont); 58 59 if ( nTokenCount == 4 ) 60 { 61 // compatibility with old options string: "Save as shown" as 4th token, numeric 62 bSaveAsShown = rStr.getToken( 3, ',' ).toInt32() != 0; 63 bQuoteAllText = true; // use old default then 64 } 65 else 66 { 67 // look at the same positions as in ScAsciiOptions 68 if ( nTokenCount >= 7 ) 69 bQuoteAllText = rStr.getToken(6, ',') == "true"; 70 if ( nTokenCount >= 9 ) 71 bSaveAsShown = rStr.getToken(8, ',') == "true"; 72 if ( nTokenCount >= 10 ) 73 bSaveFormulas = rStr.getToken(9, ',') == "true"; 74 if ( nTokenCount >= 11 ) 75 bRemoveSpace = rStr.getToken(10, ',') == "true"; 76 } 77 } 78 } 79 80 OUString ScImportOptions::BuildString() const 81 { 82 OUString aResult; 83 84 if( bFixedWidth ) 85 aResult += pStrFix; 86 else 87 aResult += OUString::number(nFieldSepCode); 88 aResult += "," + OUString::number(nTextSepCode) + "," + aStrFont + 89 // use the same string format as ScAsciiOptions: 90 ",1,,0," + // first row, no column info, default language 91 OUString::boolean( bQuoteAllText ) + // same as "quoted field as text" in ScAsciiOptions 92 ",true," + // "detect special numbers" 93 OUString::boolean( bSaveAsShown ) + // "save as shown": not in ScAsciiOptions 94 "," + 95 OUString::boolean( bSaveFormulas ) + // "save formulas": not in ScAsciiOptions 96 "," + 97 OUString::boolean( bRemoveSpace ); // same as "Remove space" in ScAsciiOptions 98 99 return aResult; 100 } 101 102 void ScImportOptions::SetTextEncoding( rtl_TextEncoding nEnc ) 103 { 104 eCharSet = (nEnc == RTL_TEXTENCODING_DONTKNOW ? 105 osl_getThreadTextEncoding() : nEnc); 106 aStrFont = ScGlobal::GetCharsetString( nEnc ); 107 } 108 109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 110
