sc/qa/unit/subsequent_export_test5.cxx | 41 +++++++++++++++++++++++++++++++++ sc/source/ui/docshell/docsh.cxx | 2 - 2 files changed, 42 insertions(+), 1 deletion(-)
New commits: commit 4836f5dbc53be01c74d25c9a4cfed1cd16c87785 Author: Andras Timar <[email protected]> AuthorDate: Mon Mar 2 21:11:00 2026 +0100 Commit: Miklos Vajna <[email protected]> CommitDate: Tue Mar 3 09:40:48 2026 +0100 fix CSV import with empty filter options in batch mode When SID_FILE_FILTEROPTIONS is set to an empty string (e.g. via Collabora Online convert-to API without infilterOptions), ReadFromString("") was called which does nothing, but bOptInit was set to true. This prevented the fallback defaults (comma separator, UTF-8, double-quote) from being applied, causing each CSV line to be imported as a single cell. Skip ReadFromString when the filter options string is empty, so the sensible defaults are used instead. Note: the soffice --convert-to command line is not affected, because when --infilter is not specified, SID_FILE_FILTEROPTIONS is not set at all (GetItemIfSet returns nullptr), so the fallback defaults always apply. The bug is specific to the COOL convert-to API path, where the item gets explicitly set to an empty string. Change-Id: I2c53198bf40b7e903166429bbc7584e21ce37629 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200863 Reviewed-by: Miklos Vajna <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> diff --git a/sc/qa/unit/subsequent_export_test5.cxx b/sc/qa/unit/subsequent_export_test5.cxx index 60196628530e..bdef5d6f9edd 100644 --- a/sc/qa/unit/subsequent_export_test5.cxx +++ b/sc/qa/unit/subsequent_export_test5.cxx @@ -17,6 +17,7 @@ #include <svtools/sfxecode.hxx> #include <svl/intitem.hxx> #include <sfx2/docfile.hxx> +#include <comphelper/sequence.hxx> using namespace ::com::sun::star; @@ -594,6 +595,46 @@ CPPUNIT_TEST_FIXTURE(ScCsvJsonFilterTest, testCsvImportExportJsonRoundTrip) CPPUNIT_ASSERT_EQUAL(u"a \"quoted\" note"_ustr, pDoc->GetString(ScAddress(2, 1, 0))); } +CPPUNIT_TEST_FIXTURE(ScCsvJsonFilterTest, testCsvImportEmptyFilterOptions) +{ + // Write a comma-separated CSV file + utl::TempFileNamed aTempFile; + aTempFile.EnableKillingFile(); + { + SvFileStream aStream(aTempFile.GetURL(), StreamMode::WRITE); + aStream.WriteOString("Name,Value,Note Alpha,100,first Beta,200,second "); + aStream.Flush(); + } + + // Load with explicitly empty FilterOptions (simulates convert-to API without + // infilterOptions). Before the fix, ReadFromString("") left the default semicolon + // separator and set bOptInit=true, preventing the comma/UTF-8 fallback defaults. + std::vector<css::beans::PropertyValue> aFilterOptions; + css::beans::PropertyValue aFilterName; + aFilterName.Name = "FilterName"; + aFilterName.Value <<= u"Text - txt - csv (StarCalc)"_ustr; + aFilterOptions.push_back(aFilterName); + css::beans::PropertyValue aFilterOpts; + aFilterOpts.Name = "FilterOptions"; + aFilterOpts.Value <<= OUString(); + aFilterOptions.push_back(aFilterOpts); + loadWithParams(aTempFile.GetURL(), comphelper::containerToSequence(aFilterOptions)); + + ScDocument* pDoc = getScDoc(); + + // With the fix, commas are detected as field separators (fallback defaults apply). + // Without the fix, each line is imported as a single cell. + CPPUNIT_ASSERT_EQUAL(u"Name"_ustr, pDoc->GetString(ScAddress(0, 0, 0))); + CPPUNIT_ASSERT_EQUAL(u"Value"_ustr, pDoc->GetString(ScAddress(1, 0, 0))); + CPPUNIT_ASSERT_EQUAL(u"Note"_ustr, pDoc->GetString(ScAddress(2, 0, 0))); + CPPUNIT_ASSERT_EQUAL(u"Alpha"_ustr, pDoc->GetString(ScAddress(0, 1, 0))); + CPPUNIT_ASSERT_EQUAL(100.0, pDoc->GetValue(ScAddress(1, 1, 0))); + CPPUNIT_ASSERT_EQUAL(u"first"_ustr, pDoc->GetString(ScAddress(2, 1, 0))); + CPPUNIT_ASSERT_EQUAL(u"Beta"_ustr, pDoc->GetString(ScAddress(0, 2, 0))); + CPPUNIT_ASSERT_EQUAL(200.0, pDoc->GetValue(ScAddress(1, 2, 0))); + CPPUNIT_ASSERT_EQUAL(u"second"_ustr, pDoc->GetString(ScAddress(2, 2, 0))); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx index 6978726d4e3e..15c9badb1f72 100644 --- a/sc/source/ui/docshell/docsh.cxx +++ b/sc/source/ui/docshell/docsh.cxx @@ -1485,7 +1485,7 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium ) } bOptInit = true; } - else + else if (!sFilterOptions.isEmpty()) { aOptions.ReadFromString( sFilterOptions, rMedium.GetInStream() ); bOptInit = true;
