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