Blame SOURCES/0001-rhbz-1980800-allow-convert-to-csv-to-write-each-shee.patch

1433b6
From c5a9fb7f00fe4d701d98c4058ad0f506c8dd146f Mon Sep 17 00:00:00 2001
1433b6
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
1433b6
Date: Tue, 13 Jul 2021 12:38:07 +0100
1433b6
Subject: [PATCH] rhbz#1980800 allow --convert-to csv to write each sheet to a
1433b6
 separate file
1433b6
1433b6
Related: tdf#135762 except only currently implemented for command line use
1433b6
1433b6
sample usage:
1433b6
soffice --convert-to csv:"Text - txt - csv (StarCalc)":44,34,UTF8,1,,0,false,true,false,false,false,-1 sample.ods
1433b6
where the new (11th!) final token ("-1") enables writing each sheet to a
1433b6
new file based on the suggested target name so output in this example
1433b6
is files sample-Sheet1.csv and sample-Sheet2.csv
1433b6
1433b6
Only -1 for 'all sheets' vs 0 for existing 'current sheet only' (which
1433b6
is always sheet 0 from the command line) are currently options but the
1433b6
token could be expanded in the future to select specific sheets to
1433b6
export.
1433b6
1433b6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118850
1433b6
Tested-by: Jenkins
1433b6
Reviewed-by: Eike Rathke <erack@redhat.com>
1433b6
(cherry picked from commit b8903bc106dad036acb3d117e5c4fc955697fe02)
1433b6
1433b6
Related: tdf#135762 Allow --convert-to csv to specify 1-based sheet number
1433b6
1433b6
Same multifile mechanism as for -1 all sheets is used, so
1433b6
1433b6
soffice --convert-to csv:"Text - txt - csv (StarCalc)":44,34,UTF8,1,,0,false,true,false,false,false,2 sample.ods
1433b6
1433b6
writes a file sample-Sheet2.csv
1433b6
1433b6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118971
1433b6
Reviewed-by: Eike Rathke <erack@redhat.com>
1433b6
Tested-by: Jenkins
1433b6
(cherry picked from commit fda91f8be16ba760e360940ebafd6244c648cb8c)
1433b6
1433b6
Related: tdf#135762 Suppress cout if not command line
1433b6
1433b6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119294
1433b6
Reviewed-by: Eike Rathke <erack@redhat.com>
1433b6
Tested-by: Jenkins
1433b6
(cherry picked from commit 0cda081c9aa3b3dcb363f97bac60c845ce9a13e0)
1433b6
1433b6
Change-Id: Ib99a120f1a2c8d1008a7a3c59a6b39f572fb346e
1433b6
b9248c9561e4e340c88458ac5dfd159e443a4cfd
1433b6
9431221aadf97739bb197871f25fa151ef4c391c
1433b6
---
1433b6
 desktop/source/app/dispatchwatcher.cxx |  50 +++++++--
1433b6
 include/sfx2/docfile.hxx               |   1 +
1433b6
 sc/source/ui/dbgui/imoptdlg.cxx        |  16 ++-
1433b6
 sc/source/ui/docshell/docsh.cxx        | 141 +++++++++++++++++++++----
1433b6
 sc/source/ui/inc/docsh.hxx             |   2 +-
1433b6
 sc/source/ui/inc/imoptdlg.hxx          |   6 +-
1433b6
 sfx2/source/doc/docfile.cxx            |   4 +
1433b6
 7 files changed, 184 insertions(+), 36 deletions(-)
1433b6
1433b6
diff --git a/desktop/source/app/dispatchwatcher.cxx b/desktop/source/app/dispatchwatcher.cxx
1433b6
index 04140173c6d1..a5365da618e8 100644
1433b6
--- a/desktop/source/app/dispatchwatcher.cxx
1433b6
+++ b/desktop/source/app/dispatchwatcher.cxx
1433b6
@@ -30,6 +30,7 @@
1433b6
 #include "dispatchwatcher.hxx"
1433b6
 #include <rtl/ustring.hxx>
1433b6
 #include <comphelper/processfactory.hxx>
1433b6
+#include <comphelper/string.hxx>
1433b6
 #include <comphelper/synchronousdispatch.hxx>
1433b6
 #include <com/sun/star/io/IOException.hpp>
1433b6
 #include <com/sun/star/util/XCloseable.hpp>
1433b6
@@ -604,6 +605,8 @@ bool DispatchWatcher::executeDispatchRequests( const std::vector
1433b6
                                 aFilter = impl_GuessFilter( aOutFile, aDocService );
1433b6
                             }
1433b6
 
1433b6
+                            bool bMultiFileTarget = false;
1433b6
+
1433b6
                             if (aFilter.isEmpty())
1433b6
                             {
1433b6
                                 std::cerr << "Error: no export filter" << std::endl;
1433b6
@@ -611,29 +614,54 @@ bool DispatchWatcher::executeDispatchRequests( const std::vector
1433b6
                             else
1433b6
                             {
1433b6
                                 sal_Int32 nFilterOptionsIndex = aFilter.indexOf(':');
1433b6
-                                sal_Int32 nProps = ( 0 < nFilterOptionsIndex ) ? 3 : 2;
1433b6
+                                sal_Int32 nProps = ( 0 < nFilterOptionsIndex ) ? 4 : 3;
1433b6
 
1433b6
                                 if ( !aImgOut.isEmpty() )
1433b6
                                     nProps +=1;
1433b6
                                 Sequence<PropertyValue> conversionProperties( nProps );
1433b6
-                                conversionProperties[0].Name = "Overwrite";
1433b6
-                                conversionProperties[0].Value <<= true;
1433b6
+                                conversionProperties[0].Name = "ConversionRequestOrigin";
1433b6
+                                conversionProperties[0].Value <<= OUString("CommandLine");
1433b6
+                                conversionProperties[1].Name = "Overwrite";
1433b6
+                                conversionProperties[1].Value <<= true;
1433b6
 
1433b6
-                                conversionProperties[1].Name = "FilterName";
1433b6
+                                conversionProperties[2].Name = "FilterName";
1433b6
                                 if( 0 < nFilterOptionsIndex )
1433b6
                                 {
1433b6
-                                    conversionProperties[1].Value <<= aFilter.copy(0, nFilterOptionsIndex);
1433b6
+                                    OUString sFilterName = aFilter.copy(0, nFilterOptionsIndex);
1433b6
+                                    OUString sFilterOptions = aFilter.copy(nFilterOptionsIndex + 1);
1433b6
+
1433b6
+                                    if (sFilterName == "Text - txt - csv (StarCalc)")
1433b6
+                                    {
1433b6
+                                        sal_Int32 nIdx(0);
1433b6
+                                        // If the 11th token is '-1' then we export a file
1433b6
+                                        // per sheet where the file name is based on the suggested
1433b6
+                                        // output filename concatenated with the sheet name, so adjust
1433b6
+                                        // the output and overwrite messages
1433b6
+                                        // If the 11th token is not present or numeric 0 then the
1433b6
+                                        // default sheet is exported with the output filename. If it
1433b6
+                                        // is numeric >0 then that sheet (1-based) with the output
1433b6
+                                        // filename concatenated with the sheet name. So even if
1433b6
+                                        // that is a single file, the multi file target mechanism is
1433b6
+                                        // used.
1433b6
+                                        const OUString aTok(sFilterOptions.getToken(11, ',', nIdx));
1433b6
+                                        // Actual validity is checked in Calc, here just check for
1433b6
+                                        // presence of numeric value at start.
1433b6
+                                        bMultiFileTarget = (!aTok.isEmpty() && aTok.toInt32() != 0);
1433b6
+                                    }
1433b6
+
1433b6
+                                    conversionProperties[2].Value <<= sFilterName;
1433b6
 
1433b6
-                                    conversionProperties[2].Name = "FilterOptions";
1433b6
-                                    conversionProperties[2].Value <<= aFilter.copy(nFilterOptionsIndex + 1);
1433b6
+                                    conversionProperties[3].Name = "FilterOptions";
1433b6
+                                    conversionProperties[3].Value <<= sFilterOptions;
1433b6
                                 }
1433b6
                                 else
1433b6
                                 {
1433b6
-                                    conversionProperties[1].Value <<= aFilter;
1433b6
+                                    conversionProperties[2].Value <<= aFilter;
1433b6
                                 }
1433b6
 
1433b6
                                 if ( !aImgOut.isEmpty() )
1433b6
                                 {
1433b6
+                                    assert(conversionProperties[nProps-1].Name.isEmpty());
1433b6
                                     conversionProperties[nProps-1].Name = "ImageFilter";
1433b6
                                     conversionProperties[nProps-1].Value <<= aImgOut;
1433b6
                                 }
1433b6
@@ -645,9 +673,11 @@ bool DispatchWatcher::executeDispatchRequests( const std::vector
1433b6
                                 OString aTargetURL8 = OUStringToOString(aTempName, osl_getThreadTextEncoding());
1433b6
                                 if (aDispatchRequest.aRequestType != REQUEST_CAT)
1433b6
                                 {
1433b6
-                                    std::cout << "convert " << aSource8 << " -> " << aTargetURL8;
1433b6
+                                    std::cout << "convert " << aSource8;
1433b6
+                                    if (!bMultiFileTarget)
1433b6
+                                        std::cout << " -> " << aTargetURL8;
1433b6
                                     std::cout << " using filter : " << OUStringToOString(aFilter, osl_getThreadTextEncoding()) << std::endl;
1433b6
-                                    if (FStatHelper::IsDocument(aOutFile))
1433b6
+                                    if (!bMultiFileTarget && FStatHelper::IsDocument(aOutFile))
1433b6
                                         std::cout << "Overwriting: " << OUStringToOString(aTempName, osl_getThreadTextEncoding()) << std::endl ;
1433b6
                                 }
1433b6
                                 try
1433b6
diff --git a/include/sfx2/docfile.hxx b/include/sfx2/docfile.hxx
1433b6
index 2019b5738c01..09aae02b1976 100644
1433b6
--- a/include/sfx2/docfile.hxx
1433b6
+++ b/include/sfx2/docfile.hxx
1433b6
@@ -108,6 +108,7 @@ public:
1433b6
     const OUString&     GetOrigURL() const;
1433b6
 
1433b6
     SfxItemSet  *       GetItemSet() const;
1433b6
+    css::uno::Sequence<css::beans::PropertyValue> GetArgs() const;
1433b6
     void                Close(bool bInDestruction = false);
1433b6
     void                CloseAndRelease();
1433b6
     void                ReOpen();
1433b6
diff --git a/sc/source/ui/dbgui/imoptdlg.cxx b/sc/source/ui/dbgui/imoptdlg.cxx
1433b6
index 26781924baac..7aa8c8acb061 100644
1433b6
--- a/sc/source/ui/dbgui/imoptdlg.cxx
1433b6
+++ b/sc/source/ui/dbgui/imoptdlg.cxx
1433b6
@@ -20,6 +20,7 @@
1433b6
 #include <imoptdlg.hxx>
1433b6
 #include <asciiopt.hxx>
1433b6
 #include <comphelper/string.hxx>
1433b6
+#include <unotools/charclass.hxx>
1433b6
 #include <osl/thread.h>
1433b6
 #include <global.hxx>
1433b6
 
1433b6
@@ -43,6 +44,7 @@ ScImportOptions::ScImportOptions( const OUString& rStr )
1433b6
     bSaveNumberAsSuch = true;
1433b6
     bSaveFormulas = false;
1433b6
     bRemoveSpace = false;
1433b6
+    nSheetToExport = 0;
1433b6
     sal_Int32 nTokenCount = comphelper::string::getTokenCount(rStr, ',');
1433b6
     if ( nTokenCount >= 3 )
1433b6
     {
1433b6
@@ -76,6 +78,16 @@ ScImportOptions::ScImportOptions( const OUString& rStr )
1433b6
                 bSaveFormulas = rStr.getToken(0, ',', nIdx) == "true";
1433b6
             if ( nTokenCount >= 11 )
1433b6
                 bRemoveSpace = rStr.getToken(0, ',', nIdx) == "true";
1433b6
+            if ( nTokenCount >= 12 )
1433b6
+            {
1433b6
+                const OUString aTok(rStr.getToken(0, ',', nIdx));
1433b6
+                if (aTok == "-1")
1433b6
+                    nSheetToExport = -1;    // all
1433b6
+                else if (aTok.isEmpty() || CharClass::isAsciiNumeric(aTok))
1433b6
+                    nSheetToExport = aTok.toInt32();
1433b6
+                else
1433b6
+                    nSheetToExport = -23;   // invalid, force error
1433b6
+            }
1433b6
         }
1433b6
     }
1433b6
 }
1433b6
@@ -99,7 +111,9 @@ OUString ScImportOptions::BuildString() const
1433b6
             "," +
1433b6
             OUString::boolean( bSaveFormulas ) +  // "save formulas": not in ScAsciiOptions
1433b6
             "," +
1433b6
-            OUString::boolean( bRemoveSpace );    // same as "Remove space" in ScAsciiOptions
1433b6
+            OUString::boolean( bRemoveSpace ) +  // same as "Remove space" in ScAsciiOptions
1433b6
+            "," +
1433b6
+            OUString::number(nSheetToExport) ;  // Only available for command line --convert-to
1433b6
 
1433b6
     return aResult;
1433b6
 }
1433b6
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
1433b6
index bd7402231333..1c544fb6fa1a 100644
1433b6
--- a/sc/source/ui/docshell/docsh.cxx
1433b6
+++ b/sc/source/ui/docshell/docsh.cxx
1433b6
@@ -45,6 +45,7 @@
1433b6
 #include <sfx2/objface.hxx>
1433b6
 #include <sfx2/viewfrm.hxx>
1433b6
 #include <svl/documentlockfile.hxx>
1433b6
+#include <svl/fstathelper.hxx>
1433b6
 #include <svl/sharecontrolfile.hxx>
1433b6
 #include <svl/urihelper.hxx>
1433b6
 #include <osl/file.hxx>
1433b6
@@ -120,6 +121,7 @@
1433b6
 #include <comphelper/processfactory.hxx>
1433b6
 #include <comphelper/string.hxx>
1433b6
 #include <unotools/configmgr.hxx>
1433b6
+#include <unotools/ucbstreamhelper.hxx>
1433b6
 #include <uiitems.hxx>
1433b6
 #include <dpobject.hxx>
1433b6
 #include <markdata.hxx>
1433b6
@@ -1920,7 +1922,7 @@ void escapeTextSep(sal_Int32 nPos, const StrT& rStrDelim, StrT& rStr)
1433b6
 
1433b6
 }
1433b6
 
1433b6
-void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt )
1433b6
+void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt, SCTAB nTab )
1433b6
 {
1433b6
     sal_Unicode cDelim    = rAsciiOpt.nFieldSepCode;
1433b6
     sal_Unicode cStrDelim = rAsciiOpt.nTextSepCode;
1433b6
@@ -1966,7 +1968,6 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt
1433b6
 
1433b6
     SCCOL nStartCol = 0;
1433b6
     SCROW nStartRow = 0;
1433b6
-    SCTAB nTab = GetSaveTab();
1433b6
     SCCOL nEndCol;
1433b6
     SCROW nEndRow;
1433b6
     m_aDocument.GetCellArea( nTab, nEndCol, nEndRow );
1433b6
@@ -2384,35 +2385,129 @@ bool ScDocShell::ConvertTo( SfxMedium &rMed )
1433b6
     }
1433b6
     else if (aFltName == pFilterAscii)
1433b6
     {
1433b6
-        SvStream* pStream = rMed.GetOutStream();
1433b6
-        if (pStream)
1433b6
+        OUString sItStr;
1433b6
+        SfxItemSet*  pSet = rMed.GetItemSet();
1433b6
+        const SfxPoolItem* pItem;
1433b6
+        if ( pSet && SfxItemState::SET ==
1433b6
+             pSet->GetItemState( SID_FILE_FILTEROPTIONS, true, &pItem ) )
1433b6
         {
1433b6
-            OUString sItStr;
1433b6
-            SfxItemSet*  pSet = rMed.GetItemSet();
1433b6
-            const SfxPoolItem* pItem;
1433b6
-            if ( pSet && SfxItemState::SET ==
1433b6
-                 pSet->GetItemState( SID_FILE_FILTEROPTIONS, true, &pItem ) )
1433b6
+            sItStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
1433b6
+        }
1433b6
+
1433b6
+        if ( sItStr.isEmpty() )
1433b6
+        {
1433b6
+            //  default for ascii export (from API without options):
1433b6
+            //  ISO8859-1/MS_1252 encoding, comma, double quotes
1433b6
+
1433b6
+            ScImportOptions aDefOptions( ',', '"', RTL_TEXTENCODING_MS_1252 );
1433b6
+            sItStr = aDefOptions.BuildString();
1433b6
+        }
1433b6
+
1433b6
+        weld::WaitObject aWait( GetActiveDialogParent() );
1433b6
+        ScImportOptions aOptions( sItStr );
1433b6
+
1433b6
+        if (aOptions.nSheetToExport)
1433b6
+        {
1433b6
+            // Only from command line --convert-to
1433b6
+            bRet = true;
1433b6
+
1433b6
+            // Verbose only from command line, not UI (in case we actually
1433b6
+            // implement that) nor macro filter options.
1433b6
+            bool bVerbose = false;
1433b6
+            const css::uno::Sequence<css::beans::PropertyValue> & rArgs = rMed.GetArgs();
1433b6
+            const auto pProp = std::find_if( rArgs.begin(), rArgs.end(),
1433b6
+                    [](const css::beans::PropertyValue& rProp) { return rProp.Name == "ConversionRequestOrigin"; });
1433b6
+            if (pProp != rArgs.end())
1433b6
             {
1433b6
-                sItStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
1433b6
+                OUString aOrigin;
1433b6
+                pProp->Value >>= aOrigin;
1433b6
+                bVerbose = (aOrigin == "CommandLine");
1433b6
             }
1433b6
 
1433b6
-            if ( sItStr.isEmpty() )
1433b6
+            SCTAB nStartTab;
1433b6
+            SCTAB nCount = m_aDocument.GetTableCount();
1433b6
+            if (aOptions.nSheetToExport == -1)
1433b6
             {
1433b6
-                //  default for ascii export (from API without options):
1433b6
-                //  ISO8859-1/MS_1252 encoding, comma, double quotes
1433b6
-
1433b6
-                ScImportOptions aDefOptions( ',', '"', RTL_TEXTENCODING_MS_1252 );
1433b6
-                sItStr = aDefOptions.BuildString();
1433b6
+                // All sheets.
1433b6
+                nStartTab = 0;
1433b6
+            }
1433b6
+            else if (0 < aOptions.nSheetToExport && aOptions.nSheetToExport <= nCount)
1433b6
+            {
1433b6
+                // One sheet, 1-based.
1433b6
+                nCount = aOptions.nSheetToExport;
1433b6
+                nStartTab = nCount - 1;
1433b6
+            }
1433b6
+            else
1433b6
+            {
1433b6
+                // Usage error, no export but log.
1433b6
+                if (bVerbose)
1433b6
+                {
1433b6
+                    if (aOptions.nSheetToExport < 0)
1433b6
+                        std::cout << "Bad sheet number string given." << std::endl;
1433b6
+                    else
1433b6
+                        std::cout << "No sheet number " << aOptions.nSheetToExport
1433b6
+                            << ", number of sheets is " << nCount << std::endl;
1433b6
+                }
1433b6
+                nStartTab = 0;
1433b6
+                nCount = 0;
1433b6
+                SetError(SCERR_EXPORT_DATA);
1433b6
+                bRet = false;
1433b6
             }
1433b6
 
1433b6
-            weld::WaitObject aWait( GetActiveDialogParent() );
1433b6
-            ScImportOptions aOptions( sItStr );
1433b6
-            AsciiSave( *pStream, aOptions );
1433b6
-            bRet = true;
1433b6
+            INetURLObject aURLObject(rMed.GetURLObject());
1433b6
+            OUString sExt = aURLObject.CutExtension();
1433b6
+            OUString sBaseName = aURLObject.GetLastName();
1433b6
+            aURLObject.CutLastName();
1433b6
 
1433b6
-            if (m_aDocument.GetTableCount() > 1)
1433b6
-                if (!rMed.GetError())
1433b6
-                    rMed.SetError(SCWARN_EXPORT_ASCII);
1433b6
+            for (SCTAB i = nStartTab; i < nCount; ++i)
1433b6
+            {
1433b6
+                OUString sTabName;
1433b6
+                if (!m_aDocument.GetName(i, sTabName))
1433b6
+                    sTabName = OUString::number(i);
1433b6
+                INetURLObject aSheetURLObject(aURLObject);
1433b6
+                OUString sFileName = sBaseName + "-" + sTabName;
1433b6
+                if (!sExt.isEmpty())
1433b6
+                    sFileName = sFileName + "." + sExt;
1433b6
+                aSheetURLObject.Append(sFileName);
1433b6
+
1433b6
+                // log similar to DispatchWatcher::executeDispatchRequests
1433b6
+                OUString aOutFile = aSheetURLObject.GetMainURL(INetURLObject::DecodeMechanism::NONE);
1433b6
+                if (bVerbose)
1433b6
+                {
1433b6
+                    OUString aDisplayedName;
1433b6
+                    if (osl::FileBase::E_None != osl::FileBase::getSystemPathFromFileURL(aOutFile, aDisplayedName))
1433b6
+                        aDisplayedName = aOutFile;
1433b6
+                    std::cout << "Writing sheet " << OUStringToOString(sTabName, osl_getThreadTextEncoding()) << " -> "
1433b6
+                                                  << OUStringToOString(aDisplayedName, osl_getThreadTextEncoding())
1433b6
+                                                  << std::endl;
1433b6
+
1433b6
+                    if (FStatHelper::IsDocument(aOutFile))
1433b6
+                        std::cout << "Overwriting: " << OUStringToOString(aDisplayedName, osl_getThreadTextEncoding())
1433b6
+                                                     << std::endl ;
1433b6
+                }
1433b6
+
1433b6
+                std::unique_ptr<SvStream> xStm = ::utl::UcbStreamHelper::CreateStream(aOutFile, StreamMode::TRUNC | StreamMode::WRITE);
1433b6
+                if (!xStm)
1433b6
+                {
1433b6
+                    SetError(ERRCODE_IO_CANTCREATE);
1433b6
+                    bRet = false;
1433b6
+                    break;
1433b6
+                }
1433b6
+                AsciiSave(*xStm, aOptions, i);
1433b6
+            }
1433b6
+        }
1433b6
+        else
1433b6
+        {
1433b6
+            SvStream* pStream = rMed.GetOutStream();
1433b6
+            if (pStream)
1433b6
+            {
1433b6
+                AsciiSave(*pStream, aOptions, GetSaveTab());
1433b6
+                bRet = true;
1433b6
+
1433b6
+                if (m_aDocument.GetTableCount() > 1)
1433b6
+                    if (!rMed.GetError())
1433b6
+                        rMed.SetError(SCWARN_EXPORT_ASCII);
1433b6
+            }
1433b6
         }
1433b6
     }
1433b6
     else if (aFltName == pFilterDBase)
1433b6
diff --git a/sc/source/ui/inc/docsh.hxx b/sc/source/ui/inc/docsh.hxx
1433b6
index a519f4c87d04..6a075ff6dade 100644
1433b6
--- a/sc/source/ui/inc/docsh.hxx
1433b6
+++ b/sc/source/ui/inc/docsh.hxx
1433b6
@@ -230,7 +230,7 @@ public:
1433b6
 
1433b6
     ScDrawLayer*    MakeDrawLayer();
1433b6
 
1433b6
-    void            AsciiSave( SvStream& rStream, const ScImportOptions& rOpt );
1433b6
+    void            AsciiSave( SvStream& rStream, const ScImportOptions& rOpt, SCTAB nTab );
1433b6
 
1433b6
     void            Execute( SfxRequest& rReq );
1433b6
     void            GetState( SfxItemSet &rSet );
1433b6
diff --git a/sc/source/ui/inc/imoptdlg.hxx b/sc/source/ui/inc/imoptdlg.hxx
1433b6
index bac941c2a377..382067d67813 100644
1433b6
--- a/sc/source/ui/inc/imoptdlg.hxx
1433b6
+++ b/sc/source/ui/inc/imoptdlg.hxx
1433b6
@@ -32,7 +32,8 @@ public:
1433b6
         ScImportOptions( sal_Unicode nFieldSep, sal_Unicode nTextSep, rtl_TextEncoding nEnc )
1433b6
             : nFieldSepCode(nFieldSep), nTextSepCode(nTextSep),
1433b6
             bFixedWidth(false), bSaveAsShown(false), bQuoteAllText(false),
1433b6
-            bSaveNumberAsSuch(true), bSaveFormulas(false), bRemoveSpace(false)
1433b6
+            bSaveNumberAsSuch(true), bSaveFormulas(false), bRemoveSpace(false),
1433b6
+            nSheetToExport(0)
1433b6
         { SetTextEncoding( nEnc ); }
1433b6
 
1433b6
     ScImportOptions& operator=( const ScImportOptions& rCpy ) = default;
1433b6
@@ -51,6 +52,9 @@ public:
1433b6
     bool        bSaveNumberAsSuch;
1433b6
     bool        bSaveFormulas;
1433b6
     bool        bRemoveSpace;
1433b6
+    // "0" for 'current sheet', "-1" for all sheets (each to a separate file),
1433b6
+    // or 1-based specific sheet number (to a separate file).
1433b6
+    sal_Int32   nSheetToExport;
1433b6
 };
1433b6
 
1433b6
 #endif // INCLUDED_SC_SOURCE_UI_INC_IMOPTDLG_HXX
1433b6
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
1433b6
index 5d00d39bd837..ccdd3632e6e5 100644
1433b6
--- a/sfx2/source/doc/docfile.cxx
1433b6
+++ b/sfx2/source/doc/docfile.cxx
1433b6
@@ -328,6 +328,8 @@ public:
1433b6
 
1433b6
     util::DateTime m_aDateTime;
1433b6
 
1433b6
+    uno::Sequence<beans::PropertyValue> m_aArgs;
1433b6
+
1433b6
     explicit SfxMedium_Impl();
1433b6
     ~SfxMedium_Impl();
1433b6
     SfxMedium_Impl(const SfxMedium_Impl&) = delete;
1433b6
@@ -3240,6 +3242,7 @@ SfxMedium::SfxMedium( const uno::Sequence<beans::PropertyValue>& aArgs ) :
1433b6
     SfxAllItemSet *pParams = new SfxAllItemSet( SfxGetpApp()->GetPool() );
1433b6
     pImpl->m_pSet.reset( pParams );
1433b6
     TransformParameters( SID_OPENDOC, aArgs, *pParams );
1433b6
+    pImpl->m_aArgs = aArgs;
1433b6
 
1433b6
     OUString aFilterProvider, aFilterName;
1433b6
     {
1433b6
@@ -3301,6 +3304,7 @@ SfxMedium::SfxMedium( const uno::Sequence<beans::PropertyValue>& aArgs ) :
1433b6
     Init_Impl();
1433b6
 }
1433b6
 
1433b6
+uno::Sequence<beans::PropertyValue> SfxMedium::GetArgs() const { return pImpl->m_aArgs; }
1433b6
 
1433b6
 SfxMedium::SfxMedium( const uno::Reference < embed::XStorage >& rStor, const OUString& rBaseURL, const std::shared_ptr<SfxItemSet>& p ) :
1433b6
     pImpl(new SfxMedium_Impl)
1433b6
-- 
1433b6
2.31.1
1433b6