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 #ifndef INCLUDED_SC_SOURCE_UI_INC_IMPEX_HXX
21 #define INCLUDED_SC_SOURCE_UI_INC_IMPEX_HXX
22 
23 #include <o3tl/deleter.hxx>
24 #include <sot/formats.hxx>
25 #include <address.hxx>
26 #include <tools/stream.hxx>
27 
28 class ScDocShell;
29 class ScDocument;
30 class ScAsciiOptions;
31 
37 {
39  ScExportTextOptions( NewlineConversion eNewlineConversion = ToSystem, sal_Unicode cSeparatorConvertTo = 0, bool bAddQuotes = false ) :
40  meNewlineConversion( eNewlineConversion ), mcSeparatorConvertTo( cSeparatorConvertTo ), mbAddQuotes( bAddQuotes ) {}
41 
43  sal_Unicode mcSeparatorConvertTo; // Convert separator to this character
45 };
46 
48 {
51  std::unique_ptr<ScDocument, o3tl::default_delete<ScDocument>> pUndoDoc;
53  OUString aStreamPath;
55  OUString maFilterOptions;
56  sal_uInt32 nSizeLimit;
58  sal_Unicode cSep; // Separator
59  sal_Unicode cStr; // String Delimiter
60  bool bFormulas; // Formula in Text?
61  bool bIncludeFiltered; // include filtered rows? (default true)
62  bool bAll; // no selection
63  bool bSingle; // Single selection
64  bool bUndo; // with Undo?
65  bool bOverflowRow; // too many rows
66  bool bOverflowCol; // too many columns
67  bool bOverflowCell; // too much data for a cell
68  bool mbApi;
69  bool mbImportBroadcast; // whether or not to broadcast after data import.
70  bool mbOverwriting; // Whether we could be overwriting existing values (paste).
71  // In this case we cannot use the insert optimization, but we
72  // do not need to broadcast after the import.
74 
75  std::unique_ptr<ScAsciiOptions> pExtOptions; // extended options
76 
77  bool StartPaste(); // Protect check, set up Undo
78  void EndPaste(bool bAutoRowHeight = true); // Undo/Redo actions, Repaint
79  bool Doc2Text( SvStream& );
80  bool Text2Doc( SvStream& );
81  bool Doc2Sylk( SvStream& );
82  bool Sylk2Doc( SvStream& );
83  bool Doc2HTML( SvStream&, const OUString& );
84  bool Doc2RTF( SvStream& );
85  bool Doc2Dif( SvStream& );
86  bool Dif2Doc( SvStream& );
87  bool ExtText2Doc( SvStream& ); // with pExtOptions
88  bool RTF2Doc( SvStream&, const OUString& rBaseURL );
89  bool HTML2Doc( SvStream&, const OUString& rBaseURL );
90 
91 public:
92  ScImportExport( ScDocument& ); // the whole document
93  ScImportExport( ScDocument&, const OUString& ); // Range/cell input
95  ScImportExport( ScDocument&, const ScRange& );
96  ~ScImportExport() COVERITY_NOEXCEPT_FALSE;
97 
98  void SetExtOptions( const ScAsciiOptions& rOpt );
99  void SetFilterOptions( const OUString& rFilterOptions );
100  bool IsRef() const { return !bAll; }
101 
102  const ScRange& GetRange() const { return aRange; }
103 
104  static void EmbeddedNullTreatment( OUString & rStr );
105 
106  static bool IsFormatSupported( SotClipboardFormatId nFormat );
107  static const sal_Unicode* ScanNextFieldFromString( const sal_Unicode* p,
108  OUString& rField, sal_Unicode cStr, const sal_Unicode* pSeps,
109  bool bMergeSeps, bool& rbIsQuoted, bool& rbOverflowCell, bool bRemoveSpace );
110  static void WriteUnicodeOrByteString( SvStream& rStrm, const OUString& rString, bool bZero = false );
111  static void WriteUnicodeOrByteEndl( SvStream& rStrm );
112 
121  static sal_Int32 CountVisualWidth(const OUString& rStr, sal_Int32& nIdx, sal_Int32 nMaxWidth);
122 
126  static sal_Int32 CountVisualWidth(const OUString& rStr);
127 
129  static void SetNoEndianSwap( SvStream& rStrm );
130 
131  void SetSeparator( sal_Unicode c ) { cSep = c; }
132  void SetDelimiter( sal_Unicode c ) { cStr = c; }
133  void SetFormulas( bool b ) { bFormulas = b; }
134  void SetIncludeFiltered( bool b ) { bIncludeFiltered = b; }
135 
136  void SetStreamPath( const OUString& rPath ) { aStreamPath = rPath; }
137 
138  bool ImportString( const OUString&, SotClipboardFormatId );
139  bool ExportString( OUString&, SotClipboardFormatId );
140  bool ExportByteString( OString&, rtl_TextEncoding, SotClipboardFormatId );
141 
142  bool ImportStream( SvStream&, const OUString& rBaseURL, SotClipboardFormatId );
143  bool ExportStream( SvStream&, const OUString& rBaseURL, SotClipboardFormatId );
144 
145  bool ExportData( const OUString& rMimeType,
146  css::uno::Any & rValue );
147 
148  // after import
149  bool IsOverflowRow() const { return bOverflowRow; }
150  bool IsOverflowCol() const { return bOverflowCol; }
151  bool IsOverflowCell() const { return bOverflowCell; }
152  bool IsOverflow() const { return bOverflowRow || bOverflowCol || bOverflowCell; }
153 
154  const OUString& GetNonConvertibleChars() const { return aNonConvertibleChars; }
155 
156  void SetApi( bool bApi ) { mbApi = bApi; }
157  void SetImportBroadcast( bool b ) { mbImportBroadcast = b; }
158  void SetOverwriting( const bool bOverwriting ) { mbOverwriting = bOverwriting; }
159  void SetExportTextOptions( const ScExportTextOptions& options ) { mExportTextOptions = options; }
160 };
161 
162 // Helper class for importing clipboard strings as streams.
164 {
165 public:
166  ScImportStringStream(const OUString& rStr);
167 };
168 
225 SC_DLLPUBLIC OUString ReadCsvLine( SvStream &rStream, bool bEmbeddedLineBreak,
226  OUString& rFieldSeparators, sal_Unicode cFieldQuote, sal_Unicode& rcDetectSep );
227 
228 #endif
229 
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool mbOverwriting
Definition: impex.hxx:70
void SetApi(bool bApi)
Definition: impex.hxx:156
These options control how multi-line cells are converted during export in certain lossy formats (such...
Definition: impex.hxx:36
sal_Unicode cSep
Definition: impex.hxx:58
SC_DLLPUBLIC OUString ReadCsvLine(SvStream &rStream, bool bEmbeddedLineBreak, OUString &rFieldSeparators, sal_Unicode cFieldQuote, sal_Unicode &rcDetectSep)
Read a CSV (comma separated values) data line using ReadUniOrByteStringLine().
Definition: impex.cxx:2453
bool bIncludeFiltered
Definition: impex.hxx:61
bool bUndo
Definition: impex.hxx:64
bool bSingle
Definition: impex.hxx:63
std::unique_ptr< ScAsciiOptions > pExtOptions
Definition: impex.hxx:75
sal_uInt16 sal_Unicode
std::unique_ptr< ScDocument, o3tl::default_delete< ScDocument > > pUndoDoc
Definition: impex.hxx:51
NewlineConversion meNewlineConversion
Definition: impex.hxx:42
bool IsOverflow() const
Definition: impex.hxx:152
const ScRange & GetRange() const
Definition: impex.hxx:102
ScImportStringStream(const OUString &rStr)
Definition: impex.cxx:2441
OUString aStreamPath
Definition: impex.hxx:53
bool IsOverflowCol() const
Definition: impex.hxx:150
sal_uInt32 nSizeLimit
Definition: impex.hxx:56
OUString aNonConvertibleChars
Definition: impex.hxx:54
SotClipboardFormatId
ScDocShell * pDocSh
Definition: impex.hxx:49
OUString maFilterOptions
Definition: impex.hxx:55
bool bFormulas
Definition: impex.hxx:60
void SetFormulas(bool b)
Definition: impex.hxx:133
void SetOverwriting(const bool bOverwriting)
Definition: impex.hxx:158
sal_Unicode mcSeparatorConvertTo
Definition: impex.hxx:43
bool mbImportBroadcast
Definition: impex.hxx:69
bool mbApi
Definition: impex.hxx:68
ScExportTextOptions(NewlineConversion eNewlineConversion=ToSystem, sal_Unicode cSeparatorConvertTo=0, bool bAddQuotes=false)
Definition: impex.hxx:39
ScRange aRange
Definition: impex.hxx:52
ScDocument & rDoc
Definition: impex.hxx:50
sal_Int32 SCROW
Definition: types.hxx:18
void SetImportBroadcast(bool b)
Definition: impex.hxx:157
bool bOverflowCell
Definition: impex.hxx:67
const OUString & GetNonConvertibleChars() const
Definition: impex.hxx:154
bool IsOverflowRow() const
Definition: impex.hxx:149
sal_Unicode cStr
Definition: impex.hxx:59
bool IsOverflowCell() const
Definition: impex.hxx:151
void SetStreamPath(const OUString &rPath)
Definition: impex.hxx:136
SOT_DLLPUBLIC bool IsFormatSupported(const DataFlavorExVector &rDataFlavorExVector, SotClipboardFormatId nId)
bool bOverflowCol
Definition: impex.hxx:66
ScExportTextOptions mExportTextOptions
Definition: impex.hxx:73
void SetExportTextOptions(const ScExportTextOptions &options)
Definition: impex.hxx:159
void SetIncludeFiltered(bool b)
Definition: impex.hxx:134
void SetDelimiter(sal_Unicode c)
Definition: impex.hxx:132
SCROW nMaxImportRow
Definition: impex.hxx:57
bool bOverflowRow
Definition: impex.hxx:65
#define SC_DLLPUBLIC
Definition: scdllapi.h:28
void SetSeparator(sal_Unicode c)
Definition: impex.hxx:131