diff options
-rw-r--r-- | desktop/source/app/dispatchwatcher.cxx | 13 | ||||
-rw-r--r-- | sc/source/ui/dbgui/imoptdlg.cxx | 15 | ||||
-rw-r--r-- | sc/source/ui/docshell/docsh.cxx | 34 | ||||
-rw-r--r-- | sc/source/ui/inc/imoptdlg.hxx | 8 |
4 files changed, 58 insertions, 12 deletions
diff --git a/desktop/source/app/dispatchwatcher.cxx b/desktop/source/app/dispatchwatcher.cxx index 8541c273cc83..1c4d878614c5 100644 --- a/desktop/source/app/dispatchwatcher.cxx +++ b/desktop/source/app/dispatchwatcher.cxx @@ -625,11 +625,20 @@ bool DispatchWatcher::executeDispatchRequests( const std::vector<DispatchRequest if (sFilterName == "Text - txt - csv (StarCalc)") { sal_Int32 nIdx(0); - // If the 11th token token is '-1' then we export a file + // If the 11th token is '-1' then we export a file // per sheet where the file name is based on the suggested // output filename concatenated with the sheet name, so adjust // the output and overwrite messages - bMultiFileTarget = sFilterOptions.getToken(11, ',', nIdx) == "-1"; + // If the 11th token is not present or numeric 0 then the + // default sheet is exported with the output filename. If it + // is numeric >0 then that sheet (1-based) with the output + // filename concatenated with the sheet name. So even if + // that is a single file, the multi file target mechanism is + // used. + const OUString aTok(sFilterOptions.getToken(11, ',', nIdx)); + // Actual validity is checked in Calc, here just check for + // presence of numeric value at start. + bMultiFileTarget = (!aTok.isEmpty() && aTok.toInt32() != 0); } conversionProperties[1].Value <<= sFilterName; diff --git a/sc/source/ui/dbgui/imoptdlg.cxx b/sc/source/ui/dbgui/imoptdlg.cxx index d8c4fd810ea3..a362e4df0ee7 100644 --- a/sc/source/ui/dbgui/imoptdlg.cxx +++ b/sc/source/ui/dbgui/imoptdlg.cxx @@ -20,6 +20,7 @@ #include <imoptdlg.hxx> #include <asciiopt.hxx> #include <comphelper/string.hxx> +#include <unotools/charclass.hxx> #include <osl/thread.h> #include <global.hxx> @@ -43,7 +44,7 @@ ScImportOptions::ScImportOptions( const OUString& rStr ) bSaveNumberAsSuch = true; bSaveFormulas = false; bRemoveSpace = false; - bNewFilePerSheet = false; + nSheetToExport = 0; sal_Int32 nTokenCount = comphelper::string::getTokenCount(rStr, ','); if ( nTokenCount < 3 ) return; @@ -79,7 +80,15 @@ ScImportOptions::ScImportOptions( const OUString& rStr ) if ( nTokenCount >= 11 ) bRemoveSpace = rStr.getToken(0, ',', nIdx) == "true"; if ( nTokenCount >= 12 ) - bNewFilePerSheet = rStr.getToken(0, ',', nIdx) == "-1"; + { + const OUString aTok(rStr.getToken(0, ',', nIdx)); + if (aTok == "-1") + nSheetToExport = -1; // all + else if (aTok.isEmpty() || CharClass::isAsciiNumeric(aTok)) + nSheetToExport = aTok.toInt32(); + else + nSheetToExport = -23; // invalid, force error + } } } @@ -104,7 +113,7 @@ OUString ScImportOptions::BuildString() const "," + OUString::boolean( bRemoveSpace ) + // same as "Remove space" in ScAsciiOptions "," + - std::u16string_view(bNewFilePerSheet ? u"-1" : u"0") ; // Only available for command line --convert-to + OUString::number(nSheetToExport) ; // Only available for command line --convert-to return aResult; } diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx index 873e5c598bab..21137a7bb1b6 100644 --- a/sc/source/ui/docshell/docsh.cxx +++ b/sc/source/ui/docshell/docsh.cxx @@ -2412,16 +2412,44 @@ bool ScDocShell::ConvertTo( SfxMedium &rMed ) weld::WaitObject aWait( GetActiveDialogParent() ); ScImportOptions aOptions( sItStr ); - if (aOptions.bNewFilePerSheet) + if (aOptions.nSheetToExport) { + // Only from command line --convert-to bRet = true; + SCTAB nStartTab; + SCTAB nCount = m_aDocument.GetTableCount(); + if (aOptions.nSheetToExport == -1) + { + // All sheets. + nStartTab = 0; + } + else if (0 < aOptions.nSheetToExport && aOptions.nSheetToExport <= nCount) + { + // One sheet, 1-based. + nCount = aOptions.nSheetToExport; + nStartTab = nCount - 1; + } + else + { + // Usage error, no export but log. + if (aOptions.nSheetToExport < 0) + std::cout << "Bad sheet number string given." << std::endl; + else + std::cout << "No sheet number " << OString::number(aOptions.nSheetToExport) + << ", number of sheets is " << nCount << std::endl; + nStartTab = 0; + nCount = 0; + SetError(SCERR_EXPORT_DATA); + bRet = false; + } + INetURLObject aURLObject(rMed.GetURLObject()); OUString sExt = aURLObject.CutExtension(); OUString sBaseName = aURLObject.GetLastName(); aURLObject.CutLastName(); - for (SCTAB i = 0, nCount = m_aDocument.GetTableCount(); i < nCount; ++i) + for (SCTAB i = nStartTab; i < nCount; ++i) { OUString sTabName; if (!m_aDocument.GetName(i, sTabName)) @@ -2447,7 +2475,7 @@ bool ScDocShell::ConvertTo( SfxMedium &rMed ) std::unique_ptr<SvStream> xStm = ::utl::UcbStreamHelper::CreateStream(aOutFile, StreamMode::TRUNC | StreamMode::WRITE); if (!xStm) { - SetError(SCERR_IMPORT_UNKNOWN); + SetError(ERRCODE_IO_CANTCREATE); bRet = false; break; } diff --git a/sc/source/ui/inc/imoptdlg.hxx b/sc/source/ui/inc/imoptdlg.hxx index 2314349f602a..935f271b0c5c 100644 --- a/sc/source/ui/inc/imoptdlg.hxx +++ b/sc/source/ui/inc/imoptdlg.hxx @@ -32,7 +32,7 @@ public: : nFieldSepCode(nFieldSep), nTextSepCode(nTextSep), bFixedWidth(false), bSaveAsShown(false), bQuoteAllText(false), bSaveNumberAsSuch(true), bSaveFormulas(false), bRemoveSpace(false), - bNewFilePerSheet(false) + nSheetToExport(0) { SetTextEncoding( nEnc ); } ScImportOptions& operator=( const ScImportOptions& rCpy ) = default; @@ -51,9 +51,9 @@ public: bool bSaveNumberAsSuch; bool bSaveFormulas; bool bRemoveSpace; - // currently only "0" for 'current sheet' and "-1" for all sheets (each to - // a separate file) are options - bool bNewFilePerSheet; + // "0" for 'current sheet', "-1" for all sheets (each to a separate file), + // or 1-based specific sheet number (to a separate file). + sal_Int32 nSheetToExport; }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |