diff options
author | Daniel Rentz [dr] <daniel.rentz@oracle.com> | 2011-02-11 16:11:43 +0100 |
---|---|---|
committer | Daniel Rentz [dr] <daniel.rentz@oracle.com> | 2011-02-11 16:11:43 +0100 |
commit | f042519085109581abcdff4403e7e6d9999d4980 (patch) | |
tree | d3f22e98804fa22c88b62d7ea42553a32df09230 /oox/inc | |
parent | aec1b58b2f959770f072778ec187ae89f6053b76 (diff) |
dr78: #164376# oox import performance: step 2 - move every access to XCell interface into SheetDataBuffer class, delay creation of array formulas and table operations, let XCellRangeData::setDataArray() accept formula token sequences in addition to plain values
Diffstat (limited to 'oox/inc')
-rw-r--r-- | oox/inc/oox/xls/defnamesbuffer.hxx | 6 | ||||
-rwxr-xr-x | oox/inc/oox/xls/sheetdatabuffer.hxx | 133 | ||||
-rw-r--r-- | oox/inc/oox/xls/sheetdatacontext.hxx | 84 | ||||
-rw-r--r-- | oox/inc/oox/xls/worksheethelper.hxx | 47 |
4 files changed, 142 insertions, 128 deletions
diff --git a/oox/inc/oox/xls/defnamesbuffer.hxx b/oox/inc/oox/xls/defnamesbuffer.hxx index 27f9f13f6e87..f26a51a1f04c 100644 --- a/oox/inc/oox/xls/defnamesbuffer.hxx +++ b/oox/inc/oox/xls/defnamesbuffer.hxx @@ -94,11 +94,11 @@ public: protected: /** Converts the OOXML formula string stored in the own model. */ - ApiTokenSequence importOoxFormula( const ::com::sun::star::table::CellAddress& rBaseAddr ); + ApiTokenSequence importOoxFormula( sal_Int16 nBaseSheet ); /** Imports the BIFF12 formula from the passed stream. */ - ApiTokenSequence importBiff12Formula( const ::com::sun::star::table::CellAddress& rBaseAddr, SequenceInputStream& rStrm ); + ApiTokenSequence importBiff12Formula( sal_Int16 nBaseSheet, SequenceInputStream& rStrm ); /** Imports the BIFF formula from the passed stream. */ - ApiTokenSequence importBiffFormula( const ::com::sun::star::table::CellAddress& rBaseAddr, BiffInputStream& rStrm, const sal_uInt16* pnFmlaSize = 0 ); + ApiTokenSequence importBiffFormula( sal_Int16 nBaseSheet, BiffInputStream& rStrm, const sal_uInt16* pnFmlaSize = 0 ); /** Tries to convert the passed token sequence to a SingleReference or ComplexReference. */ void extractReference( const ApiTokenSequence& rTokens ); diff --git a/oox/inc/oox/xls/sheetdatabuffer.hxx b/oox/inc/oox/xls/sheetdatabuffer.hxx index 52b71b4f0ef9..878d225ff81f 100755 --- a/oox/inc/oox/xls/sheetdatabuffer.hxx +++ b/oox/inc/oox/xls/sheetdatabuffer.hxx @@ -42,6 +42,53 @@ namespace xls { // ============================================================================ +/** Stores basic data about cell values and formatting. */ +struct CellModel +{ + ::com::sun::star::table::CellAddress + maCellAddr; /// The address of the current cell. + sal_Int32 mnCellType; /// Data type of the cell value. + sal_Int32 mnXfId; /// XF (cell formatting) identifier. + bool mbShowPhonetic; /// True = show phonetic text. + + explicit CellModel(); +}; + +// ---------------------------------------------------------------------------- + +/** Stores data about cell formulas. */ +struct CellFormulaModel +{ + ::com::sun::star::table::CellRangeAddress + maFormulaRef; /// Formula range for array/shared formulas and data tables. + sal_Int32 mnFormulaType; /// Type of the formula (regular, array, shared, table). + sal_Int32 mnSharedId; /// Identifier of a shared formula (OOXML only). + + explicit CellFormulaModel(); + + /** Returns true, if the passed cell address is valid for an array formula. */ + bool isValidArrayRef( const ::com::sun::star::table::CellAddress& rCellAddr ); + /** Returns true, if the passed cell address is valid for a shared formula. */ + bool isValidSharedRef( const ::com::sun::star::table::CellAddress& rCellAddr ); +}; + +// ---------------------------------------------------------------------------- + +/** Stores data about table operations. */ +struct DataTableModel +{ + ::rtl::OUString maRef1; /// First reference cell for table operations. + ::rtl::OUString maRef2; /// Second reference cell for table operations. + bool mb2dTable; /// True = 2-dimensional data table. + bool mbRowTable; /// True = row oriented data table. + bool mbRef1Deleted; /// True = first reference cell deleted. + bool mbRef2Deleted; /// True = second reference cell deleted. + + explicit DataTableModel(); +}; + +// ============================================================================ + /** Manages the cell contents and cell formatting of a sheet. */ class SheetDataBuffer : public WorksheetHelper @@ -49,81 +96,71 @@ class SheetDataBuffer : public WorksheetHelper public: explicit SheetDataBuffer( const WorksheetHelper& rHelper ); - /** Imports a shared formula from a OOXML formula string. */ - void importSharedFmla( const ::rtl::OUString& rFormula, - const ::rtl::OUString& rSharedRange, sal_Int32 nSharedId, - const ::com::sun::star::table::CellAddress& rBaseAddr ); - /** Imports a shared formula from a SHAREDFORMULA record in the passed stream */ - void importSharedFmla( SequenceInputStream& rStrm, - const ::com::sun::star::table::CellAddress& rBaseAddr ); - /** Imports a shared formula from a SHAREDFMLA record in the passed stream. */ - void importSharedFmla( BiffInputStream& rStrm, - const ::com::sun::star::table::CellAddress& rBaseAddr ); - /** Sets the passed value to the cell. */ void setValueCell( - const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >& rxCell, const ::com::sun::star::table::CellAddress& rCellAddr, double fValue ); /** Sets the passed string to the cell. */ void setStringCell( - const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >& rxCell, const ::com::sun::star::table::CellAddress& rCellAddr, const ::rtl::OUString& rText ); /** Sets the passed rich-string to the cell. */ void setStringCell( - const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >& rxCell, const ::com::sun::star::table::CellAddress& rCellAddr, const RichString& rString, sal_Int32 nXfId ); /** Sets the shared string with the passed identifier to the cell. */ void setStringCell( - const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >& rxCell, const ::com::sun::star::table::CellAddress& rCellAddr, sal_Int32 nStringId, sal_Int32 nXfId ); /** Sets the passed date/time value to the cell and adjusts number format. */ void setDateTimeCell( - const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >& rxCell, const ::com::sun::star::table::CellAddress& rCellAddr, const ::com::sun::star::util::DateTime& rDateTime ); /** Sets the passed boolean value to the cell and adjusts number format. */ void setBooleanCell( - const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >& rxCell, const ::com::sun::star::table::CellAddress& rCellAddr, bool bValue ); /** Sets the passed BIFF error code to the cell (by converting it to a formula). */ void setErrorCell( - const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >& rxCell, const ::com::sun::star::table::CellAddress& rCellAddr, const ::rtl::OUString& rErrorCode ); /** Sets the passed BIFF error code to the cell (by converting it to a formula). */ void setErrorCell( - const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >& rxCell, const ::com::sun::star::table::CellAddress& rCellAddr, sal_uInt8 nErrorCode ); /** Sets the passed formula token sequence to the cell. */ void setFormulaCell( - const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >& rxCell, const ::com::sun::star::table::CellAddress& rCellAddr, const ApiTokenSequence& rTokens ); /** Sets the shared formula with the passed identifier to the cell (OOXML only). */ void setFormulaCell( - const ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >& rxCell, const ::com::sun::star::table::CellAddress& rCellAddr, sal_Int32 nSharedId ); /** Inserts the passed token array as array formula. */ - void setArrayFormula( + void createArrayFormula( const ::com::sun::star::table::CellRangeAddress& rRange, const ApiTokenSequence& rTokens ); /** Sets a multiple table operation to the passed range. */ - void setTableOperation( + void createTableOperation( const ::com::sun::star::table::CellRangeAddress& rRange, const DataTableModel& rModel ); + /** Creates a named range with a special name for a shared formula with the + specified identifier and formula definition (OOXML only). */ + void createSharedFormula( + sal_Int32 nSharedId, + const ApiTokenSequence& rTokens ); + /** Creates a named range with a special name for a shared formula with the + specified base address and formula definition (BIFF only). */ + void createSharedFormula( + const ::com::sun::star::table::CellAddress& rCellAddr, + const ApiTokenSequence& rTokens ); /** Sets default cell formatting for the specified range of rows. */ void setRowFormat( sal_Int32 nFirstRow, sal_Int32 nLastRow, sal_Int32 nXfId, bool bCustomFormat ); - /** Processes the cell formatting data of the passed cell. */ - void setCellFormat( const CellModel& rModel ); + /** Processes the cell formatting data of the passed cell. + @param nNumFmtId If set, overrides number format of the cell XF. */ + void setCellFormat( const CellModel& rModel, sal_Int32 nNumFmtId = -1 ); /** Merges the cells in the passed cell range. */ void setMergedRange( const ::com::sun::star::table::CellRangeAddress& rRange ); /** Sets a standard number format (constant from com.sun.star.util.NumberFormat) to the specified cell. */ @@ -138,21 +175,21 @@ private: struct XfIdRowRange; struct XfIdRange; - /** Creates and returns an empty named range with a special name for a - shared formula with the specified base position. */ - ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XNamedRange > - createSharedFormulaName( const BinAddress& rMapKey ); + /** Inserts the passed array formula into the sheet. */ + void finalizeArrayFormula( + const ::com::sun::star::table::CellRangeAddress& rRange, + const ApiTokenSequence& rTokens ); + /** Inserts the passed table operation into the sheet. */ + void finalizeTableOperation( + const ::com::sun::star::table::CellRangeAddress& rRange, + const DataTableModel& rModel ); + /** Creates a named range with a special name for a shared formula with the + specified base address and formula definition. */ + void createSharedFormula( const BinAddress& rMapKey, const ApiTokenSequence& rTokens ); /** Creates a formula token array representing the shared formula with the - passed identifier (OOXML only). */ - ApiTokenSequence resolveSharedFormula( sal_Int32 nSharedId ) const; - /** Creates a formula token array representing the shared formula at the - passed base address. */ - ApiTokenSequence resolveSharedFormula( const ::com::sun::star::table::CellAddress& rBaseAddr ) const; - - /** Retries to insert a shared formula that has not been set in the last - call to setFormulaCell() due to the missing formula definition. */ - void retryPendingSharedFormulaCell(); + passed identifier. */ + ApiTokenSequence resolveSharedFormula( const BinAddress& rMapKey ) const; /** Writes all cell formatting attributes to the passed row range. */ void writeXfIdRowRangeProperties( const XfIdRowRange& rXfIdRowRange ) const; @@ -165,6 +202,9 @@ private: void finalizeMergedRange( const ::com::sun::star::table::CellRangeAddress& rRange ); private: + typedef ::std::pair< ::com::sun::star::table::CellRangeAddress, ApiTokenSequence > ArrayFormula; + typedef ::std::pair< ::com::sun::star::table::CellRangeAddress, DataTableModel > TableOperation; + struct XfIdRowRange { sal_Int32 mnFirstRow; /// Index of first row. @@ -182,10 +222,10 @@ private: ::com::sun::star::table::CellRangeAddress maRange; /// The formatted cell range. sal_Int32 mnXfId; /// XF identifier for the range. - sal_Int32 mnNumFmtId; /// Number format id overriding the XF. + sal_Int32 mnNumFmtId; /// Number format overriding the XF. - void set( const CellModel& rModel ); - bool tryExpand( const CellModel& rModel ); + void set( const CellModel& rModel, sal_Int32 nNumFmtId ); + bool tryExpand( const CellModel& rModel, sal_Int32 nNumFmtId ); bool tryMerge( const XfIdRange& rXfIdRange ); }; @@ -200,15 +240,18 @@ private: bool tryExpand( const ::com::sun::star::table::CellAddress& rAddress, sal_Int32 nHorAlign ); }; - typedef ::std::map< BinAddress, sal_Int32 > TokenIndexMap; + typedef ::std::list< ArrayFormula > ArrayFormulaList; + typedef ::std::list< TableOperation > TableOperationList; + typedef ::std::map< BinAddress, sal_Int32 > SharedFormulaMap; typedef ::std::map< BinAddress, XfIdRange > XfIdRangeMap; typedef ::std::list< MergedRange > MergedRangeList; - TokenIndexMap maTokenIndexes; /// Maps shared formula base address to defined name token index. + ArrayFormulaList maArrayFormulas; /// All array formulas in the sheet. + TableOperationList maTableOperations; /// All table operations in the sheet. + SharedFormulaMap maSharedFormulas; /// Maps shared formula base address to defined name token index. ::com::sun::star::table::CellAddress maSharedFmlaAddr; /// Address of a cell containing a pending shared formula. - ::com::sun::star::table::CellAddress - maSharedBaseAddr; /// Base address of the pending shared formula. + BinAddress maSharedBaseAddr; /// Base address of the pending shared formula. XfIdRowRange maXfIdRowRange; /// Cached XF identifier for a range of rows. XfIdRangeMap maXfIdRanges; /// Collected XF identifiers for cell ranges. MergedRangeList maMergedRanges; /// Merged cell ranges. diff --git a/oox/inc/oox/xls/sheetdatacontext.hxx b/oox/inc/oox/xls/sheetdatacontext.hxx index c01106228c72..60948ab9f70d 100644 --- a/oox/inc/oox/xls/sheetdatacontext.hxx +++ b/oox/inc/oox/xls/sheetdatacontext.hxx @@ -30,22 +30,37 @@ #include "oox/xls/excelhandlers.hxx" #include "oox/xls/richstring.hxx" - -namespace com { namespace sun { namespace star { - namespace table { class XCell; } -} } } +#include "oox/xls/sheetdatabuffer.hxx" namespace oox { namespace xls { // ============================================================================ +/** Used as base for sheet data context classes. Provides fast access to often + used converter objects and sheet index, to improve performance. + */ +struct SheetDataContextBase +{ + AddressConverter& mrAddressConv; /// The address converter. + FormulaParser& mrFormulaParser; /// The formula parser. + SheetDataBuffer& mrSheetData; /// The sheet data buffer for cell content and formatting. + CellModel maCellData; /// Position, contents, formatting of current imported cell. + CellFormulaModel maFmlaData; /// Settings for a cell formula. + sal_Int16 mnSheet; /// Index of the current sheet. + + explicit SheetDataContextBase( const WorksheetHelper& rHelper ); + virtual ~SheetDataContextBase(); +}; + +// ============================================================================ + /** This class implements importing the sheetData element. The sheetData element contains all row settings and all cells in a single sheet of a spreadsheet document. */ -class SheetDataContext : public WorksheetContextBase +class SheetDataContext : public WorksheetContextBase, private SheetDataContextBase { public: explicit SheetDataContext( WorksheetFragmentBase& rFragment ); @@ -64,12 +79,20 @@ private: /** Imports row settings from a row element. */ void importRow( const AttributeList& rAttribs ); /** Imports cell settings from a c element. */ - void importCell( const AttributeList& rAttribs ); + bool importCell( const AttributeList& rAttribs ); /** Imports cell settings from an f element. */ void importFormula( const AttributeList& rAttribs ); - /** Imports a cell address and the following XF identifier. */ - void importCellHeader( SequenceInputStream& rStrm, CellType eCellType ); + /** Imports row settings from a ROW record. */ + void importRow( SequenceInputStream& rStrm ); + + /** Reads a cell address and the following XF identifier. */ + bool readCellHeader( SequenceInputStream& rStrm, CellType eCellType ); + /** Reads a cell formula for the current cell. */ + ApiTokenSequence readCellFormula( SequenceInputStream& rStrm ); + /** Reads the formula range used by shared formulas, arrays, and data tables. */ + bool readFormulaRef( SequenceInputStream& rStrm ); + /** Imports an empty cell from a CELL_BLANK or MULTCELL_BLANK record. */ void importCellBlank( SequenceInputStream& rStrm, CellType eCellType ); /** Imports a boolean cell from a CELL_BOOL, MULTCELL_BOOL, or FORMULA_BOOL record. */ @@ -87,31 +110,28 @@ private: /** Imports a string cell from a CELL_STRING, MULTCELL_STRING, or FORMULA_STRING record. */ void importCellString( SequenceInputStream& rStrm, CellType eCellType ); - /** Imports a cell formula for the current cell. */ - void importCellFormula( SequenceInputStream& rStrm ); - - /** Imports row settings from a ROW record. */ - void importRow( SequenceInputStream& rStrm ); /** Imports an array formula from an ARRAY record. */ void importArray( SequenceInputStream& rStrm ); - /** Imports a shared formula from a SHAREDFORMULA record. */ - void importSharedFmla( SequenceInputStream& rStrm ); /** Imports table operation from a DATATABLE record. */ void importDataTable( SequenceInputStream& rStrm ); + /** Imports a shared formula from a SHAREDFORMULA record. */ + void importSharedFmla( SequenceInputStream& rStrm ); private: - SheetDataBuffer& mrSheetData; /// The sheet data buffer for cell content and formatting. - CellModel maCurrCell; /// Position and formatting of current imported cell. - DataTableModel maTableData; /// Additional data for table operation ranges. - BinAddress maCurrPos; /// Current position for binary import. - RichStringRef mxInlineStr; /// Inline rich string from 'is' element. + ::rtl::OUString maCellValue; /// Cell value string (OOXML only). + RichStringRef mxInlineStr; /// Inline rich string (OOXML only). + ApiTokenSequence maTokens; /// Formula token array (OOXML only). + DataTableModel maTableData; /// Settings for table operations. + BinAddress maCurrPos; /// Current cell position (BIFF12 only). + bool mbHasFormula; /// True = current cell has formula data (OOXML only). + bool mbValidRange; /// True = maFmlaData.maFormulaRef is valid (OOXML only). }; // ============================================================================ /** This class implements importing row settings and all cells of a sheet. */ -class BiffSheetDataContext : public BiffWorksheetContextBase +class BiffSheetDataContext : public BiffWorksheetContextBase, private SheetDataContextBase { public: explicit BiffSheetDataContext( const WorksheetHelper& rHelper ); @@ -120,13 +140,15 @@ public: virtual void importRecord( BiffInputStream& rStrm ); private: - /** Sets current cell according to the passed address. */ - void setCurrCell( const BinAddress& rAddr ); + /** Imports row settings from a ROW record. */ + void importRow( BiffInputStream& rStrm ); - /** Imports an XF identifier and sets the mnXfId member. */ - void importXfId( BiffInputStream& rStrm, bool bBiff2 ); - /** Imports a BIFF cell address and the following XF identifier. */ - void importCellHeader( BiffInputStream& rStrm, bool bBiff2 ); + /** Reads an XF identifier and initializes a new cell. */ + bool readCellXfId( const BinAddress& rAddr, BiffInputStream& rStrm, bool bBiff2 ); + /** Reads a BIFF cell address and the following XF identifier. */ + bool readCellHeader( BiffInputStream& rStrm, bool bBiff2 ); + /** Reads the formula range used by shared formulas, arrays, and data tables. */ + bool readFormulaRef( BiffInputStream& rStrm ); /** Imports a BLANK record describing a blank but formatted cell. */ void importBlank( BiffInputStream& rStrm ); @@ -149,18 +171,14 @@ private: /** Imports an RK record describing a numeric cell. */ void importRk( BiffInputStream& rStrm ); - /** Imports row settings from a ROW record. */ - void importRow( BiffInputStream& rStrm ); /** Imports an ARRAY record describing an array formula of a cell range. */ void importArray( BiffInputStream& rStrm ); - /** Imports a SHAREDFMLA record describing a shared formula in a cell range. */ - void importSharedFmla( BiffInputStream& rStrm ); /** Imports table operation from a DATATABLE or DATATABLE2 record. */ void importDataTable( BiffInputStream& rStrm ); + /** Imports a SHAREDFMLA record describing a shared formula in a cell range. */ + void importSharedFmla( BiffInputStream& rStrm ); private: - SheetDataBuffer& mrSheetData; /// The sheet data buffer for cell content and formatting. - CellModel maCurrCell; /// Position and formatting of current imported cell. sal_uInt32 mnFormulaSkipSize; /// Number of bytes to be ignored in FORMULA record. sal_uInt32 mnArraySkipSize; /// Number of bytes to be ignored in ARRAY record. sal_uInt16 mnBiff2XfId; /// Current XF identifier from IXFE record. diff --git a/oox/inc/oox/xls/worksheethelper.hxx b/oox/inc/oox/xls/worksheethelper.hxx index fe788be852cb..27754c898608 100644 --- a/oox/inc/oox/xls/worksheethelper.hxx +++ b/oox/inc/oox/xls/worksheethelper.hxx @@ -80,42 +80,6 @@ enum WorksheetType // ============================================================================ -/** Stores some data about a cell. */ -struct CellModel -{ - ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell > mxCell; - ::com::sun::star::table::CellAddress maAddress; - ::rtl::OUString maValue; /// String containing cell value data. - ::rtl::OUString maFormula; /// String containing the formula definition. - ::rtl::OUString maFormulaRef; /// String containing formula range for array/shared formulas. - sal_Int32 mnCellType; /// Data type of the cell value. - sal_Int32 mnFormulaType; /// Type of the formula (regular, array, shared, table). - sal_Int32 mnSharedId; /// Shared formula identifier. - sal_Int32 mnXfId; /// XF (cell formatting) identifier. - sal_Int32 mnNumFmtId; /// Forced number format (overrides XF if set). - bool mbShowPhonetic; /// True = show phonetic text. - - inline explicit CellModel() { reset(); } - void reset(); -}; - -// ---------------------------------------------------------------------------- - -/** Stores data about a data table a.k.a. multiple operation range. */ -struct DataTableModel -{ - ::rtl::OUString maRef1; /// String containing first reference cell for data table formulas. - ::rtl::OUString maRef2; /// String containing second reference cell for data table formulas. - bool mb2dTable; /// True = 2-dimensional data table. - bool mbRowTable; /// True = row oriented data table. - bool mbRef1Deleted; /// True = first reference cell deleted. - bool mbRef2Deleted; /// True = second reference cell deleted. - - explicit DataTableModel(); -}; - -// ---------------------------------------------------------------------------- - /** Stores formatting data about a range of columns. */ struct ColumnModel { @@ -243,17 +207,6 @@ public: /** Returns the XCell interface for the passed cell address. */ ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell > getCell( const ::com::sun::star::table::CellAddress& rAddress ) const; - /** Returns the XCell interface for the passed cell address string. */ - ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell > - getCell( - const ::rtl::OUString& rAddressStr, - ::com::sun::star::table::CellAddress* opAddress = 0 ) const; - /** Returns the XCell interface for the passed cell address. */ - ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell > - getCell( - const BinAddress& rBinAddress, - ::com::sun::star::table::CellAddress* opAddress = 0 ) const; - /** Returns the XCellRange interface for the passed cell range address. */ ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange > getCellRange( const ::com::sun::star::table::CellRangeAddress& rRange ) const; |