diff options
author | Andreas Heinisch <andreas.heinisch@yahoo.de> | 2023-01-20 12:08:13 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2023-02-18 20:05:49 +0000 |
commit | 509ab788baf54285b4e38f2560326657d97510fd (patch) | |
tree | 52b5691914cba7eb0629d5539bef2c1d2b791748 /sc/source/ui/docshell | |
parent | 0a27403bbc36c89efa321fb3c5061fe4ee7095fb (diff) |
tdf#82254 - Don't remove UTF-8 BOM from CSV when saving file
Don't remove the byte-order-mark in the resulting CSV file
when it was present in the CSV source file.
Change-Id: Id26abad2686917f320f2ace85441621bcf57ea9e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145879
Tested-by: Jenkins
Reviewed-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'sc/source/ui/docshell')
-rw-r--r-- | sc/source/ui/docshell/docsh.cxx | 13 | ||||
-rw-r--r-- | sc/source/ui/docshell/impex.cxx | 11 |
2 files changed, 20 insertions, 4 deletions
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx index f37b969bd344..4bf9343734a7 100644 --- a/sc/source/ui/docshell/docsh.cxx +++ b/sc/source/ui/docshell/docsh.cxx @@ -1301,6 +1301,15 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium ) sc::SetFormulaDirtyContext aCxt; m_pDocument->SetAllFormulasDirty(aCxt); + // tdf#82254 - check whether to include a byte-order-mark in the output + if (const bool bIncludeBOM = aImpEx.GetIncludeBOM()) + { + aOptions.SetIncludeBOM(bIncludeBOM); + if (rMedium.GetItemSet() != nullptr) + rMedium.GetItemSet()->Put( + SfxStringItem(SID_FILE_FILTEROPTIONS, aOptions.WriteToString())); + } + // for mobile case, we use a copy of the original document and give it a temporary name before editing // Therefore, the sheet name becomes ugly, long and nonsensical. #if !(defined ANDROID) @@ -1939,6 +1948,7 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt, bool bSaveNumberAsSuch = rAsciiOpt.bSaveNumberAsSuch; bool bSaveAsShown = rAsciiOpt.bSaveAsShown; bool bShowFormulas = rAsciiOpt.bSaveFormulas; + bool bIncludeBOM = rAsciiOpt.bIncludeBOM; rtl_TextEncoding eOldCharSet = rStream.GetStreamCharSet(); rStream.SetStreamCharSet( eCharSet ); @@ -1955,6 +1965,9 @@ void ScDocShell::AsciiSave( SvStream& rStream, const ScImportOptions& rAsciiOpt, } else { + // tdf#82254 - check whether to include a byte-order-mark in the output + if (bIncludeBOM && eCharSet == RTL_TEXTENCODING_UTF8) + rStream.WriteUChar(0xEF).WriteUChar(0xBB).WriteUChar(0xBF); aStrDelimEncoded = OString(&cStrDelim, 1, eCharSet); aDelimEncoded = OString(&cDelim, 1, eCharSet); rtl_TextEncodingInfo aInfo; diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx index 1b8d715890b9..87735c2087a3 100644 --- a/sc/source/ui/docshell/impex.cxx +++ b/sc/source/ui/docshell/impex.cxx @@ -114,7 +114,7 @@ ScImportExport::ScImportExport( ScDocument& r ) bFormulas( false ), bIncludeFiltered( true ), bAll( true ), bSingle( true ), bUndo( false ), bOverflowRow( false ), bOverflowCol( false ), bOverflowCell( false ), - mbApi( true ), mbImportBroadcast(false), mbOverwriting( false ) + mbApi( true ), mbImportBroadcast(false), mbOverwriting( false ), mbIncludeBOM(false) { pUndoDoc = nullptr; pExtOptions = nullptr; @@ -129,7 +129,7 @@ ScImportExport::ScImportExport( ScDocument& r, const ScAddress& rPt ) bFormulas( false ), bIncludeFiltered( true ), bAll( false ), bSingle( true ), bUndo( pDocSh != nullptr ), bOverflowRow( false ), bOverflowCol( false ), bOverflowCell( false ), - mbApi( true ), mbImportBroadcast(false), mbOverwriting( false ) + mbApi( true ), mbImportBroadcast(false), mbOverwriting( false ), mbIncludeBOM(false) { pUndoDoc = nullptr; pExtOptions = nullptr; @@ -145,7 +145,7 @@ ScImportExport::ScImportExport( ScDocument& r, const ScRange& rRange ) bFormulas( false ), bIncludeFiltered( true ), bAll( false ), bSingle( false ), bUndo( pDocSh != nullptr ), bOverflowRow( false ), bOverflowCol( false ), bOverflowCell( false ), - mbApi( true ), mbImportBroadcast(false), mbOverwriting( false ) + mbApi( true ), mbImportBroadcast(false), mbOverwriting( false ), mbIncludeBOM(false) { pUndoDoc = nullptr; pExtOptions = nullptr; @@ -162,7 +162,7 @@ ScImportExport::ScImportExport( ScDocument& r, const OUString& rPos ) bFormulas( false ), bIncludeFiltered( true ), bAll( false ), bSingle( true ), bUndo( pDocSh != nullptr ), bOverflowRow( false ), bOverflowCol( false ), bOverflowCell( false ), - mbApi( true ), mbImportBroadcast(false), mbOverwriting( false ) + mbApi( true ), mbImportBroadcast(false), mbOverwriting( false ), mbIncludeBOM(false) { pUndoDoc = nullptr; pExtOptions = nullptr; @@ -1577,6 +1577,9 @@ bool ScImportExport::ExtText2Doc( SvStream& rStrm ) std::unique_ptr<ScProgress> xProgress( new ScProgress( pDocSh, ScResId( STR_LOAD_DOC ), nRemaining, true )); rStrm.StartReadingUnicodeText( rStrm.GetStreamCharSet() ); + // tdf#82254 - check whether to include a byte-order-mark in the output + if (nOldPos != rStrm.Tell()) + mbIncludeBOM = true; SCCOL nStartCol = aRange.aStart.Col(); SCCOL nEndCol = aRange.aEnd.Col(); |