diff options
author | Eike Rathke <erack@redhat.com> | 2013-02-22 00:27:26 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2013-02-22 13:57:04 +0100 |
commit | 8970e14d7494859c6079ef2a976416598823ba50 (patch) | |
tree | 9151b52f48c6156e1bf10460ba5424d2fc604ecf /sc | |
parent | 30fee57e6c8d5d71e744ad61aec8b240a81909b8 (diff) |
resolved fdo#57841 ignore embedded NULL characters in CSV import
Change-Id: Ib0eb044f009227c0aa6e1bc520905d605323c3db
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/ui/dbgui/scuiasciiopt.cxx | 2 | ||||
-rw-r--r-- | sc/source/ui/docshell/impex.cxx | 19 | ||||
-rw-r--r-- | sc/source/ui/inc/impex.hxx | 2 |
3 files changed, 23 insertions, 0 deletions
diff --git a/sc/source/ui/dbgui/scuiasciiopt.cxx b/sc/source/ui/dbgui/scuiasciiopt.cxx index cfa4d4e2e3fa..9624fde0c13a 100644 --- a/sc/source/ui/dbgui/scuiasciiopt.cxx +++ b/sc/source/ui/dbgui/scuiasciiopt.cxx @@ -540,6 +540,8 @@ bool ScImportAsciiDlg::GetLine( sal_uLong nLine, rtl::OUString &rText ) if ( mpDatStream->GetError() == ERRCODE_IO_CANTSEEK ) mpDatStream->ResetError(); + ScImportExport::EmbeddedNullTreatment( rText); + return bRet; } diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx index 6e7e16c0c679..8cff0c90396e 100644 --- a/sc/source/ui/docshell/impex.cxx +++ b/sc/source/ui/docshell/impex.cxx @@ -1335,6 +1335,8 @@ bool ScImportExport::ExtText2Doc( SvStream& rStrm ) if ( rStrm.IsEof() && aLine.isEmpty() ) break; + EmbeddedNullTreatment( aLine); + sal_Int32 nLineLen = aLine.getLength(); SCCOL nCol = nStartCol; bool bMultiLine = false; @@ -1473,6 +1475,23 @@ bool ScImportExport::ExtText2Doc( SvStream& rStrm ) } +void ScImportExport::EmbeddedNullTreatment( OUString & rStr ) +{ + // A nasty workaround for data with embedded NULL characters. As long as we + // can't handle them properly as cell content (things assume 0-terminated + // strings at too many places) simply strip all NULL characters from raw + // data. Excel does the same. See fdo#57841 for sample data. + + // The normal case is no embedded NULL, check first before de-/allocating + // ustring stuff. + sal_Unicode cNull = 0; + if (rStr.indexOf( cNull) >= 0) + { + rStr = rStr.replaceAll( OUString( &cNull, 1), OUString()); + } +} + + const sal_Unicode* ScImportExport::ScanNextFieldFromString( const sal_Unicode* p, String& rField, sal_Unicode cStr, const sal_Unicode* pSeps, bool bMergeSeps, bool& rbIsQuoted, bool& rbOverflowCell ) diff --git a/sc/source/ui/inc/impex.hxx b/sc/source/ui/inc/impex.hxx index c42720658a96..8c7e36b26dbe 100644 --- a/sc/source/ui/inc/impex.hxx +++ b/sc/source/ui/inc/impex.hxx @@ -102,6 +102,8 @@ public: bool IsUndo() const { return bUndo; } void SetUndo( bool b ) { bUndo = b; } + SC_DLLPUBLIC static void EmbeddedNullTreatment( OUString & rStr ); + static bool IsFormatSupported( sal_uLong nFormat ); static const sal_Unicode* ScanNextFieldFromString( const sal_Unicode* p, String& rField, sal_Unicode cStr, const sal_Unicode* pSeps, |