1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
23 #include <oox/helper/refvector.hxx>
24 #include "workbookhelper.hxx"
25 #include <document.hxx>
26 #include <com/sun/star/xml/sax/XFastAttributeList.hpp>
28 namespace oox
{ class AttributeList
; }
29 namespace oox
{ class SequenceInputStream
; }
33 const sal_Int32 BIFF12_CONNECTION_UNKNOWN
= 0;
34 const sal_Int32 BIFF12_CONNECTION_ODBC
= 1;
35 const sal_Int32 BIFF12_CONNECTION_DAO
= 2;
36 const sal_Int32 BIFF12_CONNECTION_FILE
= 3;
37 const sal_Int32 BIFF12_CONNECTION_HTML
= 4;
38 const sal_Int32 BIFF12_CONNECTION_OLEDB
= 5;
39 const sal_Int32 BIFF12_CONNECTION_TEXT
= 6;
40 const sal_Int32 BIFF12_CONNECTION_ADO
= 7;
41 const sal_Int32 BIFF12_CONNECTION_DSP
= 8;
44 TODO: update import&export of Microsoft Excel Binary (XLSB) File Format (option in Excel 2007 and later)
46 XLSB is not an international standard. It is a proprietary Microsoft format for spreadsheets
47 that has been available as a full-fidelity alternative to the default XLSX format since Excel 2007.
48 It is intended for users who need to load and save large data files as fast as possible.
50 https://www.loc.gov/preservation/digital/formats/fdd/fdd000512.shtml
53 /** Special properties for data connections representing web queries. */
57 typedef ::std::vector
< css::uno::Any
> TablesVector
;
58 TablesVector maTables
; /// Names or indexes of the web query tables.
59 sal_Int32 mnCount
; /// Number of tables to pull data from when refreshing from a web query.
62 OUString maUrl
; /// Source URL to refresh the data.
63 OUString maPostMethod
; /// POST method to query data.
64 OUString maEditPage
; /// Web page showing query data (for XML queries).
65 sal_Int32 mnHtmlFormat
; /// Plain text, rich text, or HTML.
66 bool mbXml
; /// True = XML query, false = HTML query.
67 bool mbSourceData
; /// True = import XML source data referred by HTML table.
68 bool mbParsePre
; /// True = parse preformatted sections (<pre> tag).
69 bool mbConsecutive
; /// True = join consecutive delimiters.
70 bool mbFirstRow
; /// True = use column widths of first row for entire <pre> tag.
71 bool mbXl97Created
; /// True = web query created with Excel 97.
72 bool mbTextDates
; /// True = read date values as text, false = parse dates.
73 bool mbXl2000Refreshed
; /// True = refreshed with Excel 2000 or newer.
74 bool mbHtmlTables
; /// True = HTML tables, false = entire document.
76 explicit WebPrModel();
79 /** Special properties for <textPr> (Text Import Settings) and its child elements */
82 css::uno::Sequence
<css::uno::Any
> maTextPrSequenceAny
; // <textPr> attributes.
83 css::uno::Sequence
<css::uno::Any
> maTextFieldsSequenceAny
; // <textFields> attributes.
84 std::vector
<css::uno::Sequence
<css::uno::Any
>>
85 vTextField
; // Field settings for text import, <textField>.
88 /** Special properties for <parameters> (Query Parameters) and its child element. */
89 struct ParametersModel
91 // <parameters> has only a single attribute.
92 sal_Int32 mnCount
; // The number of parameters used.
93 std::vector
<css::uno::Sequence
<css::uno::Any
>> vParameter
; // holds <parameter> attributes.
96 /** Special properties for <extLst> (Future Feature Data Storage Area) and its child elements. */
97 struct ExtensionListModel
99 // <extLst> has no attribute.
100 // <ext> has only one attribute:
101 // - uri (A token to identify version and application information for the particular extension)
102 std::vector
<OUString
> vExtension
; // holds uri (URI) attribute of <ext> (Extension) element.
105 /** Common properties of an external data connection. */
106 struct ConnectionModel
108 typedef ::std::unique_ptr
< WebPrModel
> WebPrModelPtr
;
109 WebPrModelPtr mxWebPr
; /// Special settings for web queries.
111 std::unique_ptr
<TextPrModel
> mxTextPr
; /// Text import settings.
112 std::unique_ptr
<ParametersModel
> mxParameters
; /// Query Parameters settings.
113 std::unique_ptr
<ExtensionListModel
> mxExtensionList
; /// Extension List settings.
115 css::uno::Sequence
<css::uno::Any
> maDbPrSequenceAny
;
116 css::uno::Sequence
<css::uno::Any
> maOlapPrSequenceAny
;
118 OUString maName
; /// Unique name of this connection.
119 OUString maDescription
; /// User description of this connection.
120 OUString maSourceFile
; /// URL of a source data file.
121 OUString maSourceConnFile
; /// URL of a source connection file. Office Data Connection (ODC) file to share data between Excel users
122 OUString maSsoId
; /// Single sign-on identifier.
123 OUString maXr16Uid
; /// Value of xr16:uid attribute.
124 sal_Int32 mnId
; /// Unique connection identifier.
125 sal_Int32 mnType
; /// Data source type.
126 sal_Int32 mnReconnectMethod
; /// Reconnection method.
127 sal_Int32 mnCredentials
; /// Credentials method.
128 sal_Int32 mnInterval
; /// Refresh interval in minutes.
129 sal_Int16 mnRefreshedVersion
; /// Refreshed version.
130 sal_Int16 mnMinRefreshableVersion
; /// minRefreshableVersion (type="xsd:unsignedByte")
131 bool mbKeepAlive
; /// True = keep connection open after import.
132 bool mbNew
; /// True = new connection, never updated.
133 bool mbDeleted
; /// True = connection has been deleted.
134 bool mbOnlyUseConnFile
; /// True = use maSourceConnFile, ignore mnReconnectMethod.
135 bool mbBackground
; /// True = background refresh enabled.
136 bool mbRefreshOnLoad
; /// True = refresh connection on import.
137 bool mbSaveData
; /// True = save cached data with connection.
138 bool mbSavePassword
; /// True = save password in connection string.
140 explicit ConnectionModel();
142 WebPrModel
& createWebPr();
143 TextPrModel
& createTextPr();
144 ParametersModel
& createParameters();
145 ExtensionListModel
& createExtensionList();
148 /** An external data connection (database, web query, etc.). */
149 class Connection final
: public WorkbookHelper
152 explicit Connection( const WorkbookHelper
& rHelper
);
154 /** Imports connection settings from the connection element. */
155 void importConnection( const AttributeList
& rAttribs
);
156 /** Imports web query settings from the webPr element. */
157 void importWebPr( const AttributeList
& rAttribs
);
158 /** Imports web query table settings from the tables element. */
159 void importTables(const AttributeList
& rAttribs
);
160 /** Imports a web query table identifier from the m, s, or x element. */
161 void importTable( const AttributeList
& rAttribs
, sal_Int32 nElement
);
162 /** Imports database settings from the dbPr element. */
163 void importDbPr(const AttributeList
& rAttribs
);
164 /** Imports OLAP settings from the olapPr element. */
165 void importOlapPr(const AttributeList
& rAttribs
);
166 /** Imports text settings from the textPr element. */
167 void importTextPr(const AttributeList
& rAttribs
);
168 /** Set of fields to retrieve from a text file - represents textFields element. */
169 void importTextFields(const AttributeList
& rAttribs
);
170 /** Field settings for text import from the textField element. */
171 void importTextField(const AttributeList
& rAttribs
);
172 /** Imports collection of parameters for an ODBC or web query from the parameters element. */
173 void importParameters(const AttributeList
& rAttribs
);
174 /** Imports properties about any parameters used with external data connections from the parameter element. */
175 void importParameter(const AttributeList
& rAttribs
);
176 /** This element provides a convention for extending spreadsheetML in predefined locations, from the extLst element. */
177 void importExtensionList();
178 /** Imports extensions to the standard SpreadsheetML feature set, from the ext element. */
179 void importExtension(const AttributeList
& rAttribs
);
181 /** Imports connection settings from the CONNECTION record. */
182 void importConnection( SequenceInputStream
& rStrm
);
183 /** Imports web query settings from the WEBPR record. */
184 void importWebPr( SequenceInputStream
& rStrm
);
185 /** Imports web query table settings from the WEBPRTABLES record. */
186 void importWebPrTables( SequenceInputStream
& rStrm
);
187 /** Imports a web query table identifier from the PCITEM_MISSING, PCITEM_STRING, or PCITEM_INDEX record. */
188 void importWebPrTable( SequenceInputStream
& rStrm
, sal_Int32 nRecId
);
190 static css::uno::Sequence
<css::uno::Any
>
191 getSequenceOfAny(css::uno::Reference
<css::xml::sax::XFastAttributeList
>& xFastAttributeList
);
192 /** Returns the unique connection identifier. */
193 sal_Int32
getConnectionId() const { return maModel
.mnId
; }
194 /** Returns the source data type of the connection. */
195 sal_Int32
getConnectionType() const { return maModel
.mnType
; }
196 /** Returns read-only access to the connection model data. */
197 const ConnectionModel
& getModel() const { return maModel
; }
199 const css::uno::Sequence
<css::uno::Any
> & getDbPrSequenceAny() const
201 return maModel
.maDbPrSequenceAny
;
203 const css::uno::Sequence
<css::uno::Any
> & getOlapPrSequenceAny() const
205 return maModel
.maOlapPrSequenceAny
;
209 ConnectionModel maModel
;
212 typedef std::shared_ptr
< Connection
> ConnectionRef
;
214 class ConnectionsBuffer final
: public WorkbookHelper
217 explicit ConnectionsBuffer( const WorkbookHelper
& rHelper
);
219 /** Creates a new empty connection. */
220 Connection
& createConnection();
222 /** Maps all connections by their identifier. */
223 void finalizeImport();
225 /** Returns a data connection by its unique identifier. */
226 ConnectionRef
getConnection( sal_Int32 nConnId
) const;
229 /** Inserts the passed connection into the map according to its identifier. */
230 void insertConnectionToMap( const ConnectionRef
& rxConnection
);
233 typedef RefVector
< Connection
> ConnectionVector
;
234 typedef RefMap
< sal_Int32
, Connection
> ConnectionMap
;
236 ConnectionVector maConnections
;
237 ConnectionMap maConnectionsById
;
238 sal_Int32 mnUnusedId
;
241 } // namespace oox::xls
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */