summaryrefslogtreecommitdiff
path: root/sc/source/ui
diff options
context:
space:
mode:
authorMaxim Monastirsky <momonasmon@gmail.com>2016-05-16 17:14:37 +0300
committerMaxim Monastirsky <momonasmon@gmail.com>2016-05-19 00:01:38 +0300
commit4f1ce46b8d65360436e09750242101b566e6186c (patch)
tree76fd7cf106894e7073d824a211b07e12f1663fa4 /sc/source/ui
parent90891602fc826d11985910fc8e892706cd419539 (diff)
tdf#35208 Allow choosing encoding for old Excel files
Lots of BIFF2-BIFF5 files out there don't have CODEPAGE record at all, or have one with a wrong value, and/or FONT records with wrong charset value. To solve that, this patch adds a new "Choose Encoding" entry to the file picker, so that users could specify the encoding to use for a given file, instead of relying on the information that might be present (or not) inside the file. It can be also used in headless mode, e.g. --infilter="MS Excel (encoded)":61 This doesn't affect BIFF8 import, nor the default behavior when not explicitly using the "Choose Encoding" entry. Change-Id: I89d850d7679b81bd399044478fac7a02e8b7680e
Diffstat (limited to 'sc/source/ui')
-rw-r--r--sc/source/ui/docshell/docsh.cxx26
-rw-r--r--sc/source/ui/docshell/impex.cxx2
-rw-r--r--sc/source/ui/inc/docsh.hxx1
-rw-r--r--sc/source/ui/src/globstr.src4
-rw-r--r--sc/source/ui/unoobj/filtuno.cxx6
5 files changed, 36 insertions, 3 deletions
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index de05c84cc7cc..599fce43d954 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -153,6 +153,7 @@ static const sal_Char pFilterExcel95[] = "MS Excel 95";
static const sal_Char pFilterEx95Temp[] = "MS Excel 95 Vorlage/Template";
static const sal_Char pFilterExcel97[] = "MS Excel 97";
static const sal_Char pFilterEx97Temp[] = "MS Excel 97 Vorlage/Template";
+static const sal_Char pFilterExcelEnc[] = "MS Excel (encoded)";
static const sal_Char pFilterDBase[] = "dBase";
static const sal_Char pFilterDif[] = "DIF";
static const sal_Char pFilterSylk[] = "SYLK";
@@ -1110,7 +1111,8 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
bSetColWidths = true;
bSetRowHeights = true;
}
- else if ( aFltName == pFilterExcel4 || aFltName == pFilterExcel5 ||
+ else if ( aFltName == pFilterExcelEnc ||
+ aFltName == pFilterExcel4 || aFltName == pFilterExcel5 ||
aFltName == pFilterExcel95 || aFltName == pFilterExcel97 ||
aFltName == pFilterEx4Temp || aFltName == pFilterEx5Temp ||
aFltName == pFilterEx95Temp || aFltName == pFilterEx97Temp )
@@ -1124,9 +1126,24 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
else if ( aFltName == pFilterExcel97 || aFltName == pFilterEx97Temp )
eFormat = EIF_BIFF8;
+ rtl_TextEncoding eTextEnc = RTL_TEXTENCODING_DONTKNOW;
+ if ( eFormat != EIF_BIFF8 )
+ {
+ OUString sItStr;
+ SfxItemSet* pSet = rMedium.GetItemSet();
+ const SfxPoolItem* pItem;
+ if ( pSet && SfxItemState::SET ==
+ pSet->GetItemState( SID_FILE_FILTEROPTIONS, true, &pItem ) )
+ {
+ sItStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
+ if ( !sItStr.isEmpty() )
+ eTextEnc = ScGlobal::GetCharsetValue( sItStr );
+ }
+ }
+
MakeDrawLayer(); //! In the filter
CalcOutputFactor(); // prepare update of row height
- FltError eError = ScFormatFilter::Get().ScImportExcel( rMedium, &aDocument, eFormat );
+ FltError eError = ScFormatFilter::Get().ScImportExcel( rMedium, &aDocument, eFormat, eTextEnc );
aDocument.UpdateFontCharSet();
if ( aDocument.IsChartListenerCollectionNeedsUpdate() )
aDocument.UpdateChartListenerCollection(); //! For all imports?
@@ -2598,6 +2615,11 @@ OUString ScDocShell::GetDifFilterName()
return OUString(pFilterDif);
}
+OUString ScDocShell::GetExcelEncodingFilterName()
+{
+ return OUString(pFilterExcelEnc);
+}
+
bool ScDocShell::HasAutomaticTableName( const OUString& rFilter )
{
// sal_True for those filters that keep the default table name
diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx
index 47a796414ce8..9b23831e1c99 100644
--- a/sc/source/ui/docshell/impex.cxx
+++ b/sc/source/ui/docshell/impex.cxx
@@ -2217,7 +2217,7 @@ class ScFormatFilterMissing : public ScFormatFilterPlugin {
virtual ~ScFormatFilterMissing() {}
virtual FltError ScImportLotus123( SfxMedium&, ScDocument*, rtl_TextEncoding ) override { return eERR_INTERN; }
virtual FltError ScImportQuattroPro( SfxMedium &, ScDocument * ) override { return eERR_INTERN; }
- virtual FltError ScImportExcel( SfxMedium&, ScDocument*, const EXCIMPFORMAT ) override { return eERR_INTERN; }
+ virtual FltError ScImportExcel( SfxMedium&, ScDocument*, const EXCIMPFORMAT, rtl_TextEncoding ) override { return eERR_INTERN; }
virtual FltError ScImportStarCalc10( SvStream&, ScDocument* ) override { return eERR_INTERN; }
virtual FltError ScImportDif( SvStream&, ScDocument*, const ScAddress&,
const rtl_TextEncoding, sal_uInt32 ) override { return eERR_INTERN; }
diff --git a/sc/source/ui/inc/docsh.hxx b/sc/source/ui/inc/docsh.hxx
index 079b542e68dc..914f369d6ba1 100644
--- a/sc/source/ui/inc/docsh.hxx
+++ b/sc/source/ui/inc/docsh.hxx
@@ -398,6 +398,7 @@ public:
static OUString GetLotusFilterName();
static OUString GetDBaseFilterName();
static OUString GetDifFilterName();
+ static OUString GetExcelEncodingFilterName();
static bool HasAutomaticTableName( const OUString& rFilter );
DECL_LINK_TYPED( RefreshDBDataHdl, Timer*, void );
diff --git a/sc/source/ui/src/globstr.src b/sc/source/ui/src/globstr.src
index c74373f662b3..f026a13e5640 100644
--- a/sc/source/ui/src/globstr.src
+++ b/sc/source/ui/src/globstr.src
@@ -2109,6 +2109,10 @@ Resource RID_GLOBSTR
{
Text [ en-US ] = "%1 and %2 more";
};
+ String STR_IMPORT_EXCEL_ENCODING
+ {
+ Text [ en-US ] = "Import Excel file";
+ };
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/unoobj/filtuno.cxx b/sc/source/ui/unoobj/filtuno.cxx
index 96f74ce7b949..eac4e805da4c 100644
--- a/sc/source/ui/unoobj/filtuno.cxx
+++ b/sc/source/ui/unoobj/filtuno.cxx
@@ -274,6 +274,12 @@ sal_Int16 SAL_CALL ScFilterOptionsObj::execute() throw(uno::RuntimeException, st
// common for DIF import/export
eEncoding = RTL_TEXTENCODING_MS_1252;
}
+ else if ( aFilterString == ScDocShell::GetExcelEncodingFilterName() )
+ {
+ SAL_WARN_IF( bExport, "sc.ui", "Filter Options for Excel Export is not implemented" );
+ aTitle = ScGlobal::GetRscString( STR_IMPORT_EXCEL_ENCODING );
+ eEncoding = RTL_TEXTENCODING_MS_1252;
+ }
ScImportOptions aOptions( cAsciiDel, cStrDel, eEncoding);