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 
29 class ScDocShell;
30 class ScDocument;
31 class 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;
56  OUString maFilterOptions;
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.
75 
76  std::unique_ptr<ScAsciiOptions> pExtOptions; // extended options
77 
78  bool StartPaste(); // Protect check, set up Undo
79  void EndPaste(bool bAutoRowHeight = true); // Undo/Redo actions, Repaint
80  bool Doc2Text( SvStream& );
81  bool Text2Doc( SvStream& );
82  bool Doc2Sylk( SvStream& );
83  bool Sylk2Doc( SvStream& );
84  bool Doc2HTML( SvStream&, const OUString& );
85  bool Doc2RTF( SvStream& );
86  bool Doc2Dif( SvStream& );
87  bool Dif2Doc( SvStream& );
88  bool ExtText2Doc( SvStream& ); // with pExtOptions
89  bool RTF2Doc( SvStream&, const OUString& rBaseURL );
90  bool HTML2Doc( SvStream&, const OUString& rBaseURL );
91 
92 public:
93  ScImportExport( ScDocument& ); // the whole document
94  ScImportExport( ScDocument&, const OUString& ); // Range/cell input
96  ScImportExport( ScDocument&, const ScRange& );
97  ~ScImportExport() COVERITY_NOEXCEPT_FALSE;
98 
99  void SetExtOptions( const ScAsciiOptions& rOpt );
100  void SetFilterOptions( const OUString& rFilterOptions );
101  bool IsRef() const { return !bAll; }
102 
103  const ScRange& GetRange() const { return aRange; }
104 
105  static void EmbeddedNullTreatment( OUString & rStr );
106 
107  static bool IsFormatSupported( SotClipboardFormatId nFormat );
108  static const sal_Unicode* ScanNextFieldFromString( const sal_Unicode* p,
109  OUString& rField, sal_Unicode cStr, const sal_Unicode* pSeps,
110  bool bMergeSeps, bool& rbIsQuoted, bool& rbOverflowCell, bool bRemoveSpace );
111  static void WriteUnicodeOrByteString( SvStream& rStrm, const OUString& rString, bool bZero = false );
112  static void WriteUnicodeOrByteEndl( SvStream& rStrm );
113 
122  static sal_Int32 CountVisualWidth(const OUString& rStr, sal_Int32& nIdx, sal_Int32 nMaxWidth);
123 
127  static sal_Int32 CountVisualWidth(const OUString& rStr);
128 
130  static void SetNoEndianSwap( SvStream& rStrm );
131 
132  void SetSeparator( sal_Unicode c ) { cSep = c; }
133  void SetDelimiter( sal_Unicode c ) { cStr = c; }
134  void SetFormulas( bool b ) { bFormulas = b; }
135  void SetIncludeFiltered( bool b ) { bIncludeFiltered = b; }
136 
137  void SetStreamPath( const OUString& rPath ) { aStreamPath = rPath; }
138 
139  bool ImportString( const OUString&, SotClipboardFormatId );
140  bool ExportString( OUString&, SotClipboardFormatId );
141  bool ExportByteString( OString&, rtl_TextEncoding, SotClipboardFormatId );
142 
143  bool ImportStream( SvStream&, const OUString& rBaseURL, SotClipboardFormatId );
144  bool ExportStream( SvStream&, const OUString& rBaseURL, SotClipboardFormatId );
145 
146  bool ExportData( const OUString& rMimeType,
147  css::uno::Any & rValue );
148 
149  // after import
150  bool IsOverflowRow() const { return bOverflowRow; }
151  bool IsOverflowCol() const { return bOverflowCol; }
152  bool IsOverflowCell() const { return bOverflowCell; }
153  bool IsOverflow() const { return bOverflowRow || bOverflowCol || bOverflowCell; }
154 
155  const OUString& GetNonConvertibleChars() const { return aNonConvertibleChars; }
156 
157  void SetApi( bool bApi ) { mbApi = bApi; }
158  void SetImportBroadcast( bool b ) { mbImportBroadcast = b; }
159  void SetOverwriting( const bool bOverwriting ) { mbOverwriting = bOverwriting; }
160  void SetExportTextOptions( const ScExportTextOptions& options ) { mExportTextOptions = options; }
161 };
162 
163 // Helper class for importing clipboard strings as streams.
165 {
166 public:
167  ScImportStringStream(const OUString& rStr);
168 };
169 
237 SC_DLLPUBLIC OUString ReadCsvLine( SvStream &rStream, bool bEmbeddedLineBreak,
238  OUString& rFieldSeparators, sal_Unicode cFieldQuote, sal_Unicode& rcDetectSep,
239  sal_uInt32 nMaxSourceLines = 0 );
240 
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool mbOverwriting
Definition: impex.hxx:71
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:2676
void SetApi(bool bApi)
Definition: impex.hxx:157
These options control how multi-line cells are converted during export in certain lossy formats (such...
Definition: impex.hxx:37
sal_Unicode cSep
Definition: impex.hxx:59
bool bIncludeFiltered
Definition: impex.hxx:62
bool bUndo
Definition: impex.hxx:65
bool bSingle
Definition: impex.hxx:64
std::unique_ptr< ScAsciiOptions > pExtOptions
Definition: impex.hxx:76
sal_uInt16 sal_Unicode
std::unique_ptr< ScDocument, o3tl::default_delete< ScDocument > > pUndoDoc
Definition: impex.hxx:52
NewlineConversion meNewlineConversion
Definition: impex.hxx:43
bool IsOverflow() const
Definition: impex.hxx:153
const ScRange & GetRange() const
Definition: impex.hxx:103
ScImportStringStream(const OUString &rStr)
Definition: impex.cxx:2664
OUString aStreamPath
Definition: impex.hxx:54
bool IsOverflowCol() const
Definition: impex.hxx:151
sal_uInt32 nSizeLimit
Definition: impex.hxx:57
OUString aNonConvertibleChars
Definition: impex.hxx:55
SotClipboardFormatId
ScDocShell * pDocSh
Definition: impex.hxx:50
OUString maFilterOptions
Definition: impex.hxx:56
bool bFormulas
Definition: impex.hxx:61
void SetFormulas(bool b)
Definition: impex.hxx:134
void SetOverwriting(const bool bOverwriting)
Definition: impex.hxx:159
sal_Unicode mcSeparatorConvertTo
Definition: impex.hxx:44
bool mbImportBroadcast
Definition: impex.hxx:70
bool mbApi
Definition: impex.hxx:69
ScExportTextOptions(NewlineConversion eNewlineConversion=ToSystem, sal_Unicode cSeparatorConvertTo=0, bool bAddQuotes=false)
Definition: impex.hxx:40
ScRange aRange
Definition: impex.hxx:53
ScDocument & rDoc
Definition: impex.hxx:51
sal_Int32 SCROW
Definition: types.hxx:17
void SetImportBroadcast(bool b)
Definition: impex.hxx:158
bool bOverflowCell
Definition: impex.hxx:68
const OUString & GetNonConvertibleChars() const
Definition: impex.hxx:155
bool IsOverflowRow() const
Definition: impex.hxx:150
sal_Unicode cStr
Definition: impex.hxx:60
bool IsOverflowCell() const
Definition: impex.hxx:152
void SetStreamPath(const OUString &rPath)
Definition: impex.hxx:137
SOT_DLLPUBLIC bool IsFormatSupported(const DataFlavorExVector &rDataFlavorExVector, SotClipboardFormatId nId)
bool bOverflowCol
Definition: impex.hxx:67
ScExportTextOptions mExportTextOptions
Definition: impex.hxx:74
void SetExportTextOptions(const ScExportTextOptions &options)
Definition: impex.hxx:160
void SetIncludeFiltered(bool b)
Definition: impex.hxx:135
void SetDelimiter(sal_Unicode c)
Definition: impex.hxx:133
SCROW nMaxImportRow
Definition: impex.hxx:58
bool bOverflowRow
Definition: impex.hxx:66
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
void SetSeparator(sal_Unicode c)
Definition: impex.hxx:132