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