summaryrefslogtreecommitdiff
path: root/sc/source
diff options
context:
space:
mode:
authorGabriel Masei <gabriel.masei@1and1.ro>2024-03-17 10:13:25 +0200
committerMike Kaganski <mike.kaganski@collabora.com>2024-04-06 19:39:22 +0200
commit2feda8ba21acdcf33a9b4ba94742f574c17839bd (patch)
tree3060f16f398131e08545fe15d909ea3753a800d6 /sc/source
parent2564374efebb5218fbc3c81540fe95557f6119ac (diff)
tdf#152336 Detect charset and separators for csv files
Change-Id: Ie8451b3d30e390d363d8f9e5ec8bdf47350ca3a2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164936 Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sc/source')
-rw-r--r--sc/source/ui/attrdlg/scdlgfact.cxx5
-rw-r--r--sc/source/ui/attrdlg/scdlgfact.hxx3
-rw-r--r--sc/source/ui/dbgui/scuiasciiopt.cxx33
-rw-r--r--sc/source/ui/inc/scuiasciiopt.hxx3
-rw-r--r--sc/source/ui/unoobj/filtuno.cxx12
5 files changed, 46 insertions, 10 deletions
diff --git a/sc/source/ui/attrdlg/scdlgfact.cxx b/sc/source/ui/attrdlg/scdlgfact.cxx
index 4fe36f303c57..03926077d9f1 100644
--- a/sc/source/ui/attrdlg/scdlgfact.cxx
+++ b/sc/source/ui/attrdlg/scdlgfact.cxx
@@ -1058,9 +1058,10 @@ const SfxItemSet* ScAsyncTabController_Impl::GetOutputItemSet() const
// =========================Factories for createdialog ===================
VclPtr<AbstractScImportAsciiDlg> ScAbstractDialogFactory_Impl::CreateScImportAsciiDlg(weld::Window* pParent,
const OUString& aDatName,
- SvStream* pInStream, ScImportAsciiCall eCall)
+ SvStream* pInStream, ScImportAsciiCall eCall,
+ ScAsciiOptions* aOptions)
{
- return VclPtr<AbstractScImportAsciiDlg_Impl>::Create(std::make_shared<ScImportAsciiDlg>(pParent, aDatName,pInStream, eCall));
+ return VclPtr<AbstractScImportAsciiDlg_Impl>::Create(std::make_shared<ScImportAsciiDlg>(pParent, aDatName,pInStream, eCall, aOptions));
}
VclPtr<AbstractScTextImportOptionsDlg> ScAbstractDialogFactory_Impl::CreateScTextImportOptionsDlg(weld::Window* pParent)
diff --git a/sc/source/ui/attrdlg/scdlgfact.hxx b/sc/source/ui/attrdlg/scdlgfact.hxx
index 276bffd63195..4644ff4b35e2 100644
--- a/sc/source/ui/attrdlg/scdlgfact.hxx
+++ b/sc/source/ui/attrdlg/scdlgfact.hxx
@@ -663,7 +663,8 @@ public:
virtual VclPtr<AbstractScImportAsciiDlg> CreateScImportAsciiDlg(weld::Window* pParent,
const OUString& aDatName,
SvStream* pInStream,
- ScImportAsciiCall eCall) override;
+ ScImportAsciiCall eCall,
+ ScAsciiOptions* aOptions = nullptr) override;
virtual VclPtr<AbstractScTextImportOptionsDlg> CreateScTextImportOptionsDlg(weld::Window* pParent) override;
diff --git a/sc/source/ui/dbgui/scuiasciiopt.cxx b/sc/source/ui/dbgui/scuiasciiopt.cxx
index 601323a6586d..6cb73c803c39 100644
--- a/sc/source/ui/dbgui/scuiasciiopt.cxx
+++ b/sc/source/ui/dbgui/scuiasciiopt.cxx
@@ -316,7 +316,8 @@ static void lcl_SaveSeparators(
}
ScImportAsciiDlg::ScImportAsciiDlg(weld::Window* pParent, std::u16string_view aDatName,
- SvStream* pInStream, ScImportAsciiCall eCall)
+ SvStream* pInStream, ScImportAsciiCall eCall,
+ const ScAsciiOptions* aOptions)
: GenericDialogController(pParent, "modules/scalc/ui/textimportcsv.ui", "TextImportCsvDialog")
, mpDatStream(pInStream)
, mnStreamPos(pInStream ? pInStream->Tell() : 0)
@@ -385,7 +386,27 @@ ScImportAsciiDlg::ScImportAsciiDlg(weld::Window* pParent, std::u16string_view aD
sal_Int32 nFromRow = 1;
sal_Int32 nCharSet = -1;
sal_Int32 nLanguage = 0;
- lcl_LoadSeparators (sFieldSeparators, sTextSeparators, bMergeDelimiters,
+
+ if (aOptions)
+ {
+ if (!aOptions->GetFieldSeps().isEmpty())
+ sFieldSeparators = aOptions->GetFieldSeps();
+ if (aOptions->GetTextSep())
+ sTextSeparators = OUStringChar(aOptions->GetTextSep());
+ bMergeDelimiters = aOptions->IsMergeSeps();
+ bFixedWidth = aOptions->IsFixedLen();
+ bQuotedFieldAsText = aOptions->IsQuotedAsText();
+ bDetectSpecialNum = aOptions->IsDetectSpecialNumber();
+ bDetectScientificNum = aOptions->IsDetectScientificNumber();
+ bEvaluateFormulas = aOptions->IsEvaluateFormulas();
+ bSkipEmptyCells = aOptions->IsSkipEmptyCells();
+ bRemoveSpace = aOptions->IsRemoveSpace();
+ nFromRow = aOptions->GetStartRow();
+ nCharSet = aOptions->GetCharSet();
+ nLanguage = static_cast<sal_uInt16>(aOptions->GetLanguage());
+ }
+ else
+ lcl_LoadSeparators (sFieldSeparators, sTextSeparators, bMergeDelimiters,
bQuotedFieldAsText, bDetectSpecialNum, bDetectScientificNum, bFixedWidth, nFromRow,
nCharSet, nLanguage, bSkipEmptyCells, bRemoveSpace, bEvaluateFormulas, meCall);
// load from saved settings
@@ -415,8 +436,8 @@ ScImportAsciiDlg::ScImportAsciiDlg(weld::Window* pParent, std::u16string_view aD
mxNfRow->set_value(nFromRow);
// Clipboard is always Unicode, else detect.
- rtl_TextEncoding ePreselectUnicode = (meCall == SC_IMPORTFILE ?
- RTL_TEXTENCODING_DONTKNOW : RTL_TEXTENCODING_UNICODE);
+ rtl_TextEncoding ePreselectUnicode = (aOptions ? aOptions->GetCharSet() : (meCall == SC_IMPORTFILE ?
+ RTL_TEXTENCODING_DONTKNOW : RTL_TEXTENCODING_UNICODE));
// Sniff for Unicode / not
if( ePreselectUnicode == RTL_TEXTENCODING_DONTKNOW && mpDatStream )
{
@@ -463,7 +484,9 @@ ScImportAsciiDlg::ScImportAsciiDlg(weld::Window* pParent, std::u16string_view aD
mnStreamPos = mpDatStream->Tell();
}
- if (bIsTSV)
+ if (aOptions && !maFieldSeparators.isEmpty())
+ SetSeparators(0);
+ else if (bIsTSV)
SetSeparators('\t');
else
{
diff --git a/sc/source/ui/inc/scuiasciiopt.hxx b/sc/source/ui/inc/scuiasciiopt.hxx
index 309192477ecf..ee8ca78b221d 100644
--- a/sc/source/ui/inc/scuiasciiopt.hxx
+++ b/sc/source/ui/inc/scuiasciiopt.hxx
@@ -83,7 +83,8 @@ class ScImportAsciiDlg : public weld::GenericDialogController
public:
ScImportAsciiDlg(
weld::Window* pParent, std::u16string_view aDatName,
- SvStream* pInStream, ScImportAsciiCall eCall );
+ SvStream* pInStream, ScImportAsciiCall eCall,
+ const ScAsciiOptions* aOptions = nullptr );
virtual ~ScImportAsciiDlg() override;
void GetOptions( ScAsciiOptions& rOpt );
diff --git a/sc/source/ui/unoobj/filtuno.cxx b/sc/source/ui/unoobj/filtuno.cxx
index fa520e23aeff..b5e9421b5440 100644
--- a/sc/source/ui/unoobj/filtuno.cxx
+++ b/sc/source/ui/unoobj/filtuno.cxx
@@ -179,15 +179,25 @@ sal_Int16 SAL_CALL ScFilterOptionsObj::execute()
{
// ascii import is special...
+ ScAsciiOptions aInOptions, *pInOptions = nullptr;
INetURLObject aURL( aFileName );
// tdf#132421 - don't URL encode filename for the import ASCII dialog title
OUString aPrivDatName(aURL.GetLastName(INetURLObject::DecodeMechanism::Unambiguous));
std::unique_ptr<SvStream> pInStream;
if ( xInputStream.is() )
+ {
pInStream = utl::UcbStreamHelper::CreateStream( xInputStream );
+ if (aFilterOptions.isEmpty())
+ aFilterOptions = "DETECT,34,DETECT,,,,,,,,,,,,";
+ SfxObjectShell::DetectCsvFilterOptions(*pInStream, aFilterOptions);
+
+ aInOptions.ReadFromString(aFilterOptions);
+ pInOptions = &aInOptions;
+ }
+
ScopedVclPtr<AbstractScImportAsciiDlg> pDlg(pFact->CreateScImportAsciiDlg(Application::GetFrameWeld(xDialogParent), aPrivDatName,
- pInStream.get(), SC_IMPORTFILE));
+ pInStream.get(), SC_IMPORTFILE, pInOptions));
if ( pDlg->Execute() == RET_OK )
{
ScAsciiOptions aOptions;