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