LibreOffice Module sc (master) 1
impex.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#pragma once
21
22#include <o3tl/deleter.hxx>
23#include <sot/formats.hxx>
24#include <address.hxx>
25#include <tools/stream.hxx>
26
27#include <com/sun/star/uno/Any.hxx>
28
29class ScDocShell;
30class ScDocument;
31class ScAsciiOptions;
32
38{
40 ScExportTextOptions( NewlineConversion eNewlineConversion = ToSystem, sal_Unicode cSeparatorConvertTo = 0, bool bAddQuotes = false ) :
41 meNewlineConversion( eNewlineConversion ), mcSeparatorConvertTo( cSeparatorConvertTo ), mbAddQuotes( bAddQuotes ) {}
42
44 sal_Unicode mcSeparatorConvertTo; // Convert separator to this character
46};
47
49{
52 std::unique_ptr<ScDocument, o3tl::default_delete<ScDocument>> pUndoDoc;
54 OUString aStreamPath;
57 sal_uInt32 nSizeLimit;
59 sal_Unicode cSep; // Separator
60 sal_Unicode cStr; // String Delimiter
61 bool bFormulas; // Formula in Text?
62 bool bIncludeFiltered; // include filtered rows? (default true)
63 bool bAll; // no selection
64 bool bSingle; // Single selection
65 bool bUndo; // with Undo?
66 bool bOverflowRow; // too many rows
67 bool bOverflowCol; // too many columns
68 bool bOverflowCell; // too much data for a cell
69 bool mbApi;
70 bool mbImportBroadcast; // whether or not to broadcast after data import.
71 bool mbOverwriting; // Whether we could be overwriting existing values (paste).
72 // In this case we cannot use the insert optimization, but we
73 // do not need to broadcast after the import.
74 bool mbIncludeBOM; // Whether to include a byte-order-mark in the output.
76
77 std::unique_ptr<ScAsciiOptions> pExtOptions; // extended options
78
79 bool StartPaste(); // Protect check, set up Undo
80 void EndPaste(bool bAutoRowHeight = true); // Undo/Redo actions, Repaint
81 bool Doc2Text( SvStream& );
82 bool Text2Doc( SvStream& );
83 bool Doc2Sylk( SvStream& );
84 bool Sylk2Doc( SvStream& );
85 bool Doc2HTML( SvStream&, const OUString& );
86 bool Doc2RTF( SvStream& );
87 bool Doc2Dif( SvStream& );
88 bool Dif2Doc( SvStream& );
89 bool ExtText2Doc( SvStream& ); // with pExtOptions
90 bool RTF2Doc( SvStream&, const OUString& rBaseURL );
91 bool HTML2Doc( SvStream&, const OUString& rBaseURL );
92
93public:
94 ScImportExport( ScDocument& ); // the whole document
95 ScImportExport( ScDocument&, const OUString& ); // Range/cell input
98 ~ScImportExport() COVERITY_NOEXCEPT_FALSE;
99
100 void SetExtOptions( const ScAsciiOptions& rOpt );
101 void SetFilterOptions( const OUString& rFilterOptions );
102 bool IsRef() const { return !bAll; }
103
104 const ScRange& GetRange() const { return aRange; }
105
106 static void EmbeddedNullTreatment( OUString & rStr );
107
108 static bool IsFormatSupported( SotClipboardFormatId nFormat );
109 static const sal_Unicode* ScanNextFieldFromString( const sal_Unicode* p,
110 OUString& rField, sal_Unicode cStr, const sal_Unicode* pSeps,
111 bool bMergeSeps, bool& rbIsQuoted, bool& rbOverflowCell, bool bRemoveSpace );
112 static void WriteUnicodeOrByteString( SvStream& rStrm, std::u16string_view rString, bool bZero = false );
113 static void WriteUnicodeOrByteEndl( SvStream& rStrm );
114
123 static sal_Int32 CountVisualWidth(const OUString& rStr, sal_Int32& nIdx, sal_Int32 nMaxWidth);
124
128 static sal_Int32 CountVisualWidth(const OUString& rStr);
129
131 static void SetNoEndianSwap( SvStream& rStrm );
132
133 void SetSeparator( sal_Unicode c ) { cSep = c; }
134 void SetDelimiter( sal_Unicode c ) { cStr = c; }
135 void SetFormulas( bool b ) { bFormulas = b; }
136 void SetIncludeFiltered( bool b ) { bIncludeFiltered = b; }
137
138 void SetStreamPath( const OUString& rPath ) { aStreamPath = rPath; }
139
140 bool ImportString( const OUString&, SotClipboardFormatId );
141 bool ExportString( OUString&, SotClipboardFormatId );
142 bool ExportByteString( OString&, rtl_TextEncoding, SotClipboardFormatId );
143
144 bool ImportStream( SvStream&, const OUString& rBaseURL, SotClipboardFormatId );
145 bool ExportStream( SvStream&, const OUString& rBaseURL, SotClipboardFormatId );
146
147 bool ExportData( std::u16string_view rMimeType,
148 css::uno::Any & rValue );
149
150 // after import
151 bool IsOverflowRow() const { return bOverflowRow; }
152 bool IsOverflowCol() const { return bOverflowCol; }
153 bool IsOverflowCell() const { return bOverflowCell; }
154 bool IsOverflow() const { return bOverflowRow || bOverflowCol || bOverflowCell; }
155
156 const OUString& GetNonConvertibleChars() const { return aNonConvertibleChars; }
157
158 void SetApi( bool bApi ) { mbApi = bApi; }
159 void SetImportBroadcast( bool b ) { mbImportBroadcast = b; }
160 void SetOverwriting( const bool bOverwriting ) { mbOverwriting = bOverwriting; }
161 void SetExportTextOptions( const ScExportTextOptions& options ) { mExportTextOptions = options; }
162
163 bool GetIncludeBOM() const { return mbIncludeBOM; }
164};
165
166// Helper class for importing clipboard strings as streams.
168{
169public:
170 ScImportStringStream(const OUString& rStr);
171};
172
240SC_DLLPUBLIC OUString ReadCsvLine( SvStream &rStream, bool bEmbeddedLineBreak,
241 OUString& rFieldSeparators, sal_Unicode cFieldQuote, sal_Unicode& rcDetectSep,
242 sal_uInt32 nMaxSourceLines = 0 );
243
244/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScRange aRange
Definition: impex.hxx:53
void SetIncludeFiltered(bool b)
Definition: impex.hxx:136
sal_Unicode cStr
Definition: impex.hxx:60
bool mbOverwriting
Definition: impex.hxx:71
bool IsOverflowCol() const
Definition: impex.hxx:152
void SetApi(bool bApi)
Definition: impex.hxx:158
OUString aStreamPath
Definition: impex.hxx:54
void SetFormulas(bool b)
Definition: impex.hxx:135
bool mbIncludeBOM
Definition: impex.hxx:74
void SetStreamPath(const OUString &rPath)
Definition: impex.hxx:138
bool bOverflowCell
Definition: impex.hxx:68
bool bOverflowCol
Definition: impex.hxx:67
ScExportTextOptions mExportTextOptions
Definition: impex.hxx:75
bool bUndo
Definition: impex.hxx:65
bool mbImportBroadcast
Definition: impex.hxx:70
ScImportExport(ScDocument &, const ScAddress &)
const ScRange & GetRange() const
Definition: impex.hxx:104
void SetExportTextOptions(const ScExportTextOptions &options)
Definition: impex.hxx:161
ScDocument & rDoc
Definition: impex.hxx:51
bool IsOverflow() const
Definition: impex.hxx:154
sal_uInt32 nSizeLimit
Definition: impex.hxx:57
std::unique_ptr< ScAsciiOptions > pExtOptions
Definition: impex.hxx:77
bool bFormulas
Definition: impex.hxx:61
bool bSingle
Definition: impex.hxx:64
bool mbApi
Definition: impex.hxx:69
void SetSeparator(sal_Unicode c)
Definition: impex.hxx:133
bool IsOverflowRow() const
Definition: impex.hxx:151
ScImportExport(ScDocument &, const OUString &)
OUString maFilterOptions
Definition: impex.hxx:56
void SetImportBroadcast(bool b)
Definition: impex.hxx:159
void SetOverwriting(const bool bOverwriting)
Definition: impex.hxx:160
bool IsOverflowCell() const
Definition: impex.hxx:153
bool bIncludeFiltered
Definition: impex.hxx:62
sal_Unicode cSep
Definition: impex.hxx:59
OUString aNonConvertibleChars
Definition: impex.hxx:55
const OUString & GetNonConvertibleChars() const
Definition: impex.hxx:156
bool GetIncludeBOM() const
Definition: impex.hxx:163
bool bOverflowRow
Definition: impex.hxx:66
void SetDelimiter(sal_Unicode c)
Definition: impex.hxx:134
ScDocShell * pDocSh
Definition: impex.hxx:50
SCROW nMaxImportRow
Definition: impex.hxx:58
std::unique_ptr< ScDocument, o3tl::default_delete< ScDocument > > pUndoDoc
Definition: impex.hxx:52
ScImportStringStream(const OUString &rStr)
Definition: impex.cxx:2726
SOT_DLLPUBLIC bool IsFormatSupported(const DataFlavorExVector &rDataFlavorExVector, SotClipboardFormatId nId)
SotClipboardFormatId
SC_DLLPUBLIC OUString ReadCsvLine(SvStream &rStream, bool bEmbeddedLineBreak, OUString &rFieldSeparators, sal_Unicode cFieldQuote, sal_Unicode &rcDetectSep, sal_uInt32 nMaxSourceLines=0)
Read a CSV (comma separated values) data line using ReadUniOrByteStringLine().
Definition: impex.cxx:2738
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
These options control how multi-line cells are converted during export in certain lossy formats (such...
Definition: impex.hxx:38
ScExportTextOptions(NewlineConversion eNewlineConversion=ToSystem, sal_Unicode cSeparatorConvertTo=0, bool bAddQuotes=false)
Definition: impex.hxx:40
sal_Unicode mcSeparatorConvertTo
Definition: impex.hxx:44
NewlineConversion meNewlineConversion
Definition: impex.hxx:43
sal_uInt16 sal_Unicode
sal_Int32 SCROW
Definition: types.hxx:17