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