1ca5ec200SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3ca5ec200SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4ca5ec200SAndrew Rist * or more contributor license agreements. See the NOTICE file 5ca5ec200SAndrew Rist * distributed with this work for additional information 6ca5ec200SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7ca5ec200SAndrew Rist * to you under the Apache License, Version 2.0 (the 8ca5ec200SAndrew Rist * "License"); you may not use this file except in compliance 9ca5ec200SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11ca5ec200SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13ca5ec200SAndrew Rist * Unless required by applicable law or agreed to in writing, 14ca5ec200SAndrew Rist * software distributed under the License is distributed on an 15ca5ec200SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ca5ec200SAndrew Rist * KIND, either express or implied. See the License for the 17ca5ec200SAndrew Rist * specific language governing permissions and limitations 18ca5ec200SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20ca5ec200SAndrew Rist *************************************************************/ 21ca5ec200SAndrew Rist 22ca5ec200SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "oox/xls/workbookhelper.hxx" 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include <com/sun/star/container/XIndexAccess.hpp> 27cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 28cdf0e10cSrcweir #include <com/sun/star/document/XActionLockable.hpp> 29cdf0e10cSrcweir #include <com/sun/star/sheet/XDatabaseRange.hpp> 30cdf0e10cSrcweir #include <com/sun/star/sheet/XDatabaseRanges.hpp> 31cdf0e10cSrcweir #include <com/sun/star/sheet/XNamedRange.hpp> 32cdf0e10cSrcweir #include <com/sun/star/sheet/XNamedRanges.hpp> 33cdf0e10cSrcweir #include <com/sun/star/sheet/XSpreadsheet.hpp> 34cdf0e10cSrcweir #include <com/sun/star/sheet/XSpreadsheetDocument.hpp> 35cdf0e10cSrcweir #include <com/sun/star/style/XStyle.hpp> 36cdf0e10cSrcweir #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> 37cdf0e10cSrcweir #include <com/sun/star/table/CellAddress.hpp> 38cdf0e10cSrcweir #include <osl/thread.h> 39cdf0e10cSrcweir #include "oox/drawingml/theme.hxx" 40cdf0e10cSrcweir #include "oox/helper/progressbar.hxx" 41cdf0e10cSrcweir #include "oox/helper/propertyset.hxx" 42cdf0e10cSrcweir #include "oox/ole/vbaproject.hxx" 43cdf0e10cSrcweir #include "oox/xls/addressconverter.hxx" 44cdf0e10cSrcweir #include "oox/xls/biffinputstream.hxx" 45cdf0e10cSrcweir #include "oox/xls/biffcodec.hxx" 46cdf0e10cSrcweir #include "oox/xls/connectionsbuffer.hxx" 47cdf0e10cSrcweir #include "oox/xls/defnamesbuffer.hxx" 48cdf0e10cSrcweir #include "oox/xls/excelchartconverter.hxx" 49cdf0e10cSrcweir #include "oox/xls/excelfilter.hxx" 50cdf0e10cSrcweir #include "oox/xls/externallinkbuffer.hxx" 51cdf0e10cSrcweir #include "oox/xls/formulaparser.hxx" 52cdf0e10cSrcweir #include "oox/xls/pagesettings.hxx" 53cdf0e10cSrcweir #include "oox/xls/pivotcachebuffer.hxx" 54cdf0e10cSrcweir #include "oox/xls/pivottablebuffer.hxx" 55cdf0e10cSrcweir #include "oox/xls/scenariobuffer.hxx" 56cdf0e10cSrcweir #include "oox/xls/sharedstringsbuffer.hxx" 57cdf0e10cSrcweir #include "oox/xls/stylesbuffer.hxx" 58cdf0e10cSrcweir #include "oox/xls/tablebuffer.hxx" 59cdf0e10cSrcweir #include "oox/xls/themebuffer.hxx" 60cdf0e10cSrcweir #include "oox/xls/unitconverter.hxx" 61cdf0e10cSrcweir #include "oox/xls/viewsettings.hxx" 62cdf0e10cSrcweir #include "oox/xls/workbooksettings.hxx" 63cdf0e10cSrcweir #include "oox/xls/worksheetbuffer.hxx" 64cdf0e10cSrcweir 65cdf0e10cSrcweir namespace oox { 66cdf0e10cSrcweir namespace xls { 67cdf0e10cSrcweir 68cdf0e10cSrcweir // ============================================================================ 69cdf0e10cSrcweir 70cdf0e10cSrcweir using namespace ::com::sun::star::awt; 71cdf0e10cSrcweir using namespace ::com::sun::star::container; 72cdf0e10cSrcweir using namespace ::com::sun::star::document; 73cdf0e10cSrcweir using namespace ::com::sun::star::lang; 74cdf0e10cSrcweir using namespace ::com::sun::star::sheet; 75cdf0e10cSrcweir using namespace ::com::sun::star::style; 76cdf0e10cSrcweir using namespace ::com::sun::star::table; 77cdf0e10cSrcweir using namespace ::com::sun::star::uno; 78cdf0e10cSrcweir 79cdf0e10cSrcweir using ::oox::core::BinaryFilterBase; 80cdf0e10cSrcweir using ::oox::core::FilterBase; 81cdf0e10cSrcweir using ::oox::core::FragmentHandler; 82cdf0e10cSrcweir using ::oox::core::XmlFilterBase; 83cdf0e10cSrcweir using ::oox::drawingml::Theme; 84cdf0e10cSrcweir using ::rtl::OUString; 85cdf0e10cSrcweir 86cdf0e10cSrcweir // ============================================================================ 87cdf0e10cSrcweir 88cdf0e10cSrcweir bool IgnoreCaseCompare::operator()( const OUString& rName1, const OUString& rName2 ) const 89cdf0e10cSrcweir { 90cdf0e10cSrcweir // there is no wrapper in rtl::OUString, TODO: compare with collator 91cdf0e10cSrcweir return ::rtl_ustr_compareIgnoreAsciiCase_WithLength( 92cdf0e10cSrcweir rName1.getStr(), rName1.getLength(), rName2.getStr(), rName2.getLength() ) < 0; 93cdf0e10cSrcweir } 94cdf0e10cSrcweir 95cdf0e10cSrcweir // ============================================================================ 96cdf0e10cSrcweir 97cdf0e10cSrcweir class WorkbookGlobals 98cdf0e10cSrcweir { 99cdf0e10cSrcweir public: 100cdf0e10cSrcweir explicit WorkbookGlobals( ExcelFilter& rFilter ); 101cdf0e10cSrcweir explicit WorkbookGlobals( ExcelBiffFilter& rFilter, BiffType eBiff ); 102cdf0e10cSrcweir ~WorkbookGlobals(); 103cdf0e10cSrcweir 104cdf0e10cSrcweir /** Returns true, if this helper refers to a valid document. */ 105cdf0e10cSrcweir inline bool isValid() const { return mxDoc.is(); } 106cdf0e10cSrcweir 107cdf0e10cSrcweir // filter ----------------------------------------------------------------- 108cdf0e10cSrcweir 109cdf0e10cSrcweir /** Returns the base filter object (base class of all filters). */ 110cdf0e10cSrcweir inline FilterBase& getBaseFilter() const { return mrBaseFilter; } 111cdf0e10cSrcweir /** Returns the filter progress bar. */ 112cdf0e10cSrcweir inline SegmentProgressBar& getProgressBar() const { return *mxProgressBar; } 113cdf0e10cSrcweir /** Returns the file type of the current filter. */ 114cdf0e10cSrcweir inline FilterType getFilterType() const { return meFilterType; } 115cdf0e10cSrcweir /** Returns true, if the file is a multi-sheet document, or false if single-sheet. */ 116cdf0e10cSrcweir inline bool isWorkbookFile() const { return mbWorkbook; } 117cdf0e10cSrcweir /** Returns the VBA project storage. */ 118cdf0e10cSrcweir inline StorageRef getVbaProjectStorage() const { return mxVbaPrjStrg; } 119cdf0e10cSrcweir /** Returns the index of the current Calc sheet, if filter currently processes a sheet. */ 120cdf0e10cSrcweir inline sal_Int16 getCurrentSheetIndex() const { return mnCurrSheet; } 121cdf0e10cSrcweir 122cdf0e10cSrcweir /** Sets the VBA project storage used to import VBA source code and forms. */ 123cdf0e10cSrcweir inline void setVbaProjectStorage( const StorageRef& rxVbaPrjStrg ) { mxVbaPrjStrg = rxVbaPrjStrg; } 124cdf0e10cSrcweir /** Sets the index of the current Calc sheet, if filter currently processes a sheet. */ 125cdf0e10cSrcweir inline void setCurrentSheetIndex( sal_Int16 nSheet ) { mnCurrSheet = nSheet; } 126cdf0e10cSrcweir 127cdf0e10cSrcweir // document model --------------------------------------------------------- 128cdf0e10cSrcweir 129cdf0e10cSrcweir /** Returns a reference to the source/target spreadsheet document model. */ 130cdf0e10cSrcweir inline Reference< XSpreadsheetDocument > getDocument() const { return mxDoc; } 131cdf0e10cSrcweir /** Returns the cell or page styles container from the Calc document. */ 132cdf0e10cSrcweir Reference< XNameContainer > getStyleFamily( bool bPageStyles ) const; 133cdf0e10cSrcweir /** Returns the specified cell or page style from the Calc document. */ 134cdf0e10cSrcweir Reference< XStyle > getStyleObject( const OUString& rStyleName, bool bPageStyle ) const; 135cdf0e10cSrcweir /** Creates and returns a defined name on-the-fly in the Calc document. */ 136*dffa72deSWang Lei Reference< XNamedRange > createNamedRangeObject( OUString& orScope, OUString& orName, sal_Int32 nNameFlags ) const; 137cdf0e10cSrcweir /** Creates and returns a database range on-the-fly in the Calc document. */ 138cdf0e10cSrcweir Reference< XDatabaseRange > createDatabaseRangeObject( OUString& orName, const CellRangeAddress& rRangeAddr ) const; 139cdf0e10cSrcweir /** Creates and returns a com.sun.star.style.Style object for cells or pages. */ 140cdf0e10cSrcweir Reference< XStyle > createStyleObject( OUString& orStyleName, bool bPageStyle ) const; 141cdf0e10cSrcweir 142cdf0e10cSrcweir // buffers ---------------------------------------------------------------- 143cdf0e10cSrcweir 144cdf0e10cSrcweir /** Returns the global workbook settings object. */ 145cdf0e10cSrcweir inline WorkbookSettings& getWorkbookSettings() const { return *mxWorkbookSettings; } 146cdf0e10cSrcweir /** Returns the workbook and sheet view settings object. */ 147cdf0e10cSrcweir inline ViewSettings& getViewSettings() const { return *mxViewSettings; } 148cdf0e10cSrcweir /** Returns the worksheet buffer containing sheet names and properties. */ 149cdf0e10cSrcweir inline WorksheetBuffer& getWorksheets() const { return *mxWorksheets; } 150cdf0e10cSrcweir /** Returns the office theme object read from the theme substorage. */ 151cdf0e10cSrcweir inline ThemeBuffer& getTheme() const { return *mxTheme; } 152cdf0e10cSrcweir /** Returns all cell formatting objects read from the styles substream. */ 153cdf0e10cSrcweir inline StylesBuffer& getStyles() const { return *mxStyles; } 154cdf0e10cSrcweir /** Returns the shared strings read from the shared strings substream. */ 155cdf0e10cSrcweir inline SharedStringsBuffer& getSharedStrings() const { return *mxSharedStrings; } 156cdf0e10cSrcweir /** Returns the external links read from the external links substream. */ 157cdf0e10cSrcweir inline ExternalLinkBuffer& getExternalLinks() const { return *mxExtLinks; } 158cdf0e10cSrcweir /** Returns the defined names read from the workbook globals. */ 159cdf0e10cSrcweir inline DefinedNamesBuffer& getDefinedNames() const { return *mxDefNames; } 160cdf0e10cSrcweir /** Returns the tables collection (equivalent to Calc's database ranges). */ 161cdf0e10cSrcweir inline TableBuffer& getTables() const { return *mxTables; } 162cdf0e10cSrcweir /** Returns the scenarios collection. */ 163cdf0e10cSrcweir inline ScenarioBuffer& getScenarios() const { return *mxScenarios; } 164cdf0e10cSrcweir /** Returns the collection of external data connections. */ 165cdf0e10cSrcweir inline ConnectionsBuffer& getConnections() const { return *mxConnections; } 166cdf0e10cSrcweir /** Returns the collection of pivot caches. */ 167cdf0e10cSrcweir inline PivotCacheBuffer& getPivotCaches() const { return *mxPivotCaches; } 168cdf0e10cSrcweir /** Returns the collection of pivot tables. */ 169cdf0e10cSrcweir inline PivotTableBuffer& getPivotTables() { return *mxPivotTables; } 170cdf0e10cSrcweir 171cdf0e10cSrcweir // converters ------------------------------------------------------------- 172cdf0e10cSrcweir 173cdf0e10cSrcweir /** Returns the import formula parser. */ 174cdf0e10cSrcweir inline FormulaParser& getFormulaParser() const { return *mxFmlaParser; } 175cdf0e10cSrcweir /** Returns the measurement unit converter. */ 176cdf0e10cSrcweir inline UnitConverter& getUnitConverter() const { return *mxUnitConverter; } 177cdf0e10cSrcweir /** Returns the converter for string to cell address/range conversion. */ 178cdf0e10cSrcweir inline AddressConverter& getAddressConverter() const { return *mxAddrConverter; } 179cdf0e10cSrcweir /** Returns the chart object converter. */ 180cdf0e10cSrcweir inline ExcelChartConverter& getChartConverter() const { return *mxChartConverter; } 181cdf0e10cSrcweir /** Returns the page/print settings converter. */ 182cdf0e10cSrcweir inline PageSettingsConverter& getPageSettingsConverter() const { return *mxPageSettConverter; } 183cdf0e10cSrcweir 184cdf0e10cSrcweir // OOXML/BIFF12 specific -------------------------------------------------- 185cdf0e10cSrcweir 186cdf0e10cSrcweir /** Returns the base OOXML/BIFF12 filter object. */ 187cdf0e10cSrcweir inline XmlFilterBase& getOoxFilter() const { return *mpOoxFilter; } 188cdf0e10cSrcweir 189cdf0e10cSrcweir // BIFF2-BIFF8 specific --------------------------------------------------- 190cdf0e10cSrcweir 191cdf0e10cSrcweir /** Returns the base BIFF filter object. */ 192cdf0e10cSrcweir inline BinaryFilterBase& getBiffFilter() const { return *mpBiffFilter; } 193cdf0e10cSrcweir /** Returns the BIFF type in binary filter. */ 194cdf0e10cSrcweir inline BiffType getBiff() const { return meBiff; } 195cdf0e10cSrcweir /** Returns the text encoding used to import/export byte strings. */ 196cdf0e10cSrcweir inline rtl_TextEncoding getTextEncoding() const { return meTextEnc; } 197cdf0e10cSrcweir /** Sets the text encoding to import/export byte strings. */ 198cdf0e10cSrcweir void setTextEncoding( rtl_TextEncoding eTextEnc ); 199cdf0e10cSrcweir /** Sets code page read from a CODEPAGE record for byte string import. */ 200cdf0e10cSrcweir void setCodePage( sal_uInt16 nCodePage ); 201cdf0e10cSrcweir /** Sets text encoding from the default application font, if CODEPAGE record is missing. */ 202cdf0e10cSrcweir void setAppFontEncoding( rtl_TextEncoding eAppFontEnc ); 203cdf0e10cSrcweir /** Enables workbook file mode, used for BIFF4 workspace files. */ 204cdf0e10cSrcweir void setIsWorkbookFile(); 205cdf0e10cSrcweir /** Recreates global buffers that are used per sheet in specific BIFF versions. */ 206cdf0e10cSrcweir void createBuffersPerSheet( sal_Int16 nSheet ); 207cdf0e10cSrcweir /** Returns the codec helper that stores the encoder/decoder object. */ 208cdf0e10cSrcweir inline BiffCodecHelper& getCodecHelper() { return *mxCodecHelper; } 209cdf0e10cSrcweir 210cdf0e10cSrcweir private: 211cdf0e10cSrcweir /** Initializes some basic members and sets needed document properties. */ 212cdf0e10cSrcweir void initialize( bool bWorkbookFile ); 213cdf0e10cSrcweir /** Finalizes the filter process (sets some needed document properties). */ 214cdf0e10cSrcweir void finalize(); 215cdf0e10cSrcweir 216cdf0e10cSrcweir private: 217cdf0e10cSrcweir typedef ::std::auto_ptr< SegmentProgressBar > ProgressBarPtr; 218cdf0e10cSrcweir typedef ::std::auto_ptr< WorkbookSettings > WorkbookSettPtr; 219cdf0e10cSrcweir typedef ::std::auto_ptr< ViewSettings > ViewSettingsPtr; 220cdf0e10cSrcweir typedef ::std::auto_ptr< WorksheetBuffer > WorksheetBfrPtr; 221cdf0e10cSrcweir typedef ::boost::shared_ptr< ThemeBuffer > ThemeBfrRef; 222cdf0e10cSrcweir typedef ::std::auto_ptr< StylesBuffer > StylesBfrPtr; 223cdf0e10cSrcweir typedef ::std::auto_ptr< SharedStringsBuffer > SharedStrBfrPtr; 224cdf0e10cSrcweir typedef ::std::auto_ptr< ExternalLinkBuffer > ExtLinkBfrPtr; 225cdf0e10cSrcweir typedef ::std::auto_ptr< DefinedNamesBuffer > DefNamesBfrPtr; 226cdf0e10cSrcweir typedef ::std::auto_ptr< TableBuffer > TableBfrPtr; 227cdf0e10cSrcweir typedef ::std::auto_ptr< ScenarioBuffer > ScenarioBfrPtr; 228cdf0e10cSrcweir typedef ::std::auto_ptr< ConnectionsBuffer > ConnectionsBfrPtr; 229cdf0e10cSrcweir typedef ::std::auto_ptr< PivotCacheBuffer > PivotCacheBfrPtr; 230cdf0e10cSrcweir typedef ::std::auto_ptr< PivotTableBuffer > PivotTableBfrPtr; 231cdf0e10cSrcweir typedef ::std::auto_ptr< FormulaParser > FormulaParserPtr; 232cdf0e10cSrcweir typedef ::std::auto_ptr< UnitConverter > UnitConvPtr; 233cdf0e10cSrcweir typedef ::std::auto_ptr< AddressConverter > AddressConvPtr; 234cdf0e10cSrcweir typedef ::std::auto_ptr< ExcelChartConverter > ExcelChartConvPtr; 235cdf0e10cSrcweir typedef ::std::auto_ptr< PageSettingsConverter > PageSettConvPtr; 236cdf0e10cSrcweir typedef ::std::auto_ptr< BiffCodecHelper > BiffCodecHelperPtr; 237cdf0e10cSrcweir 238cdf0e10cSrcweir OUString maCellStyles; /// Style family name for cell styles. 239cdf0e10cSrcweir OUString maPageStyles; /// Style family name for page styles. 240cdf0e10cSrcweir OUString maCellStyleServ; /// Service name for a cell style. 241cdf0e10cSrcweir OUString maPageStyleServ; /// Service name for a page style. 242cdf0e10cSrcweir Reference< XSpreadsheetDocument > mxDoc; /// Document model. 243cdf0e10cSrcweir FilterBase& mrBaseFilter; /// Base filter object. 244cdf0e10cSrcweir ExcelFilterBase& mrExcelBase; /// Base object for registration of this structure. 245cdf0e10cSrcweir FilterType meFilterType; /// File type of the filter. 246cdf0e10cSrcweir ProgressBarPtr mxProgressBar; /// The progress bar. 247cdf0e10cSrcweir StorageRef mxVbaPrjStrg; /// Storage containing the VBA project. 248cdf0e10cSrcweir sal_Int16 mnCurrSheet; /// Current sheet index in Calc dcument. 249cdf0e10cSrcweir bool mbWorkbook; /// True = multi-sheet file. 250cdf0e10cSrcweir 251cdf0e10cSrcweir // buffers 252cdf0e10cSrcweir WorkbookSettPtr mxWorkbookSettings; /// Global workbook settings. 253cdf0e10cSrcweir ViewSettingsPtr mxViewSettings; /// Workbook and sheet view settings. 254cdf0e10cSrcweir WorksheetBfrPtr mxWorksheets; /// Sheet info buffer. 255cdf0e10cSrcweir ThemeBfrRef mxTheme; /// Formatting theme from theme substream. 256cdf0e10cSrcweir StylesBfrPtr mxStyles; /// All cell style objects from styles substream. 257cdf0e10cSrcweir SharedStrBfrPtr mxSharedStrings; /// All strings from shared strings substream. 258cdf0e10cSrcweir ExtLinkBfrPtr mxExtLinks; /// All external links. 259cdf0e10cSrcweir DefNamesBfrPtr mxDefNames; /// All defined names. 260cdf0e10cSrcweir TableBfrPtr mxTables; /// All tables (database ranges). 261cdf0e10cSrcweir ScenarioBfrPtr mxScenarios; /// All scenarios. 262cdf0e10cSrcweir ConnectionsBfrPtr mxConnections; /// All external data connections. 263cdf0e10cSrcweir PivotCacheBfrPtr mxPivotCaches; /// All pivot caches in the document. 264cdf0e10cSrcweir PivotTableBfrPtr mxPivotTables; /// All pivot tables in the document. 265cdf0e10cSrcweir 266cdf0e10cSrcweir // converters 267cdf0e10cSrcweir FormulaParserPtr mxFmlaParser; /// Import formula parser. 268cdf0e10cSrcweir UnitConvPtr mxUnitConverter; /// General unit converter. 269cdf0e10cSrcweir AddressConvPtr mxAddrConverter; /// Cell address and cell range address converter. 270cdf0e10cSrcweir ExcelChartConvPtr mxChartConverter; /// Chart object converter. 271cdf0e10cSrcweir PageSettConvPtr mxPageSettConverter; /// Page/print settings converter. 272cdf0e10cSrcweir 273cdf0e10cSrcweir // OOXML/BIFF12 specific 274cdf0e10cSrcweir XmlFilterBase* mpOoxFilter; /// Base OOXML/BIFF12 filter object. 275cdf0e10cSrcweir 276cdf0e10cSrcweir // BIFF2-BIFF8 specific 277cdf0e10cSrcweir BinaryFilterBase* mpBiffFilter; /// Base BIFF2-BIFF8 filter object. 278cdf0e10cSrcweir BiffCodecHelperPtr mxCodecHelper; /// Encoder/decoder helper. 279cdf0e10cSrcweir BiffType meBiff; /// BIFF version for BIFF import/export. 280cdf0e10cSrcweir rtl_TextEncoding meTextEnc; /// BIFF byte string text encoding. 281cdf0e10cSrcweir bool mbHasCodePage; /// True = CODEPAGE record exists in imported stream. 282cdf0e10cSrcweir }; 283cdf0e10cSrcweir 284cdf0e10cSrcweir // ---------------------------------------------------------------------------- 285cdf0e10cSrcweir 286cdf0e10cSrcweir WorkbookGlobals::WorkbookGlobals( ExcelFilter& rFilter ) : 287cdf0e10cSrcweir mrBaseFilter( rFilter ), 288cdf0e10cSrcweir mrExcelBase( rFilter ), 289cdf0e10cSrcweir meFilterType( FILTER_OOXML ), 290cdf0e10cSrcweir mpOoxFilter( &rFilter ), 291cdf0e10cSrcweir mpBiffFilter( 0 ), 292cdf0e10cSrcweir meBiff( BIFF_UNKNOWN ) 293cdf0e10cSrcweir { 294cdf0e10cSrcweir // register at the filter, needed for virtual callbacks (even during construction) 295cdf0e10cSrcweir mrExcelBase.registerWorkbookGlobals( *this ); 296cdf0e10cSrcweir initialize( true ); 297cdf0e10cSrcweir } 298cdf0e10cSrcweir 299cdf0e10cSrcweir WorkbookGlobals::WorkbookGlobals( ExcelBiffFilter& rFilter, BiffType eBiff ) : 300cdf0e10cSrcweir mrBaseFilter( rFilter ), 301cdf0e10cSrcweir mrExcelBase( rFilter ), 302cdf0e10cSrcweir meFilterType( FILTER_BIFF ), 303cdf0e10cSrcweir mpOoxFilter( 0 ), 304cdf0e10cSrcweir mpBiffFilter( &rFilter ), 305cdf0e10cSrcweir meBiff( eBiff ) 306cdf0e10cSrcweir { 307cdf0e10cSrcweir // register at the filter, needed for virtual callbacks (even during construction) 308cdf0e10cSrcweir mrExcelBase.registerWorkbookGlobals( *this ); 309cdf0e10cSrcweir initialize( eBiff >= BIFF5 ); 310cdf0e10cSrcweir } 311cdf0e10cSrcweir 312cdf0e10cSrcweir WorkbookGlobals::~WorkbookGlobals() 313cdf0e10cSrcweir { 314cdf0e10cSrcweir finalize(); 315cdf0e10cSrcweir mrExcelBase.unregisterWorkbookGlobals(); 316cdf0e10cSrcweir } 317cdf0e10cSrcweir 318cdf0e10cSrcweir // document model ------------------------------------------------------------- 319cdf0e10cSrcweir 320cdf0e10cSrcweir Reference< XNameContainer > WorkbookGlobals::getStyleFamily( bool bPageStyles ) const 321cdf0e10cSrcweir { 322cdf0e10cSrcweir Reference< XNameContainer > xStylesNC; 323cdf0e10cSrcweir try 324cdf0e10cSrcweir { 325cdf0e10cSrcweir Reference< XStyleFamiliesSupplier > xFamiliesSup( mxDoc, UNO_QUERY_THROW ); 326cdf0e10cSrcweir Reference< XNameAccess > xFamiliesNA( xFamiliesSup->getStyleFamilies(), UNO_QUERY_THROW ); 327cdf0e10cSrcweir xStylesNC.set( xFamiliesNA->getByName( bPageStyles ? maPageStyles : maCellStyles ), UNO_QUERY ); 328cdf0e10cSrcweir } 329cdf0e10cSrcweir catch( Exception& ) 330cdf0e10cSrcweir { 331cdf0e10cSrcweir } 332cdf0e10cSrcweir OSL_ENSURE( xStylesNC.is(), "WorkbookGlobals::getStyleFamily - cannot access style family" ); 333cdf0e10cSrcweir return xStylesNC; 334cdf0e10cSrcweir } 335cdf0e10cSrcweir 336cdf0e10cSrcweir Reference< XStyle > WorkbookGlobals::getStyleObject( const OUString& rStyleName, bool bPageStyle ) const 337cdf0e10cSrcweir { 338cdf0e10cSrcweir Reference< XStyle > xStyle; 339cdf0e10cSrcweir try 340cdf0e10cSrcweir { 341cdf0e10cSrcweir Reference< XNameContainer > xStylesNC( getStyleFamily( bPageStyle ), UNO_SET_THROW ); 342cdf0e10cSrcweir xStyle.set( xStylesNC->getByName( rStyleName ), UNO_QUERY ); 343cdf0e10cSrcweir } 344cdf0e10cSrcweir catch( Exception& ) 345cdf0e10cSrcweir { 346cdf0e10cSrcweir } 347cdf0e10cSrcweir OSL_ENSURE( xStyle.is(), "WorkbookGlobals::getStyleObject - cannot access style object" ); 348cdf0e10cSrcweir return xStyle; 349cdf0e10cSrcweir } 350cdf0e10cSrcweir 351*dffa72deSWang Lei Reference< XNamedRange > WorkbookGlobals::createNamedRangeObject( OUString& orScope, OUString& orName, sal_Int32 nNameFlags ) const 352cdf0e10cSrcweir { 353cdf0e10cSrcweir // create the name and insert it into the Calc document 354cdf0e10cSrcweir Reference< XNamedRange > xNamedRange; 355cdf0e10cSrcweir if( orName.getLength() > 0 ) try 356cdf0e10cSrcweir { 357cdf0e10cSrcweir // find an unused name 358cdf0e10cSrcweir PropertySet aDocProps( mxDoc ); 359cdf0e10cSrcweir Reference< XNamedRanges > xNamedRanges( aDocProps.getAnyProperty( PROP_NamedRanges ), UNO_QUERY_THROW ); 360cdf0e10cSrcweir Reference< XNameAccess > xNameAccess( xNamedRanges, UNO_QUERY_THROW ); 361cdf0e10cSrcweir orName = ContainerHelper::getUnusedName( xNameAccess, orName, '_' ); 362cdf0e10cSrcweir // create the named range 363*dffa72deSWang Lei xNamedRanges->addNewByScopeName( orScope, orName, OUString(), CellAddress( 0, 0, 0 ), nNameFlags ); 364*dffa72deSWang Lei xNamedRange.set( xNamedRanges->getByScopeName( orScope, orName ), UNO_QUERY ); 365cdf0e10cSrcweir } 366cdf0e10cSrcweir catch( Exception& ) 367cdf0e10cSrcweir { 368cdf0e10cSrcweir } 369cdf0e10cSrcweir OSL_ENSURE( xNamedRange.is(), "WorkbookGlobals::createNamedRangeObject - cannot create defined name" ); 370cdf0e10cSrcweir return xNamedRange; 371cdf0e10cSrcweir } 372cdf0e10cSrcweir 373cdf0e10cSrcweir Reference< XDatabaseRange > WorkbookGlobals::createDatabaseRangeObject( OUString& orName, const CellRangeAddress& rRangeAddr ) const 374cdf0e10cSrcweir { 375cdf0e10cSrcweir // validate cell range 376cdf0e10cSrcweir CellRangeAddress aDestRange = rRangeAddr; 377cdf0e10cSrcweir bool bValidRange = getAddressConverter().validateCellRange( aDestRange, true, true ); 378cdf0e10cSrcweir 379cdf0e10cSrcweir // create database range and insert it into the Calc document 380cdf0e10cSrcweir Reference< XDatabaseRange > xDatabaseRange; 381cdf0e10cSrcweir if( bValidRange && (orName.getLength() > 0) ) try 382cdf0e10cSrcweir { 383cdf0e10cSrcweir // find an unused name 384cdf0e10cSrcweir PropertySet aDocProps( mxDoc ); 385cdf0e10cSrcweir Reference< XDatabaseRanges > xDatabaseRanges( aDocProps.getAnyProperty( PROP_DatabaseRanges ), UNO_QUERY_THROW ); 386cdf0e10cSrcweir Reference< XNameAccess > xNameAccess( xDatabaseRanges, UNO_QUERY_THROW ); 387cdf0e10cSrcweir orName = ContainerHelper::getUnusedName( xNameAccess, orName, '_' ); 388cdf0e10cSrcweir // create the database range 389cdf0e10cSrcweir xDatabaseRanges->addNewByName( orName, aDestRange ); 390cdf0e10cSrcweir xDatabaseRange.set( xDatabaseRanges->getByName( orName ), UNO_QUERY ); 391cdf0e10cSrcweir } 392cdf0e10cSrcweir catch( Exception& ) 393cdf0e10cSrcweir { 394cdf0e10cSrcweir } 395cdf0e10cSrcweir OSL_ENSURE( xDatabaseRange.is(), "WorkbookGlobals::createDatabaseRangeObject - cannot create database range" ); 396cdf0e10cSrcweir return xDatabaseRange; 397cdf0e10cSrcweir } 398cdf0e10cSrcweir 399cdf0e10cSrcweir Reference< XStyle > WorkbookGlobals::createStyleObject( OUString& orStyleName, bool bPageStyle ) const 400cdf0e10cSrcweir { 401cdf0e10cSrcweir Reference< XStyle > xStyle; 402cdf0e10cSrcweir try 403cdf0e10cSrcweir { 404cdf0e10cSrcweir Reference< XNameContainer > xStylesNC( getStyleFamily( bPageStyle ), UNO_SET_THROW ); 405cdf0e10cSrcweir xStyle.set( mrBaseFilter.getModelFactory()->createInstance( bPageStyle ? maPageStyleServ : maCellStyleServ ), UNO_QUERY_THROW ); 406cdf0e10cSrcweir orStyleName = ContainerHelper::insertByUnusedName( xStylesNC, orStyleName, ' ', Any( xStyle ), false ); 407cdf0e10cSrcweir } 408cdf0e10cSrcweir catch( Exception& ) 409cdf0e10cSrcweir { 410cdf0e10cSrcweir } 411cdf0e10cSrcweir OSL_ENSURE( xStyle.is(), "WorkbookGlobals::createStyleObject - cannot create style" ); 412cdf0e10cSrcweir return xStyle; 413cdf0e10cSrcweir } 414cdf0e10cSrcweir 415cdf0e10cSrcweir // BIFF specific -------------------------------------------------------------- 416cdf0e10cSrcweir 417cdf0e10cSrcweir void WorkbookGlobals::setTextEncoding( rtl_TextEncoding eTextEnc ) 418cdf0e10cSrcweir { 419cdf0e10cSrcweir if( eTextEnc != RTL_TEXTENCODING_DONTKNOW ) 420cdf0e10cSrcweir meTextEnc = eTextEnc; 421cdf0e10cSrcweir } 422cdf0e10cSrcweir 423cdf0e10cSrcweir void WorkbookGlobals::setCodePage( sal_uInt16 nCodePage ) 424cdf0e10cSrcweir { 425cdf0e10cSrcweir setTextEncoding( BiffHelper::calcTextEncodingFromCodePage( nCodePage ) ); 426cdf0e10cSrcweir mbHasCodePage = true; 427cdf0e10cSrcweir } 428cdf0e10cSrcweir 429cdf0e10cSrcweir void WorkbookGlobals::setAppFontEncoding( rtl_TextEncoding eAppFontEnc ) 430cdf0e10cSrcweir { 431cdf0e10cSrcweir if( !mbHasCodePage ) 432cdf0e10cSrcweir setTextEncoding( eAppFontEnc ); 433cdf0e10cSrcweir } 434cdf0e10cSrcweir 435cdf0e10cSrcweir void WorkbookGlobals::setIsWorkbookFile() 436cdf0e10cSrcweir { 437cdf0e10cSrcweir OSL_ENSURE( meBiff == BIFF4, "WorkbookGlobals::setIsWorkbookFile - invalid call" ); 438cdf0e10cSrcweir mbWorkbook = true; 439cdf0e10cSrcweir } 440cdf0e10cSrcweir 441cdf0e10cSrcweir void WorkbookGlobals::createBuffersPerSheet( sal_Int16 nSheet ) 442cdf0e10cSrcweir { 443cdf0e10cSrcweir switch( meBiff ) 444cdf0e10cSrcweir { 445cdf0e10cSrcweir case BIFF2: 446cdf0e10cSrcweir case BIFF3: 447cdf0e10cSrcweir OSL_ENSURE( nSheet == 0, "WorkbookGlobals::createBuffersPerSheet - unexpected sheet index" ); 448cdf0e10cSrcweir mxDefNames->setLocalCalcSheet( nSheet ); 449cdf0e10cSrcweir break; 450cdf0e10cSrcweir 451cdf0e10cSrcweir case BIFF4: 452cdf0e10cSrcweir OSL_ENSURE( mbWorkbook || (nSheet == 0), "WorkbookGlobals::createBuffersPerSheet - unexpected sheet index" ); 453cdf0e10cSrcweir // #i11183# sheets in BIFF4W files have own styles and names 454cdf0e10cSrcweir if( nSheet > 0 ) 455cdf0e10cSrcweir { 456cdf0e10cSrcweir mxStyles.reset( new StylesBuffer( *this ) ); 457cdf0e10cSrcweir mxDefNames.reset( new DefinedNamesBuffer( *this ) ); 458cdf0e10cSrcweir mxExtLinks.reset( new ExternalLinkBuffer( *this ) ); 459cdf0e10cSrcweir } 460cdf0e10cSrcweir mxDefNames->setLocalCalcSheet( nSheet ); 461cdf0e10cSrcweir break; 462cdf0e10cSrcweir 463cdf0e10cSrcweir case BIFF5: 464cdf0e10cSrcweir // BIFF5 stores external references per sheet 465cdf0e10cSrcweir if( nSheet > 0 ) 466cdf0e10cSrcweir mxExtLinks.reset( new ExternalLinkBuffer( *this ) ); 467cdf0e10cSrcweir break; 468cdf0e10cSrcweir 469cdf0e10cSrcweir case BIFF8: 470cdf0e10cSrcweir break; 471cdf0e10cSrcweir 472cdf0e10cSrcweir case BIFF_UNKNOWN: 473cdf0e10cSrcweir break; 474cdf0e10cSrcweir } 475cdf0e10cSrcweir } 476cdf0e10cSrcweir 477cdf0e10cSrcweir // private -------------------------------------------------------------------- 478cdf0e10cSrcweir 479cdf0e10cSrcweir void WorkbookGlobals::initialize( bool bWorkbookFile ) 480cdf0e10cSrcweir { 481cdf0e10cSrcweir maCellStyles = CREATE_OUSTRING( "CellStyles" ); 482cdf0e10cSrcweir maPageStyles = CREATE_OUSTRING( "PageStyles" ); 483cdf0e10cSrcweir maCellStyleServ = CREATE_OUSTRING( "com.sun.star.style.CellStyle" ); 484cdf0e10cSrcweir maPageStyleServ = CREATE_OUSTRING( "com.sun.star.style.PageStyle" ); 485cdf0e10cSrcweir mnCurrSheet = -1; 486cdf0e10cSrcweir mbWorkbook = bWorkbookFile; 487cdf0e10cSrcweir meTextEnc = osl_getThreadTextEncoding(); 488cdf0e10cSrcweir mbHasCodePage = false; 489cdf0e10cSrcweir 490cdf0e10cSrcweir // the spreadsheet document 491cdf0e10cSrcweir mxDoc.set( mrBaseFilter.getModel(), UNO_QUERY ); 492cdf0e10cSrcweir OSL_ENSURE( mxDoc.is(), "WorkbookGlobals::initialize - no spreadsheet document" ); 493cdf0e10cSrcweir 494cdf0e10cSrcweir mxWorkbookSettings.reset( new WorkbookSettings( *this ) ); 495cdf0e10cSrcweir mxViewSettings.reset( new ViewSettings( *this ) ); 496cdf0e10cSrcweir mxWorksheets.reset( new WorksheetBuffer( *this ) ); 497cdf0e10cSrcweir mxTheme.reset( new ThemeBuffer( *this ) ); 498cdf0e10cSrcweir mxStyles.reset( new StylesBuffer( *this ) ); 499cdf0e10cSrcweir mxSharedStrings.reset( new SharedStringsBuffer( *this ) ); 500cdf0e10cSrcweir mxExtLinks.reset( new ExternalLinkBuffer( *this ) ); 501cdf0e10cSrcweir mxDefNames.reset( new DefinedNamesBuffer( *this ) ); 502cdf0e10cSrcweir mxTables.reset( new TableBuffer( *this ) ); 503cdf0e10cSrcweir mxScenarios.reset( new ScenarioBuffer( *this ) ); 504cdf0e10cSrcweir mxConnections.reset( new ConnectionsBuffer( *this ) ); 505cdf0e10cSrcweir mxPivotCaches.reset( new PivotCacheBuffer( *this ) ); 506cdf0e10cSrcweir mxPivotTables.reset( new PivotTableBuffer( *this ) ); 507cdf0e10cSrcweir 508cdf0e10cSrcweir mxUnitConverter.reset( new UnitConverter( *this ) ); 509cdf0e10cSrcweir mxAddrConverter.reset( new AddressConverter( *this ) ); 510cdf0e10cSrcweir mxChartConverter.reset( new ExcelChartConverter( *this ) ); 511cdf0e10cSrcweir mxPageSettConverter.reset( new PageSettingsConverter( *this ) ); 512cdf0e10cSrcweir 513cdf0e10cSrcweir // set some document properties needed during import 514cdf0e10cSrcweir if( mrBaseFilter.isImportFilter() ) 515cdf0e10cSrcweir { 516cdf0e10cSrcweir PropertySet aPropSet( mxDoc ); 517cdf0e10cSrcweir // enable editing read-only documents (e.g. from read-only files) 518cdf0e10cSrcweir aPropSet.setProperty( PROP_IsChangeReadOnlyEnabled, true ); 519cdf0e10cSrcweir // #i76026# disable Undo while loading the document 520cdf0e10cSrcweir aPropSet.setProperty( PROP_IsUndoEnabled, false ); 521cdf0e10cSrcweir // #i79826# disable calculating automatic row height while loading the document 522cdf0e10cSrcweir aPropSet.setProperty( PROP_IsAdjustHeightEnabled, false ); 523cdf0e10cSrcweir // disable automatic update of linked sheets and DDE links 524cdf0e10cSrcweir aPropSet.setProperty( PROP_IsExecuteLinkEnabled, false ); 525cdf0e10cSrcweir // #i79890# disable automatic update of defined names 526cdf0e10cSrcweir Reference< XActionLockable > xLockable( aPropSet.getAnyProperty( PROP_NamedRanges ), UNO_QUERY ); 527cdf0e10cSrcweir if( xLockable.is() ) 528cdf0e10cSrcweir xLockable->addActionLock(); 529cdf0e10cSrcweir 530cdf0e10cSrcweir //! TODO: localize progress bar text 531cdf0e10cSrcweir mxProgressBar.reset( new SegmentProgressBar( mrBaseFilter.getStatusIndicator(), CREATE_OUSTRING( "Loading..." ) ) ); 532cdf0e10cSrcweir mxFmlaParser.reset( new FormulaParser( *this ) ); 533cdf0e10cSrcweir } 534cdf0e10cSrcweir else if( mrBaseFilter.isExportFilter() ) 535cdf0e10cSrcweir { 536cdf0e10cSrcweir //! TODO: localize progress bar text 537cdf0e10cSrcweir mxProgressBar.reset( new SegmentProgressBar( mrBaseFilter.getStatusIndicator(), CREATE_OUSTRING( "Saving..." ) ) ); 538cdf0e10cSrcweir } 539cdf0e10cSrcweir 540cdf0e10cSrcweir // filter specific 541cdf0e10cSrcweir switch( getFilterType() ) 542cdf0e10cSrcweir { 543cdf0e10cSrcweir case FILTER_BIFF: 544cdf0e10cSrcweir mxCodecHelper.reset( new BiffCodecHelper( *this ) ); 545cdf0e10cSrcweir break; 546cdf0e10cSrcweir 547cdf0e10cSrcweir case FILTER_OOXML: 548cdf0e10cSrcweir break; 549cdf0e10cSrcweir 550cdf0e10cSrcweir case FILTER_UNKNOWN: 551cdf0e10cSrcweir break; 552cdf0e10cSrcweir } 553cdf0e10cSrcweir } 554cdf0e10cSrcweir 555cdf0e10cSrcweir void WorkbookGlobals::finalize() 556cdf0e10cSrcweir { 557cdf0e10cSrcweir // set some document properties needed after import 558cdf0e10cSrcweir if( mrBaseFilter.isImportFilter() ) 559cdf0e10cSrcweir { 560cdf0e10cSrcweir PropertySet aPropSet( mxDoc ); 561cdf0e10cSrcweir // #i74668# do not insert default sheets 562cdf0e10cSrcweir aPropSet.setProperty( PROP_IsLoaded, true ); 563cdf0e10cSrcweir // #i79890# enable automatic update of defined names (before IsAdjustHeightEnabled!) 564cdf0e10cSrcweir Reference< XActionLockable > xLockable( aPropSet.getAnyProperty( PROP_NamedRanges ), UNO_QUERY ); 565cdf0e10cSrcweir if( xLockable.is() ) 566cdf0e10cSrcweir xLockable->removeActionLock(); 567cdf0e10cSrcweir // enable automatic update of linked sheets and DDE links 568cdf0e10cSrcweir aPropSet.setProperty( PROP_IsExecuteLinkEnabled, true ); 569cdf0e10cSrcweir // #i79826# enable updating automatic row height after loading the document 570cdf0e10cSrcweir aPropSet.setProperty( PROP_IsAdjustHeightEnabled, true ); 571cdf0e10cSrcweir // #i76026# enable Undo after loading the document 572cdf0e10cSrcweir aPropSet.setProperty( PROP_IsUndoEnabled, true ); 573cdf0e10cSrcweir // disable editing read-only documents (e.g. from read-only files) 574cdf0e10cSrcweir aPropSet.setProperty( PROP_IsChangeReadOnlyEnabled, false ); 575cdf0e10cSrcweir // #111099# open forms in alive mode (has no effect, if no controls in document) 576cdf0e10cSrcweir aPropSet.setProperty( PROP_ApplyFormDesignMode, false ); 577cdf0e10cSrcweir } 578cdf0e10cSrcweir } 579cdf0e10cSrcweir 580cdf0e10cSrcweir // ============================================================================ 581cdf0e10cSrcweir 582cdf0e10cSrcweir WorkbookHelper::~WorkbookHelper() 583cdf0e10cSrcweir { 584cdf0e10cSrcweir } 585cdf0e10cSrcweir 586cdf0e10cSrcweir /*static*/ WorkbookGlobalsRef WorkbookHelper::constructGlobals( ExcelFilter& rFilter ) 587cdf0e10cSrcweir { 588cdf0e10cSrcweir WorkbookGlobalsRef xBookGlob( new WorkbookGlobals( rFilter ) ); 589cdf0e10cSrcweir if( !xBookGlob->isValid() ) 590cdf0e10cSrcweir xBookGlob.reset(); 591cdf0e10cSrcweir return xBookGlob; 592cdf0e10cSrcweir } 593cdf0e10cSrcweir 594cdf0e10cSrcweir /*static*/ WorkbookGlobalsRef WorkbookHelper::constructGlobals( ExcelBiffFilter& rFilter, BiffType eBiff ) 595cdf0e10cSrcweir { 596cdf0e10cSrcweir WorkbookGlobalsRef xBookGlob( new WorkbookGlobals( rFilter, eBiff ) ); 597cdf0e10cSrcweir if( !xBookGlob->isValid() ) 598cdf0e10cSrcweir xBookGlob.reset(); 599cdf0e10cSrcweir return xBookGlob; 600cdf0e10cSrcweir } 601cdf0e10cSrcweir 602cdf0e10cSrcweir // filter --------------------------------------------------------------------- 603cdf0e10cSrcweir 604cdf0e10cSrcweir FilterBase& WorkbookHelper::getBaseFilter() const 605cdf0e10cSrcweir { 606cdf0e10cSrcweir return mrBookGlob.getBaseFilter(); 607cdf0e10cSrcweir } 608cdf0e10cSrcweir 609cdf0e10cSrcweir FilterType WorkbookHelper::getFilterType() const 610cdf0e10cSrcweir { 611cdf0e10cSrcweir return mrBookGlob.getFilterType(); 612cdf0e10cSrcweir } 613cdf0e10cSrcweir 614cdf0e10cSrcweir SegmentProgressBar& WorkbookHelper::getProgressBar() const 615cdf0e10cSrcweir { 616cdf0e10cSrcweir return mrBookGlob.getProgressBar(); 617cdf0e10cSrcweir } 618cdf0e10cSrcweir 619cdf0e10cSrcweir bool WorkbookHelper::isWorkbookFile() const 620cdf0e10cSrcweir { 621cdf0e10cSrcweir return mrBookGlob.isWorkbookFile(); 622cdf0e10cSrcweir } 623cdf0e10cSrcweir 624cdf0e10cSrcweir sal_Int16 WorkbookHelper::getCurrentSheetIndex() const 625cdf0e10cSrcweir { 626cdf0e10cSrcweir return mrBookGlob.getCurrentSheetIndex(); 627cdf0e10cSrcweir } 628cdf0e10cSrcweir 629cdf0e10cSrcweir void WorkbookHelper::setVbaProjectStorage( const StorageRef& rxVbaPrjStrg ) 630cdf0e10cSrcweir { 631cdf0e10cSrcweir mrBookGlob.setVbaProjectStorage( rxVbaPrjStrg ); 632cdf0e10cSrcweir } 633cdf0e10cSrcweir 634cdf0e10cSrcweir void WorkbookHelper::setCurrentSheetIndex( sal_Int16 nSheet ) 635cdf0e10cSrcweir { 636cdf0e10cSrcweir mrBookGlob.setCurrentSheetIndex( nSheet ); 637cdf0e10cSrcweir } 638cdf0e10cSrcweir 639cdf0e10cSrcweir void WorkbookHelper::finalizeWorkbookImport() 640cdf0e10cSrcweir { 641cdf0e10cSrcweir // workbook settings, document and sheet view settings 642cdf0e10cSrcweir mrBookGlob.getWorkbookSettings().finalizeImport(); 643cdf0e10cSrcweir mrBookGlob.getViewSettings().finalizeImport(); 644cdf0e10cSrcweir 645cdf0e10cSrcweir /* Insert all pivot tables. Must be done after loading all sheets, because 646cdf0e10cSrcweir data pilots expect existing source data on creation. */ 647cdf0e10cSrcweir mrBookGlob.getPivotTables().finalizeImport(); 648cdf0e10cSrcweir 649cdf0e10cSrcweir /* Insert scenarios after all sheet processing is done, because new hidden 650cdf0e10cSrcweir sheets are created for scenarios which would confuse code that relies 651cdf0e10cSrcweir on certain sheet indexes. Must be done after pivot tables too. */ 652cdf0e10cSrcweir mrBookGlob.getScenarios().finalizeImport(); 653cdf0e10cSrcweir 654cdf0e10cSrcweir /* Set 'Default' page style to automatic page numbering (default is manual 655cdf0e10cSrcweir number 1). Otherwise hidden sheets (e.g. for scenarios) which have 656cdf0e10cSrcweir 'Default' page style will break automatic page numbering for following 657cdf0e10cSrcweir sheets. Automatic numbering is set by passing the value 0. */ 658cdf0e10cSrcweir PropertySet aDefPageStyle( getStyleObject( CREATE_OUSTRING( "Default" ), true ) ); 659cdf0e10cSrcweir aDefPageStyle.setProperty< sal_Int16 >( PROP_FirstPageNumber, 0 ); 660cdf0e10cSrcweir 661cdf0e10cSrcweir /* Import the VBA project (after finalizing workbook settings which 662cdf0e10cSrcweir contains the workbook code name). */ 663cdf0e10cSrcweir StorageRef xVbaPrjStrg = mrBookGlob.getVbaProjectStorage(); 664cdf0e10cSrcweir if( xVbaPrjStrg.get() && xVbaPrjStrg->isStorage() ) 665cdf0e10cSrcweir getBaseFilter().getVbaProject().importVbaProject( *xVbaPrjStrg, getBaseFilter().getGraphicHelper() ); 666cdf0e10cSrcweir } 667cdf0e10cSrcweir 668cdf0e10cSrcweir // document model ------------------------------------------------------------- 669cdf0e10cSrcweir 670cdf0e10cSrcweir Reference< XSpreadsheetDocument > WorkbookHelper::getDocument() const 671cdf0e10cSrcweir { 672cdf0e10cSrcweir return mrBookGlob.getDocument(); 673cdf0e10cSrcweir } 674cdf0e10cSrcweir 675cdf0e10cSrcweir Reference< XSpreadsheet > WorkbookHelper::getSheetFromDoc( sal_Int16 nSheet ) const 676cdf0e10cSrcweir { 677cdf0e10cSrcweir Reference< XSpreadsheet > xSheet; 678cdf0e10cSrcweir try 679cdf0e10cSrcweir { 680cdf0e10cSrcweir Reference< XIndexAccess > xSheetsIA( getDocument()->getSheets(), UNO_QUERY_THROW ); 681cdf0e10cSrcweir xSheet.set( xSheetsIA->getByIndex( nSheet ), UNO_QUERY_THROW ); 682cdf0e10cSrcweir } 683cdf0e10cSrcweir catch( Exception& ) 684cdf0e10cSrcweir { 685cdf0e10cSrcweir } 686cdf0e10cSrcweir return xSheet; 687cdf0e10cSrcweir } 688cdf0e10cSrcweir 689cdf0e10cSrcweir Reference< XSpreadsheet > WorkbookHelper::getSheetFromDoc( const OUString& rSheet ) const 690cdf0e10cSrcweir { 691cdf0e10cSrcweir Reference< XSpreadsheet > xSheet; 692cdf0e10cSrcweir try 693cdf0e10cSrcweir { 694cdf0e10cSrcweir Reference< XNameAccess > xSheetsNA( getDocument()->getSheets(), UNO_QUERY_THROW ); 695cdf0e10cSrcweir xSheet.set( xSheetsNA->getByName( rSheet ), UNO_QUERY ); 696cdf0e10cSrcweir } 697cdf0e10cSrcweir catch( Exception& ) 698cdf0e10cSrcweir { 699cdf0e10cSrcweir } 700cdf0e10cSrcweir return xSheet; 701cdf0e10cSrcweir } 702cdf0e10cSrcweir 703cdf0e10cSrcweir Reference< XCell > WorkbookHelper::getCellFromDoc( const CellAddress& rAddress ) const 704cdf0e10cSrcweir { 705cdf0e10cSrcweir Reference< XCell > xCell; 706cdf0e10cSrcweir try 707cdf0e10cSrcweir { 708cdf0e10cSrcweir Reference< XSpreadsheet > xSheet( getSheetFromDoc( rAddress.Sheet ), UNO_SET_THROW ); 709cdf0e10cSrcweir xCell = xSheet->getCellByPosition( rAddress.Column, rAddress.Row ); 710cdf0e10cSrcweir } 711cdf0e10cSrcweir catch( Exception& ) 712cdf0e10cSrcweir { 713cdf0e10cSrcweir } 714cdf0e10cSrcweir return xCell; 715cdf0e10cSrcweir } 716cdf0e10cSrcweir 717cdf0e10cSrcweir Reference< XCellRange > WorkbookHelper::getCellRangeFromDoc( const CellRangeAddress& rRange ) const 718cdf0e10cSrcweir { 719cdf0e10cSrcweir Reference< XCellRange > xRange; 720cdf0e10cSrcweir try 721cdf0e10cSrcweir { 722cdf0e10cSrcweir Reference< XSpreadsheet > xSheet( getSheetFromDoc( rRange.Sheet ), UNO_SET_THROW ); 723cdf0e10cSrcweir xRange = xSheet->getCellRangeByPosition( rRange.StartColumn, rRange.StartRow, rRange.EndColumn, rRange.EndRow ); 724cdf0e10cSrcweir } 725cdf0e10cSrcweir catch( Exception& ) 726cdf0e10cSrcweir { 727cdf0e10cSrcweir } 728cdf0e10cSrcweir return xRange; 729cdf0e10cSrcweir } 730cdf0e10cSrcweir 731cdf0e10cSrcweir Reference< XNameContainer > WorkbookHelper::getStyleFamily( bool bPageStyles ) const 732cdf0e10cSrcweir { 733cdf0e10cSrcweir return mrBookGlob.getStyleFamily( bPageStyles ); 734cdf0e10cSrcweir } 735cdf0e10cSrcweir 736cdf0e10cSrcweir Reference< XStyle > WorkbookHelper::getStyleObject( const OUString& rStyleName, bool bPageStyle ) const 737cdf0e10cSrcweir { 738cdf0e10cSrcweir return mrBookGlob.getStyleObject( rStyleName, bPageStyle ); 739cdf0e10cSrcweir } 740cdf0e10cSrcweir 741*dffa72deSWang Lei Reference< XNamedRange > WorkbookHelper::createNamedRangeObject( OUString& orName, sal_Int32 nSheetId, sal_Int32 nNameFlags ) const 742cdf0e10cSrcweir { 743*dffa72deSWang Lei OUString orScope = nSheetId >= 0? getWorksheets().getCalcSheetName(nSheetId) : OUString(); 744*dffa72deSWang Lei return mrBookGlob.createNamedRangeObject( orScope, orName, nNameFlags ); 745cdf0e10cSrcweir } 746cdf0e10cSrcweir 747cdf0e10cSrcweir Reference< XDatabaseRange > WorkbookHelper::createDatabaseRangeObject( OUString& orName, const CellRangeAddress& rRangeAddr ) const 748cdf0e10cSrcweir { 749cdf0e10cSrcweir return mrBookGlob.createDatabaseRangeObject( orName, rRangeAddr ); 750cdf0e10cSrcweir } 751cdf0e10cSrcweir 752cdf0e10cSrcweir Reference< XStyle > WorkbookHelper::createStyleObject( OUString& orStyleName, bool bPageStyle ) const 753cdf0e10cSrcweir { 754cdf0e10cSrcweir return mrBookGlob.createStyleObject( orStyleName, bPageStyle ); 755cdf0e10cSrcweir } 756cdf0e10cSrcweir 757cdf0e10cSrcweir // buffers -------------------------------------------------------------------- 758cdf0e10cSrcweir 759cdf0e10cSrcweir WorkbookSettings& WorkbookHelper::getWorkbookSettings() const 760cdf0e10cSrcweir { 761cdf0e10cSrcweir return mrBookGlob.getWorkbookSettings(); 762cdf0e10cSrcweir } 763cdf0e10cSrcweir 764cdf0e10cSrcweir ViewSettings& WorkbookHelper::getViewSettings() const 765cdf0e10cSrcweir { 766cdf0e10cSrcweir return mrBookGlob.getViewSettings(); 767cdf0e10cSrcweir } 768cdf0e10cSrcweir 769cdf0e10cSrcweir WorksheetBuffer& WorkbookHelper::getWorksheets() const 770cdf0e10cSrcweir { 771cdf0e10cSrcweir return mrBookGlob.getWorksheets(); 772cdf0e10cSrcweir } 773cdf0e10cSrcweir 774cdf0e10cSrcweir ThemeBuffer& WorkbookHelper::getTheme() const 775cdf0e10cSrcweir { 776cdf0e10cSrcweir return mrBookGlob.getTheme(); 777cdf0e10cSrcweir } 778cdf0e10cSrcweir 779cdf0e10cSrcweir StylesBuffer& WorkbookHelper::getStyles() const 780cdf0e10cSrcweir { 781cdf0e10cSrcweir return mrBookGlob.getStyles(); 782cdf0e10cSrcweir } 783cdf0e10cSrcweir 784cdf0e10cSrcweir SharedStringsBuffer& WorkbookHelper::getSharedStrings() const 785cdf0e10cSrcweir { 786cdf0e10cSrcweir return mrBookGlob.getSharedStrings(); 787cdf0e10cSrcweir } 788cdf0e10cSrcweir 789cdf0e10cSrcweir ExternalLinkBuffer& WorkbookHelper::getExternalLinks() const 790cdf0e10cSrcweir { 791cdf0e10cSrcweir return mrBookGlob.getExternalLinks(); 792cdf0e10cSrcweir } 793cdf0e10cSrcweir 794cdf0e10cSrcweir DefinedNamesBuffer& WorkbookHelper::getDefinedNames() const 795cdf0e10cSrcweir { 796cdf0e10cSrcweir return mrBookGlob.getDefinedNames(); 797cdf0e10cSrcweir } 798cdf0e10cSrcweir 799cdf0e10cSrcweir TableBuffer& WorkbookHelper::getTables() const 800cdf0e10cSrcweir { 801cdf0e10cSrcweir return mrBookGlob.getTables(); 802cdf0e10cSrcweir } 803cdf0e10cSrcweir 804cdf0e10cSrcweir ScenarioBuffer& WorkbookHelper::getScenarios() const 805cdf0e10cSrcweir { 806cdf0e10cSrcweir return mrBookGlob.getScenarios(); 807cdf0e10cSrcweir } 808cdf0e10cSrcweir 809cdf0e10cSrcweir ConnectionsBuffer& WorkbookHelper::getConnections() const 810cdf0e10cSrcweir { 811cdf0e10cSrcweir return mrBookGlob.getConnections(); 812cdf0e10cSrcweir } 813cdf0e10cSrcweir 814cdf0e10cSrcweir PivotCacheBuffer& WorkbookHelper::getPivotCaches() const 815cdf0e10cSrcweir { 816cdf0e10cSrcweir return mrBookGlob.getPivotCaches(); 817cdf0e10cSrcweir } 818cdf0e10cSrcweir 819cdf0e10cSrcweir PivotTableBuffer& WorkbookHelper::getPivotTables() const 820cdf0e10cSrcweir { 821cdf0e10cSrcweir return mrBookGlob.getPivotTables(); 822cdf0e10cSrcweir } 823cdf0e10cSrcweir 824cdf0e10cSrcweir // converters ----------------------------------------------------------------- 825cdf0e10cSrcweir 826cdf0e10cSrcweir FormulaParser& WorkbookHelper::getFormulaParser() const 827cdf0e10cSrcweir { 828cdf0e10cSrcweir return mrBookGlob.getFormulaParser(); 829cdf0e10cSrcweir } 830cdf0e10cSrcweir 831cdf0e10cSrcweir UnitConverter& WorkbookHelper::getUnitConverter() const 832cdf0e10cSrcweir { 833cdf0e10cSrcweir return mrBookGlob.getUnitConverter(); 834cdf0e10cSrcweir } 835cdf0e10cSrcweir 836cdf0e10cSrcweir AddressConverter& WorkbookHelper::getAddressConverter() const 837cdf0e10cSrcweir { 838cdf0e10cSrcweir return mrBookGlob.getAddressConverter(); 839cdf0e10cSrcweir } 840cdf0e10cSrcweir 841cdf0e10cSrcweir ExcelChartConverter& WorkbookHelper::getChartConverter() const 842cdf0e10cSrcweir { 843cdf0e10cSrcweir return mrBookGlob.getChartConverter(); 844cdf0e10cSrcweir } 845cdf0e10cSrcweir 846cdf0e10cSrcweir PageSettingsConverter& WorkbookHelper::getPageSettingsConverter() const 847cdf0e10cSrcweir { 848cdf0e10cSrcweir return mrBookGlob.getPageSettingsConverter(); 849cdf0e10cSrcweir } 850cdf0e10cSrcweir 851cdf0e10cSrcweir // OOXML/BIFF12 specific ------------------------------------------------------ 852cdf0e10cSrcweir 853cdf0e10cSrcweir XmlFilterBase& WorkbookHelper::getOoxFilter() const 854cdf0e10cSrcweir { 855cdf0e10cSrcweir OSL_ENSURE( mrBookGlob.getFilterType() == FILTER_OOXML, "WorkbookHelper::getOoxFilter - invalid call" ); 856cdf0e10cSrcweir return mrBookGlob.getOoxFilter(); 857cdf0e10cSrcweir } 858cdf0e10cSrcweir 859cdf0e10cSrcweir bool WorkbookHelper::importOoxFragment( const ::rtl::Reference< FragmentHandler >& rxHandler ) 860cdf0e10cSrcweir { 861cdf0e10cSrcweir return getOoxFilter().importFragment( rxHandler ); 862cdf0e10cSrcweir } 863cdf0e10cSrcweir 864cdf0e10cSrcweir // BIFF specific -------------------------------------------------------------- 865cdf0e10cSrcweir 866cdf0e10cSrcweir BinaryFilterBase& WorkbookHelper::getBiffFilter() const 867cdf0e10cSrcweir { 868cdf0e10cSrcweir OSL_ENSURE( mrBookGlob.getFilterType() == FILTER_BIFF, "WorkbookHelper::getBiffFilter - invalid call" ); 869cdf0e10cSrcweir return mrBookGlob.getBiffFilter(); 870cdf0e10cSrcweir } 871cdf0e10cSrcweir 872cdf0e10cSrcweir BiffType WorkbookHelper::getBiff() const 873cdf0e10cSrcweir { 874cdf0e10cSrcweir return mrBookGlob.getBiff(); 875cdf0e10cSrcweir } 876cdf0e10cSrcweir 877cdf0e10cSrcweir rtl_TextEncoding WorkbookHelper::getTextEncoding() const 878cdf0e10cSrcweir { 879cdf0e10cSrcweir return mrBookGlob.getTextEncoding(); 880cdf0e10cSrcweir } 881cdf0e10cSrcweir 882cdf0e10cSrcweir void WorkbookHelper::setTextEncoding( rtl_TextEncoding eTextEnc ) 883cdf0e10cSrcweir { 884cdf0e10cSrcweir mrBookGlob.setTextEncoding( eTextEnc ); 885cdf0e10cSrcweir } 886cdf0e10cSrcweir 887cdf0e10cSrcweir void WorkbookHelper::setCodePage( sal_uInt16 nCodePage ) 888cdf0e10cSrcweir { 889cdf0e10cSrcweir mrBookGlob.setCodePage( nCodePage ); 890cdf0e10cSrcweir } 891cdf0e10cSrcweir 892cdf0e10cSrcweir void WorkbookHelper::setAppFontEncoding( rtl_TextEncoding eAppFontEnc ) 893cdf0e10cSrcweir { 894cdf0e10cSrcweir mrBookGlob.setAppFontEncoding( eAppFontEnc ); 895cdf0e10cSrcweir } 896cdf0e10cSrcweir 897cdf0e10cSrcweir void WorkbookHelper::setIsWorkbookFile() 898cdf0e10cSrcweir { 899cdf0e10cSrcweir mrBookGlob.setIsWorkbookFile(); 900cdf0e10cSrcweir } 901cdf0e10cSrcweir 902cdf0e10cSrcweir void WorkbookHelper::createBuffersPerSheet( sal_Int16 nSheet ) 903cdf0e10cSrcweir { 904cdf0e10cSrcweir mrBookGlob.createBuffersPerSheet( nSheet ); 905cdf0e10cSrcweir } 906cdf0e10cSrcweir 907cdf0e10cSrcweir BiffCodecHelper& WorkbookHelper::getCodecHelper() const 908cdf0e10cSrcweir { 909cdf0e10cSrcweir return mrBookGlob.getCodecHelper(); 910cdf0e10cSrcweir } 911cdf0e10cSrcweir 912cdf0e10cSrcweir // ============================================================================ 913cdf0e10cSrcweir 914cdf0e10cSrcweir } // namespace xls 915cdf0e10cSrcweir } // namespace oox 916