xref: /trunk/main/oox/inc/oox/xls/workbookhelper.hxx (revision 102b8ff7)
1e3508121SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3e3508121SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4e3508121SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5e3508121SAndrew Rist  * distributed with this work for additional information
6e3508121SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7e3508121SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8e3508121SAndrew Rist  * "License"); you may not use this file except in compliance
9e3508121SAndrew Rist  * with the License.  You may obtain a copy of the License at
10e3508121SAndrew Rist  *
11e3508121SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12e3508121SAndrew Rist  *
13e3508121SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14e3508121SAndrew Rist  * software distributed under the License is distributed on an
15e3508121SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16e3508121SAndrew Rist  * KIND, either express or implied.  See the License for the
17e3508121SAndrew Rist  * specific language governing permissions and limitations
18e3508121SAndrew Rist  * under the License.
19e3508121SAndrew Rist  *
20e3508121SAndrew Rist  *************************************************************/
21e3508121SAndrew Rist 
22e3508121SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef OOX_XLS_WORKBOOKHELPER_HXX
25cdf0e10cSrcweir #define OOX_XLS_WORKBOOKHELPER_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <boost/shared_ptr.hpp>
28cdf0e10cSrcweir #include <rtl/ref.hxx>
29cdf0e10cSrcweir #include "oox/helper/storagebase.hxx"
30cdf0e10cSrcweir #include "oox/xls/biffhelper.hxx"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir namespace com { namespace sun { namespace star {
33cdf0e10cSrcweir     namespace container { class XNameAccess; }
34cdf0e10cSrcweir     namespace container { class XNameContainer; }
35cdf0e10cSrcweir     namespace lang { class XMultiServiceFactory; }
36cdf0e10cSrcweir     namespace sheet { class XDatabaseRange; }
37*102b8ff7SWang Lei     namespace sheet { class XNamedRange2; }
38cdf0e10cSrcweir     namespace sheet { class XSpreadsheet; }
39cdf0e10cSrcweir     namespace sheet { class XSpreadsheetDocument; }
40cdf0e10cSrcweir     namespace style { class XStyle; }
41cdf0e10cSrcweir     namespace table { struct CellAddress; }
42cdf0e10cSrcweir     namespace table { struct CellRangeAddress; }
43cdf0e10cSrcweir     namespace table { class XCell; }
44cdf0e10cSrcweir     namespace table { class XCellRange; }
45cdf0e10cSrcweir } } }
46cdf0e10cSrcweir 
47cdf0e10cSrcweir namespace oox {
48cdf0e10cSrcweir     class AttributeList;
49cdf0e10cSrcweir     class SegmentProgressBar;
50cdf0e10cSrcweir     class SequenceInputStream;
51cdf0e10cSrcweir }
52cdf0e10cSrcweir 
53cdf0e10cSrcweir namespace oox { namespace core {
54cdf0e10cSrcweir     class BinaryFilterBase;
55cdf0e10cSrcweir     class FilterBase;
56cdf0e10cSrcweir     class FragmentHandler;
57cdf0e10cSrcweir     class XmlFilterBase;
58cdf0e10cSrcweir } }
59cdf0e10cSrcweir 
60cdf0e10cSrcweir namespace oox { namespace drawingml {
61cdf0e10cSrcweir     class Theme;
62cdf0e10cSrcweir } }
63cdf0e10cSrcweir 
64cdf0e10cSrcweir namespace oox {
65cdf0e10cSrcweir namespace xls {
66cdf0e10cSrcweir 
67cdf0e10cSrcweir class ExcelFilter;
68cdf0e10cSrcweir class ExcelBiffFilter;
69cdf0e10cSrcweir 
70cdf0e10cSrcweir // ============================================================================
71cdf0e10cSrcweir 
72cdf0e10cSrcweir /** An enumeration for all supported spreadsheet filter types. */
73cdf0e10cSrcweir enum FilterType
74cdf0e10cSrcweir {
75cdf0e10cSrcweir     FILTER_OOXML,       /// MS Excel OOXML (Office Open XML) or BIFF12.
76cdf0e10cSrcweir     FILTER_BIFF,        /// MS Excel BIFF2-BIFF8 (Binary Interchange File Format).
77cdf0e10cSrcweir     FILTER_UNKNOWN      /// Unknown filter type.
78cdf0e10cSrcweir };
79cdf0e10cSrcweir 
80cdf0e10cSrcweir // ============================================================================
81cdf0e10cSrcweir 
82cdf0e10cSrcweir /** Functor for case-insensitive string comparison, usable in maps etc. */
83cdf0e10cSrcweir struct IgnoreCaseCompare
84cdf0e10cSrcweir {
85cdf0e10cSrcweir     bool operator()( const ::rtl::OUString& rName1, const ::rtl::OUString& rName2 ) const;
86cdf0e10cSrcweir };
87cdf0e10cSrcweir 
88cdf0e10cSrcweir // ============================================================================
89cdf0e10cSrcweir 
90cdf0e10cSrcweir class AddressConverter;
91cdf0e10cSrcweir class BiffCodecHelper;
92cdf0e10cSrcweir class ConnectionsBuffer;
93cdf0e10cSrcweir class DefinedNamesBuffer;
94cdf0e10cSrcweir class ExcelChartConverter;
95cdf0e10cSrcweir class ExternalLinkBuffer;
96cdf0e10cSrcweir class FormulaParser;
97cdf0e10cSrcweir class PageSettingsConverter;
98cdf0e10cSrcweir class PivotCacheBuffer;
99cdf0e10cSrcweir class PivotTableBuffer;
100cdf0e10cSrcweir class ScenarioBuffer;
101cdf0e10cSrcweir class SharedStringsBuffer;
102cdf0e10cSrcweir class StylesBuffer;
103cdf0e10cSrcweir class TableBuffer;
104cdf0e10cSrcweir class ThemeBuffer;
105cdf0e10cSrcweir class UnitConverter;
106cdf0e10cSrcweir class ViewSettings;
107cdf0e10cSrcweir class WorkbookSettings;
108cdf0e10cSrcweir class WorksheetBuffer;
109cdf0e10cSrcweir 
110cdf0e10cSrcweir class WorkbookGlobals;
111cdf0e10cSrcweir typedef ::boost::shared_ptr< WorkbookGlobals > WorkbookGlobalsRef;
112cdf0e10cSrcweir 
113cdf0e10cSrcweir /** Helper class to provice access to global workbook data.
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     All classes derived from this helper class will have access to a singleton
116cdf0e10cSrcweir     object of type WorkbookGlobals containing global workbook settings,
117cdf0e10cSrcweir     buffers, converters, etc. Nearly all classes in this filter implementation
118cdf0e10cSrcweir     are derived directly or indirectly from this class.
119cdf0e10cSrcweir 
120cdf0e10cSrcweir     This class contains just a simple reference to the WorkbookGlobals object
121cdf0e10cSrcweir     to prevent circular references, as the WorkbookGlobals object contains a
122cdf0e10cSrcweir     lot of objects derived from this class.
123cdf0e10cSrcweir  */
124cdf0e10cSrcweir class WorkbookHelper
125cdf0e10cSrcweir {
126cdf0e10cSrcweir public:
WorkbookHelper(WorkbookGlobals & rBookGlob)127cdf0e10cSrcweir     inline /*implicit*/ WorkbookHelper( WorkbookGlobals& rBookGlob ) : mrBookGlob( rBookGlob ) {}
128cdf0e10cSrcweir     virtual             ~WorkbookHelper();
129cdf0e10cSrcweir 
130cdf0e10cSrcweir     static WorkbookGlobalsRef constructGlobals( ExcelFilter& rFilter );
131cdf0e10cSrcweir     static WorkbookGlobalsRef constructGlobals( ExcelBiffFilter& rFilter, BiffType eBiff );
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     // filter -----------------------------------------------------------------
134cdf0e10cSrcweir 
135cdf0e10cSrcweir     /** Returns the base filter object (base class of all filters). */
136cdf0e10cSrcweir     ::oox::core::FilterBase& getBaseFilter() const;
137cdf0e10cSrcweir     /** Returns the file type of the current filter. */
138cdf0e10cSrcweir     FilterType          getFilterType() const;
139cdf0e10cSrcweir     /** Returns the filter progress bar. */
140cdf0e10cSrcweir     SegmentProgressBar& getProgressBar() const;
141cdf0e10cSrcweir     /** Returns true, if the file is a multi-sheet document, or false if single-sheet. */
142cdf0e10cSrcweir     bool                isWorkbookFile() const;
143cdf0e10cSrcweir     /** Returns the index of the current Calc sheet, if filter currently processes a sheet. */
144cdf0e10cSrcweir     sal_Int16           getCurrentSheetIndex() const;
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     /** Sets the VBA project storage used to import VBA source code and forms. */
147cdf0e10cSrcweir     void                setVbaProjectStorage( const StorageRef& rxVbaPrjStrg );
148cdf0e10cSrcweir     /** Sets the index of the current Calc sheet, if filter currently processes a sheet. */
149cdf0e10cSrcweir     void                setCurrentSheetIndex( sal_Int16 nSheet );
150cdf0e10cSrcweir     /** Final conversion after importing the workbook. */
151cdf0e10cSrcweir     void                finalizeWorkbookImport();
152cdf0e10cSrcweir 
153cdf0e10cSrcweir     // document model ---------------------------------------------------------
154cdf0e10cSrcweir 
155cdf0e10cSrcweir     /** Returns a reference to the source/target spreadsheet document model. */
156cdf0e10cSrcweir     ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheetDocument >
157cdf0e10cSrcweir                         getDocument() const;
158cdf0e10cSrcweir 
159cdf0e10cSrcweir     /** Returns a reference to the specified spreadsheet in the document model. */
160cdf0e10cSrcweir     ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheet >
161cdf0e10cSrcweir                         getSheetFromDoc( sal_Int16 nSheet ) const;
162cdf0e10cSrcweir     /** Returns a reference to the specified spreadsheet in the document model. */
163cdf0e10cSrcweir     ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheet >
164cdf0e10cSrcweir                         getSheetFromDoc( const ::rtl::OUString& rSheet ) const;
165cdf0e10cSrcweir 
166cdf0e10cSrcweir     /** Returns the XCell interface for the passed cell address. */
167cdf0e10cSrcweir     ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >
168cdf0e10cSrcweir                         getCellFromDoc(
169cdf0e10cSrcweir                             const ::com::sun::star::table::CellAddress& rAddress ) const;
170cdf0e10cSrcweir     /** Returns the XCellRange interface for the passed cell range address. */
171cdf0e10cSrcweir     ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange >
172cdf0e10cSrcweir                         getCellRangeFromDoc(
173cdf0e10cSrcweir                             const ::com::sun::star::table::CellRangeAddress& rRange ) const;
174cdf0e10cSrcweir 
175cdf0e10cSrcweir     /** Returns the cell or page styles container from the Calc document. */
176cdf0e10cSrcweir     ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >
177cdf0e10cSrcweir                         getStyleFamily( bool bPageStyles ) const;
178cdf0e10cSrcweir     /** Returns the specified cell or page style from the Calc document. */
179cdf0e10cSrcweir     ::com::sun::star::uno::Reference< ::com::sun::star::style::XStyle >
180cdf0e10cSrcweir                         getStyleObject( const ::rtl::OUString& rStyleName, bool bPageStyle ) const;
181cdf0e10cSrcweir 
182cdf0e10cSrcweir     /** Creates and returns a defined name on-the-fly in the Calc document.
183cdf0e10cSrcweir         The name will not be buffered in the global defined names buffer.
184cdf0e10cSrcweir         @param orName  (in/out-parameter) Returns the resulting used name. */
185*102b8ff7SWang Lei     ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XNamedRange2 >
186cdf0e10cSrcweir                         createNamedRangeObject(
187cdf0e10cSrcweir                             ::rtl::OUString& orName,
188dffa72deSWang Lei 							sal_Int32 nSheetId = -1, //Add scope for name range
189cdf0e10cSrcweir                             sal_Int32 nNameFlags = 0 ) const;
190cdf0e10cSrcweir 
191cdf0e10cSrcweir     /** Creates and returns a database range on-the-fly in the Calc document.
192cdf0e10cSrcweir         The range will not be buffered in the global table buffer.
193cdf0e10cSrcweir         @param orName  (in/out-parameter) Returns the resulting used name. */
194cdf0e10cSrcweir     ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDatabaseRange >
195cdf0e10cSrcweir                         createDatabaseRangeObject(
196cdf0e10cSrcweir                             ::rtl::OUString& orName,
197cdf0e10cSrcweir                             const ::com::sun::star::table::CellRangeAddress& rRangeAddr ) const;
198cdf0e10cSrcweir 
199cdf0e10cSrcweir     /** Creates and returns a com.sun.star.style.Style object for cells or pages. */
200cdf0e10cSrcweir     ::com::sun::star::uno::Reference< ::com::sun::star::style::XStyle >
201cdf0e10cSrcweir                         createStyleObject(
202cdf0e10cSrcweir                             ::rtl::OUString& orStyleName,
203cdf0e10cSrcweir                             bool bPageStyle ) const;
204cdf0e10cSrcweir 
205cdf0e10cSrcweir     // buffers ----------------------------------------------------------------
206cdf0e10cSrcweir 
207cdf0e10cSrcweir     /** Returns the global workbook settings object. */
208cdf0e10cSrcweir     WorkbookSettings&   getWorkbookSettings() const;
209cdf0e10cSrcweir     /** Returns the workbook and sheet view settings object. */
210cdf0e10cSrcweir     ViewSettings&       getViewSettings() const;
211cdf0e10cSrcweir     /** Returns the worksheet buffer containing sheet names and properties. */
212cdf0e10cSrcweir     WorksheetBuffer&    getWorksheets() const;
213cdf0e10cSrcweir     /** Returns the office theme object read from the theme substorage. */
214cdf0e10cSrcweir     ThemeBuffer&        getTheme() const;
215cdf0e10cSrcweir     /** Returns all cell formatting objects read from the styles substream. */
216cdf0e10cSrcweir     StylesBuffer&       getStyles() const;
217cdf0e10cSrcweir     /** Returns the shared strings read from the shared strings substream. */
218cdf0e10cSrcweir     SharedStringsBuffer& getSharedStrings() const;
219cdf0e10cSrcweir     /** Returns the external links read from the external links substream. */
220cdf0e10cSrcweir     ExternalLinkBuffer& getExternalLinks() const;
221cdf0e10cSrcweir     /** Returns the defined names read from the workbook globals. */
222cdf0e10cSrcweir     DefinedNamesBuffer& getDefinedNames() const;
223cdf0e10cSrcweir     /** Returns the tables collection (equivalent to Calc's database ranges). */
224cdf0e10cSrcweir     TableBuffer&        getTables() const;
225cdf0e10cSrcweir     /** Returns the scenarios collection. */
226cdf0e10cSrcweir     ScenarioBuffer&     getScenarios() const;
227cdf0e10cSrcweir     /** Returns the collection of external data connections. */
228cdf0e10cSrcweir     ConnectionsBuffer&  getConnections() const;
229cdf0e10cSrcweir     /** Returns the collection of pivot caches. */
230cdf0e10cSrcweir     PivotCacheBuffer&   getPivotCaches() const;
231cdf0e10cSrcweir     /** Returns the collection of pivot tables. */
232cdf0e10cSrcweir     PivotTableBuffer&   getPivotTables() const;
233cdf0e10cSrcweir 
234cdf0e10cSrcweir     // converters -------------------------------------------------------------
235cdf0e10cSrcweir 
236cdf0e10cSrcweir     /** Returns the import formula parser (import filter only!). */
237cdf0e10cSrcweir     FormulaParser&      getFormulaParser() const;
238cdf0e10cSrcweir     /** Returns the measurement unit converter. */
239cdf0e10cSrcweir     UnitConverter&      getUnitConverter() const;
240cdf0e10cSrcweir     /** Returns the converter for string to cell address/range conversion. */
241cdf0e10cSrcweir     AddressConverter&   getAddressConverter() const;
242cdf0e10cSrcweir     /** Returns the chart object converter. */
243cdf0e10cSrcweir     ExcelChartConverter& getChartConverter() const;
244cdf0e10cSrcweir     /** Returns the page and print settings converter. */
245cdf0e10cSrcweir     PageSettingsConverter& getPageSettingsConverter() const;
246cdf0e10cSrcweir 
247cdf0e10cSrcweir     // OOXML/BIFF12 specific (MUST NOT be called in BIFF filter) --------------
248cdf0e10cSrcweir 
249cdf0e10cSrcweir     /** Returns the base OOXML/BIFF12 filter object.
250cdf0e10cSrcweir         Must not be called, if current filter is not the OOXML/BIFF12 filter. */
251cdf0e10cSrcweir     ::oox::core::XmlFilterBase& getOoxFilter() const;
252cdf0e10cSrcweir 
253cdf0e10cSrcweir     /** Imports a fragment using the passed fragment handler, which contains
254cdf0e10cSrcweir         the full path to the fragment stream. */
255cdf0e10cSrcweir     bool                importOoxFragment( const ::rtl::Reference< ::oox::core::FragmentHandler >& rxHandler );
256cdf0e10cSrcweir 
257cdf0e10cSrcweir     // BIFF2-BIFF8 specific (MUST NOT be called in OOXML/BIFF12 filter) -------
258cdf0e10cSrcweir 
259cdf0e10cSrcweir     /** Returns the base BIFF filter object. */
260cdf0e10cSrcweir     ::oox::core::BinaryFilterBase& getBiffFilter() const;
261cdf0e10cSrcweir     /** Returns the BIFF type in binary filter. */
262cdf0e10cSrcweir     BiffType            getBiff() const;
263cdf0e10cSrcweir 
264cdf0e10cSrcweir     /** Returns the text encoding used to import/export byte strings. */
265cdf0e10cSrcweir     rtl_TextEncoding    getTextEncoding() const;
266cdf0e10cSrcweir     /** Sets the text encoding to import/export byte strings. */
267cdf0e10cSrcweir     void                setTextEncoding( rtl_TextEncoding eTextEnc );
268cdf0e10cSrcweir     /** Sets code page read from a CODEPAGE record for byte string import. */
269cdf0e10cSrcweir     void                setCodePage( sal_uInt16 nCodePage );
270cdf0e10cSrcweir     /** Sets text encoding from the default application font, if CODEPAGE record is missing. */
271cdf0e10cSrcweir     void                setAppFontEncoding( rtl_TextEncoding eAppFontEnc );
272cdf0e10cSrcweir 
273cdf0e10cSrcweir     /** Enables workbook file mode, used for BIFF4 workspace files. */
274cdf0e10cSrcweir     void                setIsWorkbookFile();
275cdf0e10cSrcweir     /** Recreates global buffers that are used per sheet in specific BIFF versions. */
276cdf0e10cSrcweir     void                createBuffersPerSheet( sal_Int16 nSheet );
277cdf0e10cSrcweir 
278cdf0e10cSrcweir     /** Returns the codec helper that stores the encoder/decoder object. */
279cdf0e10cSrcweir     BiffCodecHelper&    getCodecHelper() const;
280cdf0e10cSrcweir 
281cdf0e10cSrcweir private:
282cdf0e10cSrcweir     WorkbookGlobals&    mrBookGlob;
283cdf0e10cSrcweir };
284cdf0e10cSrcweir 
285cdf0e10cSrcweir // ============================================================================
286cdf0e10cSrcweir 
287cdf0e10cSrcweir } // namespace xls
288cdf0e10cSrcweir } // namespace oox
289cdf0e10cSrcweir 
290cdf0e10cSrcweir #endif
291