Line data Source code
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 OOX_XLS_WORKBOOKHELPER_HXX
21 : #define OOX_XLS_WORKBOOKHELPER_HXX
22 :
23 : #include <boost/shared_ptr.hpp>
24 : #include <rtl/ref.hxx>
25 : #include "oox/helper/storagebase.hxx"
26 : #include "biffhelper.hxx"
27 : #include "rangenam.hxx"
28 :
29 : namespace com { namespace sun { namespace star {
30 : namespace container { class XNameAccess; }
31 : namespace container { class XNameContainer; }
32 : namespace lang { class XMultiServiceFactory; }
33 : namespace sheet { class XDatabaseRange; }
34 : namespace sheet { class XNamedRange; }
35 : namespace sheet { class XSpreadsheet; }
36 : namespace sheet { class XSpreadsheetDocument; }
37 : namespace sheet { struct FormulaToken; }
38 : namespace style { class XStyle; }
39 : namespace table { struct CellAddress; }
40 : namespace table { struct CellRangeAddress; }
41 : namespace table { class XCell; }
42 : namespace table { class XCellRange; }
43 : } } }
44 :
45 : namespace oox {
46 : class AttributeList;
47 : class SegmentProgressBar;
48 : class ISegmentProgressBar;
49 : }
50 :
51 : namespace oox { namespace core {
52 : class FilterBase;
53 : class FragmentHandler;
54 : class XmlFilterBase;
55 : } }
56 :
57 : class ScDocument;
58 : class ScEditEngineDefaulter;
59 :
60 : namespace oox {
61 : namespace xls {
62 :
63 : class ExcelFilter;
64 :
65 : // ============================================================================
66 :
67 : /** An enumeration for all supported spreadsheet filter types. */
68 : enum FilterType
69 : {
70 : FILTER_OOXML, /// MS Excel OOXML (Office Open XML) or BIFF12.
71 : FILTER_BIFF, /// MS Excel BIFF2-BIFF8 (Binary Interchange File Format).
72 : FILTER_UNKNOWN /// Unknown filter type.
73 : };
74 :
75 : // ============================================================================
76 :
77 : /** Functor for case-insensitive string comparison, usable in maps etc. */
78 : struct IgnoreCaseCompare
79 : {
80 : bool operator()( const OUString& rName1, const OUString& rName2 ) const;
81 : };
82 :
83 : // ============================================================================
84 :
85 : class AddressConverter;
86 : class BiffCodecHelper;
87 : class ConnectionsBuffer;
88 : class DefinedNamesBuffer;
89 : class ExcelChartConverter;
90 : class ExternalLinkBuffer;
91 : class FormulaParser;
92 : class PageSettingsConverter;
93 : class PivotCacheBuffer;
94 : class PivotTableBuffer;
95 : class ScenarioBuffer;
96 : class SharedStringsBuffer;
97 : class StylesBuffer;
98 : class TableBuffer;
99 : class ThemeBuffer;
100 : class UnitConverter;
101 : class ViewSettings;
102 : class WorkbookSettings;
103 : class WorksheetBuffer;
104 : class FormulaBuffer;
105 :
106 : class WorkbookGlobals;
107 : typedef ::boost::shared_ptr< WorkbookGlobals > WorkbookGlobalsRef;
108 :
109 : /** Helper class to provice access to global workbook data.
110 :
111 : All classes derived from this helper class will have access to a singleton
112 : object of type WorkbookGlobals containing global workbook settings,
113 : buffers, converters, etc. Nearly all classes in this filter implementation
114 : are derived directly or indirectly from this class.
115 :
116 : This class contains just a simple reference to the WorkbookGlobals object
117 : to prevent circular references, as the WorkbookGlobals object contains a
118 : lot of objects derived from this class.
119 : */
120 5696 : class WorkbookHelper
121 : {
122 : public:
123 541 : inline /*implicit*/ WorkbookHelper( WorkbookGlobals& rBookGlob ) : mrBookGlob( rBookGlob ) {}
124 : virtual ~WorkbookHelper();
125 :
126 : static WorkbookGlobalsRef constructGlobals( ExcelFilter& rFilter );
127 :
128 : // filter -----------------------------------------------------------------
129 :
130 : /** Returns the base filter object (base class of all filters). */
131 : ::oox::core::FilterBase& getBaseFilter() const;
132 : /** Returns the file type of the current filter. */
133 : FilterType getFilterType() const;
134 : /** Returns the filter progress bar. */
135 : SegmentProgressBar& getProgressBar() const;
136 : /** Returns true, if the file is a multi-sheet document, or false if single-sheet. */
137 : bool isWorkbookFile() const;
138 : /** Returns the index of the current Calc sheet, if filter currently processes a sheet. */
139 : sal_Int16 getCurrentSheetIndex() const;
140 :
141 : /** Sets the VBA project storage used to import VBA source code and forms. */
142 : void setVbaProjectStorage( const StorageRef& rxVbaPrjStrg );
143 : /** Sets the index of the current Calc sheet, if filter currently processes a sheet. */
144 : void setCurrentSheetIndex( sal_Int16 nSheet );
145 : /** Final conversion after importing the workbook. */
146 : void finalizeWorkbookImport();
147 :
148 : // document model ---------------------------------------------------------
149 : ScDocument& getScDocument() const;
150 : ScEditEngineDefaulter& getEditEngine() const;
151 : /** Returns a reference to the source/target spreadsheet document model. */
152 : ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheetDocument >
153 : getDocument() const;
154 :
155 : /** Returns a reference to the specified spreadsheet in the document model. */
156 : ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheet >
157 : getSheetFromDoc( sal_Int16 nSheet ) const;
158 : /** Returns a reference to the specified spreadsheet in the document model. */
159 : ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheet >
160 : getSheetFromDoc( const OUString& rSheet ) const;
161 :
162 : /** Returns the XCellRange interface for the passed cell range address. */
163 : ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange >
164 : getCellRangeFromDoc(
165 : const ::com::sun::star::table::CellRangeAddress& rRange ) const;
166 :
167 : /** Returns the cell or page styles container from the Calc document. */
168 : ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >
169 : getStyleFamily( bool bPageStyles ) const;
170 : /** Returns the specified cell or page style from the Calc document. */
171 : ::com::sun::star::uno::Reference< ::com::sun::star::style::XStyle >
172 : getStyleObject( const OUString& rStyleName, bool bPageStyle ) const;
173 :
174 : /** Creates and returns a defined name on-the-fly in the Calc document.
175 : The name will not be buffered in the global defined names buffer.
176 : @param orName (in/out-parameter) Returns the resulting used name. */
177 : ScRangeData* createNamedRangeObject(
178 : OUString& orName,
179 : const ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaToken>& rTokens,
180 : sal_Int32 nIndex,
181 : sal_Int32 nNameFlags = 0 ) const;
182 :
183 : /** Creates and returns a defined name on-the-fly in the sheet.
184 : The name will not be buffered in the global defined names buffer.
185 : @param orName (in/out-parameter) Returns the resulting used name. */
186 : ScRangeData* createLocalNamedRangeObject(
187 : OUString& orName,
188 : const ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaToken>& rTokens,
189 : sal_Int32 nIndex,
190 : sal_Int32 nNameFlags = 0, sal_Int32 nTab = -1 ) const;
191 :
192 : /** Creates and returns a database range on-the-fly in the Calc document.
193 : The range will not be buffered in the global table buffer.
194 : @param orName (in/out-parameter) Returns the resulting used name. */
195 : ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDatabaseRange >
196 : createDatabaseRangeObject(
197 : OUString& orName,
198 : const ::com::sun::star::table::CellRangeAddress& rRangeAddr ) const;
199 :
200 : /** Creates and returns an unnamed database range on-the-fly in the Calc document.
201 : The range will not be buffered in the global table buffer. */
202 : ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDatabaseRange >
203 : createUnnamedDatabaseRangeObject(
204 : const ::com::sun::star::table::CellRangeAddress& rRangeAddr ) const;
205 :
206 : /** Creates and returns a com.sun.star.style.Style object for cells or pages. */
207 : ::com::sun::star::uno::Reference< ::com::sun::star::style::XStyle >
208 : createStyleObject(
209 : OUString& orStyleName,
210 : bool bPageStyle ) const;
211 :
212 : // buffers ----------------------------------------------------------------
213 :
214 : FormulaBuffer& getFormulaBuffer() const;
215 : /** Returns the global workbook settings object. */
216 : WorkbookSettings& getWorkbookSettings() const;
217 : /** Returns the workbook and sheet view settings object. */
218 : ViewSettings& getViewSettings() const;
219 : /** Returns the worksheet buffer containing sheet names and properties. */
220 : WorksheetBuffer& getWorksheets() const;
221 : /** Returns the office theme object read from the theme substorage. */
222 : ThemeBuffer& getTheme() const;
223 : /** Returns all cell formatting objects read from the styles substream. */
224 : StylesBuffer& getStyles() const;
225 : /** Returns the shared strings read from the shared strings substream. */
226 : SharedStringsBuffer& getSharedStrings() const;
227 : /** Returns the external links read from the external links substream. */
228 : ExternalLinkBuffer& getExternalLinks() const;
229 : /** Returns the defined names read from the workbook globals. */
230 : DefinedNamesBuffer& getDefinedNames() const;
231 : /** Returns the tables collection (equivalent to Calc's database ranges). */
232 : TableBuffer& getTables() const;
233 : /** Returns the scenarios collection. */
234 : ScenarioBuffer& getScenarios() const;
235 : /** Returns the collection of external data connections. */
236 : ConnectionsBuffer& getConnections() const;
237 : /** Returns the collection of pivot caches. */
238 : PivotCacheBuffer& getPivotCaches() const;
239 : /** Returns the collection of pivot tables. */
240 : PivotTableBuffer& getPivotTables() const;
241 :
242 : // converters -------------------------------------------------------------
243 :
244 : /** Returns the import formula parser (import filter only!). */
245 : FormulaParser& getFormulaParser() const;
246 : /** Returns the measurement unit converter. */
247 : UnitConverter& getUnitConverter() const;
248 : /** Returns the converter for string to cell address/range conversion. */
249 : AddressConverter& getAddressConverter() const;
250 : /** Returns the chart object converter. */
251 : ExcelChartConverter* getChartConverter() const;
252 : /** Returns the page and print settings converter. */
253 : PageSettingsConverter& getPageSettingsConverter() const;
254 :
255 : // OOXML/BIFF12 specific (MUST NOT be called in BIFF filter) --------------
256 :
257 : /** Returns the base OOXML/BIFF12 filter object.
258 : Must not be called, if current filter is not the OOXML/BIFF12 filter. */
259 : ::oox::core::XmlFilterBase& getOoxFilter() const;
260 :
261 : /** Imports a fragment using the passed fragment handler, which contains
262 : the full path to the fragment stream. */
263 : bool importOoxFragment( const ::rtl::Reference< ::oox::core::FragmentHandler >& rxHandler );
264 :
265 : // BIFF2-BIFF8 specific (MUST NOT be called in OOXML/BIFF12 filter) -------
266 :
267 : /** Returns the BIFF type in binary filter. */
268 : BiffType getBiff() const;
269 :
270 : /** Returns the text encoding used to import/export byte strings. */
271 : rtl_TextEncoding getTextEncoding() const;
272 :
273 : /** Returns the codec helper that stores the encoder/decoder object. */
274 : BiffCodecHelper& getCodecHelper() const;
275 :
276 : private:
277 : WorkbookGlobals& mrBookGlob;
278 : };
279 :
280 : // ============================================================================
281 :
282 : } // namespace xls
283 : } // namespace oox
284 :
285 : #endif
286 :
287 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|