diff options
37 files changed, 1773 insertions, 995 deletions
diff --git a/oox/inc/oox/dump/biffdumper.hxx b/oox/inc/oox/dump/biffdumper.hxx index 078330cb8dbe..a3bdc4a87c73 100644 --- a/oox/inc/oox/dump/biffdumper.hxx +++ b/oox/inc/oox/dump/biffdumper.hxx @@ -443,6 +443,8 @@ private: void dumpExtCfColor( const String& rName = EMPTY_STRING ); void dumpExtGradientHead(); + sal_uInt8 dumpFilterColumnOperator( const String& rName ); + ::rtl::OUString dumpPivotString( const String& rName, sal_uInt16 nStrLen ); ::rtl::OUString dumpPivotString( const String& rName ); diff --git a/oox/inc/oox/xls/autofilterbuffer.hxx b/oox/inc/oox/xls/autofilterbuffer.hxx new file mode 100755 index 000000000000..105afa606f47 --- /dev/null +++ b/oox/inc/oox/xls/autofilterbuffer.hxx @@ -0,0 +1,278 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef OOX_XLS_AUTOFILTERBUFFER_HXX +#define OOX_XLS_AUTOFILTERBUFFER_HXX + +#include <com/sun/star/table/CellRangeAddress.hpp> +#include "oox/xls/workbookhelper.hxx" + +namespace com { namespace sun { namespace star { + namespace sheet { struct TableFilterField2; } + namespace sheet { class XDatabaseRange; } + namespace sheet { class XSheetFilterDescriptor2; } +} } } + +namespace oox { +namespace xls { + +// ============================================================================ + +/** Contains UNO API filter settings for a column in a filtered range. */ +struct ApiFilterSettings +{ + typedef ::std::vector< ::com::sun::star::sheet::TableFilterField2 > FilterFieldVector; + + FilterFieldVector maFilterFields; /// List of UNO API filter settings. + OptValue< bool > mobNeedsRegExp; /// If set, requires regular expressions to be enabled/disabled. + + explicit ApiFilterSettings(); + + void appendField( bool bAnd, sal_Int32 nOperator, double fValue ); + void appendField( bool bAnd, sal_Int32 nOperator, const ::rtl::OUString& rValue ); +}; + +// ============================================================================ + +/** Base class for specific filter settings for a column in a filtered range. + */ +class FilterSettingsBase : public WorkbookHelper +{ +public: + explicit FilterSettingsBase( const WorkbookHelper& rHelper ); + + /** Derived classes import filter settings from the passed attribute list. */ + virtual void importAttribs( sal_Int32 nElement, const AttributeList& rAttribs ); + /** Derived classes import filter settings from the passed record. */ + virtual void importRecord( sal_Int32 nRecId, RecordInputStream& rStrm ); + /** Derived classes import filter settings from the FILTERCOLUMN record. */ + virtual void importBiffRecord( BiffInputStream& rStrm, sal_uInt16 nFlags ); + + /** Derived classes return converted UNO API filter settings representing all filter settings. */ + virtual ApiFilterSettings finalizeImport( sal_Int32 nMaxCount ); +}; + +typedef ::boost::shared_ptr< FilterSettingsBase > FilterSettingsRef; + +// ============================================================================ + +/** Settings for a discrete filter, specifying a list of values to be shown in + the filtered range. + */ +class DiscreteFilter : public FilterSettingsBase +{ +public: + explicit DiscreteFilter( const WorkbookHelper& rHelper ); + + /** Imports filter settings from the filters and filter elements. */ + virtual void importAttribs( sal_Int32 nElement, const AttributeList& rAttribs ); + /** Imports filter settings from the FILTERS and FILTER records. */ + virtual void importRecord( sal_Int32 nRecId, RecordInputStream& rStrm ); + + /** Returns converted UNO API filter settings representing all filter settings. */ + virtual ApiFilterSettings finalizeImport( sal_Int32 nMaxCount ); + +private: + typedef ::std::vector< ::rtl::OUString > FilterValueVector; + + FilterValueVector maValues; + sal_Int32 mnCalendarType; + bool mbShowBlank; +}; + +// ============================================================================ + +/** Settings for a top-10 filter. */ +class Top10Filter : public FilterSettingsBase +{ +public: + explicit Top10Filter( const WorkbookHelper& rHelper ); + + /** Imports filter settings from the filters and filter elements. */ + virtual void importAttribs( sal_Int32 nElement, const AttributeList& rAttribs ); + /** Imports filter settings from the FILTERS and FILTER records. */ + virtual void importRecord( sal_Int32 nRecId, RecordInputStream& rStrm ); + /** Imports filter settings from the FILTERCOLUMN record. */ + virtual void importBiffRecord( BiffInputStream& rStrm, sal_uInt16 nFlags ); + + /** Returns converted UNO API filter settings representing all filter settings. */ + virtual ApiFilterSettings finalizeImport( sal_Int32 nMaxCount ); + +private: + double mfValue; /// Number of items or percentage. + bool mbTop; /// True = show top (greatest) items/percentage. + bool mbPercent; /// True = percentage, false = number of items. +}; + +// ============================================================================ + +/** A filter criterion for a custom filter. */ +struct FilterCriterionModel +{ + ::com::sun::star::uno::Any maValue; /// The comparison operator. + sal_Int32 mnOperator; /// Comparison operator. + sal_uInt8 mnDataType; /// Operator data type (BIFF only). + sal_uInt8 mnStrLen; /// Length of string operator (BIFF5-BIFF8 only). + + explicit FilterCriterionModel(); + + /** Sets the passed BIFF operator constant. */ + void setBiffOperator( sal_uInt8 nOperator ); + + /** Imports the criterion model from the passed BIFF12 stream. */ + void readBiffData( RecordInputStream& rStrm ); + /** Imports the initial criterion data from the passed BIFF5/BIFF8 stream. */ + void readBiffData( BiffInputStream& rStrm ); + /** Imports the trailing string data from the passed BIFF5/BIFF8 stream. */ + void readString( BiffInputStream& rStrm, BiffType eBiff, rtl_TextEncoding eTextEnc ); +}; + +// ---------------------------------------------------------------------------- + +/** Settings for a custom filter, specifying one or two comparison operators + associated with some values. + */ +class CustomFilter : public FilterSettingsBase +{ +public: + explicit CustomFilter( const WorkbookHelper& rHelper ); + + /** Imports filter settings from the filters and filter elements. */ + virtual void importAttribs( sal_Int32 nElement, const AttributeList& rAttribs ); + /** Imports filter settings from the FILTERS and FILTER records. */ + virtual void importRecord( sal_Int32 nRecId, RecordInputStream& rStrm ); + /** Imports filter settings from the FILTERCOLUMN record. */ + virtual void importBiffRecord( BiffInputStream& rStrm, sal_uInt16 nFlags ); + + /** Returns converted UNO API filter settings representing all filter settings. */ + virtual ApiFilterSettings finalizeImport( sal_Int32 nMaxCount ); + +private: + /** Apeends the passed filter criteriom, if it contains valid settings. */ + void appendCriterion( const FilterCriterionModel& rCriterion ); + +private: + typedef ::std::vector< FilterCriterionModel > FilterCriterionVector; + + FilterCriterionVector maCriteria; + bool mbAnd; +}; + +// ============================================================================ + +/** A column in a filtered range. Contains an object with specific filter + settings for the cells in the column. + */ +class FilterColumn : public WorkbookHelper +{ +public: + explicit FilterColumn( const WorkbookHelper& rHelper ); + + /** Imports auto filter column settings from the filterColumn element. */ + void importFilterColumn( const AttributeList& rAttribs ); + /** Imports auto filter column settings from the FILTERCOLUMN record. */ + void importFilterColumn( RecordInputStream& rStrm ); + /** Imports auto filter column settings from the FILTERCOLUMN record. */ + void importFilterColumn( BiffInputStream& rStrm ); + + /** Creates and returns the specified filter settings object. */ + template< typename FilterSettingsType > + inline FilterSettingsBase& createFilterSettings() + { mxSettings.reset( new FilterSettingsType( *this ) ); return *mxSettings; } + + /** Returns the index of the column in the filtered range this object is related to. */ + inline sal_Int32 getColumnId() const { return mnColId; } + + /** Returns converted UNO API filter settings representing all filter + settings of this column. */ + ApiFilterSettings finalizeImport( sal_Int32 nMaxCount ); + +private: + FilterSettingsRef mxSettings; + sal_Int32 mnColId; + bool mbHiddenButton; + bool mbShowButton; +}; + +// ============================================================================ + +class AutoFilter : public WorkbookHelper +{ +public: + explicit AutoFilter( const WorkbookHelper& rHelper ); + + /** Imports auto filter settings from the autoFilter element. */ + void importAutoFilter( const AttributeList& rAttribs, sal_Int16 nSheet ); + /** Imports auto filter settings from the AUTOFILTER record. */ + void importAutoFilter( RecordInputStream& rStrm, sal_Int16 nSheet ); + + /** Creates a new auto filter column and stores it internally. */ + FilterColumn& createFilterColumn(); + + /** Applies the filter to the passed filter descriptor. */ + void finalizeImport( const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSheetFilterDescriptor2 >& rxFilterDesc ); + +private: + typedef RefVector< FilterColumn > FilterColumnVector; + + FilterColumnVector maFilterColumns; + ::com::sun::star::table::CellRangeAddress maRange; +}; + +// ============================================================================ + +class AutoFilterBuffer : public WorkbookHelper +{ +public: + explicit AutoFilterBuffer( const WorkbookHelper& rHelper ); + + /** Creates a new auto filter and stores it internally. */ + AutoFilter& createAutoFilter(); + + /** Applies filter settings to a new database range object (used for sheet + autofilter or advanced filter as specified by built-in defined names). */ + void finalizeImport( sal_Int16 nSheet ); + + /** Applies the filters to the passed database range object. + @return True = this buffer contains valid auto filter settings. */ + bool finalizeImport( const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDatabaseRange >& rxDatabaseRange ); + +private: + /** Returns the auto filter object used to perform auto filtering. */ + AutoFilter* getActiveAutoFilter(); + +private: + typedef RefVector< AutoFilter > AutoFilterVector; + AutoFilterVector maAutoFilters; +}; + +// ============================================================================ + +} // namespace xls +} // namespace oox + +#endif diff --git a/oox/inc/oox/xls/autofiltercontext.hxx b/oox/inc/oox/xls/autofiltercontext.hxx index 5efe0da2a9e8..6deb40bedd9c 100644 --- a/oox/inc/oox/xls/autofiltercontext.hxx +++ b/oox/inc/oox/xls/autofiltercontext.hxx @@ -28,124 +28,82 @@ #ifndef OOX_XLS_AUTOFILTERCONTEXT_HXX #define OOX_XLS_AUTOFILTERCONTEXT_HXX -#define USE_SC_MULTI_STRING_FILTER_PATCH 0 - #include "oox/xls/excelhandlers.hxx" -#include <com/sun/star/table/CellRangeAddress.hpp> - -#if USE_SC_MULTI_STRING_FILTER_PATCH -#include <com/sun/star/sheet/TableFilterFieldBase.hpp> -#else -#include <com/sun/star/sheet/TableFilterField.hpp> -#endif - -#include <boost/shared_ptr.hpp> -#include <list> - -namespace com { namespace sun { namespace star { namespace sheet { -#if USE_SC_MULTI_STRING_FILTER_PATCH - struct TableFilterFieldBase; -#else - struct TableFilterField; -#endif - struct TableFilterFieldMultiString; -}}}} namespace oox { namespace xls { +class AutoFilter; +class FilterColumn; +class FilterSettingsBase; + // ============================================================================ -struct FilterFieldItem +class FilterSettingsContext : public WorksheetContextBase { -#if USE_SC_MULTI_STRING_FILTER_PATCH - typedef ::boost::shared_ptr< ::com::sun::star::sheet::TableFilterFieldBase > TableFilterFieldRef; -#else - typedef ::boost::shared_ptr< ::com::sun::star::sheet::TableFilterField > TableFilterFieldRef; -#endif +public: + explicit FilterSettingsContext( WorksheetContextBase& rParent, FilterSettingsBase& rFilterSettings ); - enum Type { NORMAL, MULTI_STRING }; +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual void onStartElement( const AttributeList& rAttribs ); - TableFilterFieldRef mpField; - Type meType; + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, RecordInputStream& rStrm ); + virtual void onStartRecord( RecordInputStream& rStrm ); - FilterFieldItem(); - FilterFieldItem(Type eType); +private: + FilterSettingsBase& mrFilterSettings; }; // ============================================================================ -class AutoFilterContext : public WorksheetContextBase +class FilterColumnContext : public WorksheetContextBase { public: - explicit AutoFilterContext( WorksheetFragmentBase& rFragment ); + explicit FilterColumnContext( WorksheetContextBase& rParent, FilterColumn& rFilterColumn ); protected: virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); virtual void onStartElement( const AttributeList& rAttribs ); - virtual void onEndElement(); - -private: - /** Initializes data members to prepare for autofilter parsing. Call this - method when a new autofilter context starts. */ - void initialize(); - - /** Commits the imported autofilter data to Calc. */ - void setAutoFilter(); - - /** Check if the shown blank bit is on, if so, add show blank filter to the - list. */ - void maybeShowBlank(); - - /** Packs the collected filter names into a single regex string. */ - void setFilterNames(); - void importAutoFilter( const AttributeList& rAttribs ); + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, RecordInputStream& rStrm ); + virtual void onStartRecord( RecordInputStream& rStrm ); - void importFilterColumn( const AttributeList& rAttribs ); - - void importTop10( const AttributeList& rAttribs ); - - /** Be sure to check for its 'and' attribute when there are two - customFilter's. If the attribute is not given, assume OR. */ - void importCustomFilters( const AttributeList& rAttribs ); +private: + FilterColumn& mrFilterColumn; +}; - /** Imports custumFilter element. Note that the standard specifies there - can be at most two custom filters specified, but no more than two. When - there are two custom filters, then their relationship (AND or OR) must - be specified by the parent element <customFilters>. */ - void importCustomFilter( const AttributeList& rAttribs ); +// ============================================================================ - void importFilters( const AttributeList& rAttribs ); +class AutoFilterContext : public WorksheetContextBase +{ +public: + explicit AutoFilterContext( WorksheetFragmentBase& rFragment, AutoFilter& rAutoFilter ); - void importFilter( const AttributeList& rAttribs ); +protected: + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual void onStartElement( const AttributeList& rAttribs ); - void importDynamicFilter( const AttributeList& rAttribs ); + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, RecordInputStream& rStrm ); + virtual void onStartRecord( RecordInputStream& rStrm ); private: - typedef ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell > XCellRef; - - ::std::list< FilterFieldItem > maFields; - - ::std::list< ::rtl::OUString > maFilterNames; - ::com::sun::star::table::CellRangeAddress maAutoFilterRange; - sal_Int32 mnCurColID; + AutoFilter& mrAutoFilter; +}; - /** If this is false (i.e. the given cell range address is not valid), then - don't do anything. */ - bool mbValidAddress:1; +// ============================================================================ - /** We use regex to compensate for Calc's lack of filtering by individual - names (i.e. <filter> tag). */ - bool mbUseRegex:1; +class BiffAutoFilterContext : public BiffWorksheetContextBase +{ +public: + explicit BiffAutoFilterContext( const WorksheetHelper& rHelper, AutoFilter& rAutoFilter ); - /** The <filters> tag may have a 'blank' attribute when the blank values - need to be shown. This flag stores that information. */ - bool mbShowBlank:1; +protected: + /** Imports all records related to the current auto filter. */ + virtual void importRecord( BiffInputStream& rStrm ); - /** true if FilterConnection_AND, or false if FilterConnection_OR. This - flag is used to store the relationship of paired customFilter's. */ - bool mbConnectionAnd:1; +private: + AutoFilter& mrAutoFilter; }; // ============================================================================ diff --git a/oox/inc/oox/xls/biffhelper.hxx b/oox/inc/oox/xls/biffhelper.hxx index ba0228b761bb..dd93621ba130 100644 --- a/oox/inc/oox/xls/biffhelper.hxx +++ b/oox/inc/oox/xls/biffhelper.hxx @@ -85,6 +85,8 @@ const sal_Int32 BIFF12_ID_CONTROL = 0x0284; const sal_Int32 BIFF12_ID_CONTROLS = 0x0283; const sal_Int32 BIFF12_ID_CUSTOMCHARTVIEW = 0x028F; const sal_Int32 BIFF12_ID_CUSTOMCHARTVIEWS = 0x028D; +const sal_Int32 BIFF12_ID_CUSTOMFILTER = 0x00AE; +const sal_Int32 BIFF12_ID_CUSTOMFILTERS = 0x00AC; const sal_Int32 BIFF12_ID_CUSTOMSHEETVIEW = 0x01A7; const sal_Int32 BIFF12_ID_CUSTOMSHEETVIEWS = 0x01A6; const sal_Int32 BIFF12_ID_CUSTOMWORKBOOKVIEW= 0x018D; @@ -99,6 +101,8 @@ const sal_Int32 BIFF12_ID_DDEITEM_ERROR = 0x0245; const sal_Int32 BIFF12_ID_DDEITEM_STRING = 0x0246; const sal_Int32 BIFF12_ID_DEFINEDNAME = 0x0027; const sal_Int32 BIFF12_ID_DIMENSION = 0x0094; +const sal_Int32 BIFF12_ID_DISCRETEFILTER = 0x00A7; +const sal_Int32 BIFF12_ID_DISCRETEFILTERS = 0x00A5; const sal_Int32 BIFF12_ID_DRAWING = 0x0226; const sal_Int32 BIFF12_ID_DXF = 0x01FB; const sal_Int32 BIFF12_ID_DXFS = 0x01F9; @@ -266,6 +270,7 @@ const sal_uInt16 BIFF8_MAXRECSIZE = 8224; const sal_uInt16 BIFF2_ID_ARRAY = 0x0021; const sal_uInt16 BIFF3_ID_ARRAY = 0x0221; +const sal_uInt16 BIFF_ID_AUTOFILTER = 0x009D; const sal_uInt16 BIFF2_ID_BLANK = 0x0001; const sal_uInt16 BIFF3_ID_BLANK = 0x0201; const sal_uInt16 BIFF2_ID_BOF = 0x0009; @@ -393,6 +398,8 @@ const sal_uInt16 BIFF_ID_EXTERNSHEET = 0x0017; const sal_uInt16 BIFF_ID_EXTSST = 0x00FF; const sal_uInt16 BIFF_ID_FILEPASS = 0x002F; const sal_uInt16 BIFF_ID_FILESHARING = 0x005B; +const sal_uInt16 BIFF_ID_FILTERCOLUMN = 0x009E; +const sal_uInt16 BIFF_ID_FILTERMODE = 0x009B; const sal_uInt16 BIFF2_ID_FONT = 0x0031; const sal_uInt16 BIFF3_ID_FONT = 0x0231; const sal_uInt16 BIFF5_ID_FONT = 0x0031; @@ -576,6 +583,9 @@ const sal_uInt8 BIFF_DATATYPE_STRING = 2; const sal_uInt8 BIFF_DATATYPE_BOOL = 4; const sal_uInt8 BIFF_DATATYPE_ERROR = 16; +const sal_uInt8 BIFF_BOOLERR_BOOL = 0; +const sal_uInt8 BIFF_BOOLERR_ERROR = 1; + // BIFF8 unicode strings ------------------------------------------------------ const sal_uInt8 BIFF_STRF_16BIT = 0x01; diff --git a/oox/inc/oox/xls/connectionsbuffer.hxx b/oox/inc/oox/xls/connectionsbuffer.hxx index bfab732fa7fc..69d609993864 100755 --- a/oox/inc/oox/xls/connectionsbuffer.hxx +++ b/oox/inc/oox/xls/connectionsbuffer.hxx @@ -86,6 +86,7 @@ struct ConnectionModel sal_Int32 mnId; /// Unique connection identifier. sal_Int32 mnType; /// Data source type. sal_Int32 mnReconnectMethod; /// Reconnection method. + sal_Int32 mnCredentials; /// Credentials method. sal_Int32 mnInterval; /// Refresh interval in minutes. bool mbKeepAlive; /// True = keep connection open after import. bool mbNew; /// True = new connection, never updated. @@ -94,6 +95,7 @@ struct ConnectionModel bool mbBackground; /// True = background refresh enabled. bool mbRefreshOnLoad; /// True = refresh connection on import. bool mbSaveData; /// True = save cached data with connection. + bool mbSavePassword; /// True = save password in connection string. explicit ConnectionModel(); @@ -151,23 +153,27 @@ class ConnectionsBuffer : public WorkbookHelper public: explicit ConnectionsBuffer( const WorkbookHelper& rHelper ); - /** Imports connection settings from the connection element. */ - ConnectionRef importConnection( const AttributeList& rAttribs ); - /** Imports connection settings from the CONNECTION record. */ - ConnectionRef importConnection( RecordInputStream& rStrm ); - /** Creates a new empty connection with an unused identifier. */ - ConnectionRef createConnection(); + /** Creates a new empty connection. */ + Connection& createConnection(); + /** Creates a new empty connection with a valid but unused identifier. */ + Connection& createConnectionWithId(); + + /** Maps all connections by their identifier. */ + void finalizeImport(); /** Returns a data connection by its unique identifier. */ ConnectionRef getConnection( sal_Int32 nConnId ) const; private: - /** Inserts the passed connection object. */ - void insertConnection( const ConnectionRef& rxConnection ); + /** Inserts the passed connection into the map according to its identifier. */ + void insertConnectionToMap( const ConnectionRef& rxConnection ); private: + typedef RefVector< Connection > ConnectionVector; typedef RefMap< sal_Int32, Connection > ConnectionMap; - ConnectionMap maConnections; + + ConnectionVector maConnections; + ConnectionMap maConnectionsById; sal_Int32 mnUnusedId; }; diff --git a/oox/inc/oox/xls/connectionsfragment.hxx b/oox/inc/oox/xls/connectionsfragment.hxx index a104daf050d5..8c4a608de7d1 100644 --- a/oox/inc/oox/xls/connectionsfragment.hxx +++ b/oox/inc/oox/xls/connectionsfragment.hxx @@ -29,24 +29,28 @@ #define OOX_XLS_CONNECTIONSFRAGMENT_HXX #include "oox/xls/excelhandlers.hxx" -#include "oox/xls/connectionsbuffer.hxx" namespace oox { namespace xls { +class Connection; + // ============================================================================ class ConnectionContext : public WorkbookContextBase { public: - explicit ConnectionContext( WorkbookFragmentBase& rParent, const ConnectionRef& rxConnection ); + explicit ConnectionContext( WorkbookFragmentBase& rParent, Connection& rConnection ); protected: virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); + virtual void onStartElement( const AttributeList& rAttribs ); + virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, RecordInputStream& rStrm ); + virtual void onStartRecord( RecordInputStream& rStrm ); private: - ConnectionRef mxConnection; + Connection& mrConnection; }; // ============================================================================ @@ -63,10 +67,7 @@ protected: virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, RecordInputStream& rStrm ); virtual const ::oox::core::RecordInfo* getRecordInfos() const; - -private: - void importConnection( const AttributeList& rAttribs ); - void importWebPr( const AttributeList& rAttribs ); + virtual void finalizeImport(); }; // ============================================================================ diff --git a/oox/inc/oox/xls/defnamesbuffer.hxx b/oox/inc/oox/xls/defnamesbuffer.hxx index 2aca217fc28d..15d7db41832d 100644 --- a/oox/inc/oox/xls/defnamesbuffer.hxx +++ b/oox/inc/oox/xls/defnamesbuffer.hxx @@ -46,19 +46,19 @@ class BiffInputStreamPos; // codes for built-in names const sal_Unicode BIFF_DEFNAME_CONSOLIDATEAREA = '\x00'; -const sal_Unicode BIFF_DEFNAME_AUTOOPEN = '\x01'; -const sal_Unicode BIFF_DEFNAME_AUTOCLOSE = '\x02'; -const sal_Unicode BIFF_DEFNAME_EXTRACT = '\x03'; +const sal_Unicode BIFF_DEFNAME_AUTOOPEN = '\x01'; // Sheet macro executed when workbook is opened. +const sal_Unicode BIFF_DEFNAME_AUTOCLOSE = '\x02'; // Sheet macro executed when workbook is closed. +const sal_Unicode BIFF_DEFNAME_EXTRACT = '\x03'; // Filter output destination for advanced filter. const sal_Unicode BIFF_DEFNAME_DATABASE = '\x04'; -const sal_Unicode BIFF_DEFNAME_CRITERIA = '\x05'; -const sal_Unicode BIFF_DEFNAME_PRINTAREA = '\x06'; -const sal_Unicode BIFF_DEFNAME_PRINTTITLES = '\x07'; +const sal_Unicode BIFF_DEFNAME_CRITERIA = '\x05'; // Filter criteria source range for advanced filter. +const sal_Unicode BIFF_DEFNAME_PRINTAREA = '\x06'; // Print ranges. +const sal_Unicode BIFF_DEFNAME_PRINTTITLES = '\x07'; // Rows/columns repeated on each page when printing. const sal_Unicode BIFF_DEFNAME_RECORDER = '\x08'; const sal_Unicode BIFF_DEFNAME_DATAFORM = '\x09'; -const sal_Unicode BIFF_DEFNAME_AUTOACTIVATE = '\x0A'; -const sal_Unicode BIFF_DEFNAME_AUTODEACTIVATE = '\x0B'; +const sal_Unicode BIFF_DEFNAME_AUTOACTIVATE = '\x0A'; // Sheet macro executed when workbook is activated. +const sal_Unicode BIFF_DEFNAME_AUTODEACTIVATE = '\x0B'; // Sheet macro executed when workbook is deactivated. const sal_Unicode BIFF_DEFNAME_SHEETTITLE = '\x0C'; -const sal_Unicode BIFF_DEFNAME_FILTERDATABASE = '\x0D'; +const sal_Unicode BIFF_DEFNAME_FILTERDATABASE = '\x0D'; // Sheet range autofilter or advanced filter works on. const sal_Unicode BIFF_DEFNAME_UNKNOWN = '\x0E'; // ============================================================================ @@ -69,9 +69,9 @@ struct DefinedNameModel ::rtl::OUString maFormula; /// The formula string. sal_Int32 mnSheet; /// Sheet index for local names. sal_Int32 mnFuncGroupId; /// Function group identifier. - bool mbMacro; /// True = Macro name (VBasic or sheet macro). + bool mbMacro; /// True = Macro name (VBA or sheet macro). bool mbFunction; /// True = function, false = command. - bool mbVBName; /// True = VBasic macro, false = sheet macro. + bool mbVBName; /// True = VBA macro, false = sheet macro. bool mbHidden; /// True = name hidden in UI. explicit DefinedNameModel(); @@ -134,19 +134,21 @@ public: /** Converts the formula string or BIFF token array for this defined name. */ void convertFormula(); + /** Returns true, if this defined name is global in the document. */ + inline bool isGlobalName() const { return mnCalcSheet < 0; } /** Returns true, if this defined name is a special builtin name. */ inline bool isBuiltinName() const { return mcBuiltinId != BIFF_DEFNAME_UNKNOWN; } /** Returns true, if this defined name is a macro function call. */ inline bool isMacroFunction() const { return maModel.mbMacro && maModel.mbFunction; } /** Returns true, if this defined name is a reference to a VBA macro. */ inline bool isVBName() const { return maModel.mbMacro && maModel.mbVBName; } - /** Returns true, if this defined name is global in the document. */ - inline bool isGlobalName() const { return mnCalcSheet < 0; } - /** Returns the token index used in API token arrays (com.sun.star.sheet.FormulaToken). */ - inline sal_Int32 getTokenIndex() const { return mnTokenIndex; } /** Returns the 0-based sheet index for local names, or -1 for global names. */ inline sal_Int16 getLocalCalcSheet() const { return mnCalcSheet; } + /** Returns the built-in identifier of the defined name. */ + inline sal_Unicode getBuiltinId() const { return mcBuiltinId; } + /** Returns the token index used in API token arrays (com.sun.star.sheet.FormulaToken). */ + inline sal_Int32 getTokenIndex() const { return mnTokenIndex; } /** Tries to resolve the defined name to an absolute cell range. */ bool getAbsoluteRange( ::com::sun::star::table::CellRangeAddress& orRange ) const; @@ -201,16 +203,27 @@ public: If no local name is found, tries to find a matching global name. @return Reference to the defined name or empty reference. */ DefinedNameRef getByModelName( const ::rtl::OUString& rModelName, sal_Int16 nCalcSheet = -1 ) const; + /** Returns a built-in defined name by its built-in identifier. + @param nSheet The sheet index of the built-in name. + @return Reference to the defined name or empty reference. */ + DefinedNameRef getByBuiltinId( sal_Unicode cBuiltinId, sal_Int16 nCalcSheet ) const; private: DefinedNameRef createDefinedName(); private: + typedef ::std::pair< sal_Int16, ::rtl::OUString > SheetNameKey; + typedef ::std::pair< sal_Int16, sal_Unicode > BuiltinKey; + typedef RefVector< DefinedName > DefNameVector; - typedef RefMap< sal_Int32, DefinedName > DefNameMap; + typedef RefMap< SheetNameKey, DefinedName > DefNameNameMap; + typedef RefMap< BuiltinKey, DefinedName > DefNameBuiltinMap; + typedef RefMap< sal_Int32, DefinedName > DefNameTokenIdMap; DefNameVector maDefNames; /// List of all defined names in insertion order. - DefNameMap maDefNameMap; /// Maps all defined names by API token index. + DefNameNameMap maModelNameMap; /// Maps all defined names by sheet index and model name. + DefNameBuiltinMap maBuiltinMap; /// Maps all defined names by sheet index and built-in identifier. + DefNameTokenIdMap maTokenIdMap; /// Maps all defined names by API token index. sal_Int16 mnCalcSheet; /// Current sheet index for BIFF2-BIFF4 names (always sheet-local). }; diff --git a/oox/inc/oox/xls/pivotcachefragment.hxx b/oox/inc/oox/xls/pivotcachefragment.hxx index d2a5ab4d7ace..4521fc8c0859 100644 --- a/oox/inc/oox/xls/pivotcachefragment.hxx +++ b/oox/inc/oox/xls/pivotcachefragment.hxx @@ -126,7 +126,7 @@ class BiffPivotCacheRecordsContext : public BiffWorksheetContextBase { public: explicit BiffPivotCacheRecordsContext( - const BiffWorkbookFragmentBase& rFragment, + const WorkbookHelper& rHelper, const PivotCache& rPivotCache ); /** Reads the current record from stream and tries to insert a cell into diff --git a/oox/inc/oox/xls/pivottablefragment.hxx b/oox/inc/oox/xls/pivottablefragment.hxx index a6cfe7ef2c64..039adc36134f 100644 --- a/oox/inc/oox/xls/pivottablefragment.hxx +++ b/oox/inc/oox/xls/pivottablefragment.hxx @@ -100,7 +100,7 @@ private: class BiffPivotTableContext : public BiffWorksheetContextBase { public: - explicit BiffPivotTableContext( const BiffWorksheetFragmentBase& rFragment ); + explicit BiffPivotTableContext( const WorksheetHelper& rHelper ); /** Imports all records related to the current pivot table. */ virtual void importRecord( BiffInputStream& rStrm ); diff --git a/oox/inc/oox/xls/querytablefragment.hxx b/oox/inc/oox/xls/querytablefragment.hxx index 65727fb87351..9aafdd15684e 100644 --- a/oox/inc/oox/xls/querytablefragment.hxx +++ b/oox/inc/oox/xls/querytablefragment.hxx @@ -59,7 +59,7 @@ private: class BiffQueryTableContext : public BiffWorksheetContextBase { public: - explicit BiffQueryTableContext( const BiffWorksheetFragmentBase& rFragment ); + explicit BiffQueryTableContext( const WorksheetHelper& rHelper ); /** Imports all records related to the current query table. */ virtual void importRecord( BiffInputStream& rStrm ); diff --git a/oox/inc/oox/xls/sheetdatacontext.hxx b/oox/inc/oox/xls/sheetdatacontext.hxx index 54f4b64fb64b..6a267db28214 100644 --- a/oox/inc/oox/xls/sheetdatacontext.hxx +++ b/oox/inc/oox/xls/sheetdatacontext.hxx @@ -113,7 +113,7 @@ private: class BiffSheetDataContext : public BiffWorksheetContextBase { public: - explicit BiffSheetDataContext( const BiffWorksheetFragmentBase& rParent ); + explicit BiffSheetDataContext( const WorksheetHelper& rHelper ); /** Tries to import a sheet data record. */ virtual void importRecord( BiffInputStream& rStrm ); diff --git a/oox/inc/oox/xls/tablebuffer.hxx b/oox/inc/oox/xls/tablebuffer.hxx index 8c127184f15d..4e9cb9824df0 100644 --- a/oox/inc/oox/xls/tablebuffer.hxx +++ b/oox/inc/oox/xls/tablebuffer.hxx @@ -30,6 +30,7 @@ #include <com/sun/star/table/CellRangeAddress.hpp> #include "oox/helper/containerhelper.hxx" +#include "oox/xls/autofilterbuffer.hxx" #include "oox/xls/workbookhelper.hxx" namespace oox { @@ -62,6 +63,8 @@ public: void importTable( const AttributeList& rAttribs, sal_Int16 nSheet ); /** Imports a table definition from a TABLE record. */ void importTable( RecordInputStream& rStrm, sal_Int16 nSheet ); + /** Creates a new auto filter and stores it internally. */ + inline AutoFilter& createAutoFilter() { return maAutoFilters.createAutoFilter(); } /** Creates a database range from this tables. */ void finalizeImport(); @@ -70,7 +73,7 @@ public: inline sal_Int32 getTableId() const { return maModel.mnId; } /** Returns the token index used in API token arrays (com.sun.star.sheet.FormulaToken). */ inline sal_Int32 getTokenIndex() const { return mnTokenIndex; } - /** Returns the display name of the table. */ + /** Returns the original display name of the table. */ inline const ::rtl::OUString& getDisplayName() const { return maModel.maDisplayName; } /** Returns the original (unchecked) total range of the table. */ @@ -88,6 +91,8 @@ public: private: TableModel maModel; + AutoFilterBuffer maAutoFilters; /// Filter settings for this table. + ::rtl::OUString maDBRangeName; /// Name of the databae range in the Calc document. ::com::sun::star::table::CellRangeAddress maDestRange; /// Validated range of the table in the worksheet. sal_Int32 mnTokenIndex; /// Token index used in API token array. @@ -102,10 +107,8 @@ class TableBuffer : public WorkbookHelper public: explicit TableBuffer( const WorkbookHelper& rHelper ); - /** Imports a table definition from the passed attributes. */ - TableRef importTable( const AttributeList& rAttribs, sal_Int16 nSheet ); - /** Imports a table definition from a TABLE record. */ - TableRef importTable( RecordInputStream& rStrm, sal_Int16 nSheet ); + /** Creates a new empty table. */ + Table& createTable(); /** Creates database ranges from all imported tables. */ void finalizeImport(); @@ -116,12 +119,15 @@ public: TableRef getTable( const ::rtl::OUString& rDispName ) const; private: - void insertTable( const TableRef& rxTable ); + /** Inserts the passed table into the maps according to its identifier and name. */ + void insertTableToMaps( const TableRef& rxTable ); private: + typedef RefVector< Table > TableVector; typedef RefMap< sal_Int32, Table > TableIdMap; typedef RefMap< ::rtl::OUString, Table > TableNameMap; + TableVector maTables; TableIdMap maIdTables; TableNameMap maNameTables; }; diff --git a/oox/inc/oox/xls/tablefragment.hxx b/oox/inc/oox/xls/tablefragment.hxx index 5b92063ba147..40b9cca3a8fd 100644 --- a/oox/inc/oox/xls/tablefragment.hxx +++ b/oox/inc/oox/xls/tablefragment.hxx @@ -29,11 +29,12 @@ #define OOX_XLS_TABLEFRAGMENT_HXX #include "oox/xls/excelhandlers.hxx" -#include "oox/xls/tablebuffer.hxx" namespace oox { namespace xls { +class Table; + // ============================================================================ class TableFragment : public WorksheetFragmentBase @@ -50,7 +51,7 @@ protected: virtual const ::oox::core::RecordInfo* getRecordInfos() const; private: - TableRef mxTable; /// Current table. + Table& mrTable; }; // ============================================================================ diff --git a/oox/inc/oox/xls/workbookhelper.hxx b/oox/inc/oox/xls/workbookhelper.hxx index 78a9d674fa96..ee5b2f12cea5 100644 --- a/oox/inc/oox/xls/workbookhelper.hxx +++ b/oox/inc/oox/xls/workbookhelper.hxx @@ -37,14 +37,15 @@ namespace com { namespace sun { namespace star { namespace container { class XNameAccess; } namespace container { class XNameContainer; } namespace lang { class XMultiServiceFactory; } - namespace table { struct CellAddress; } - namespace table { struct CellRangeAddress; } - namespace table { class XCell; } - namespace table { class XCellRange; } + namespace sheet { class XDatabaseRange; } namespace sheet { class XNamedRange; } namespace sheet { class XSpreadsheet; } namespace sheet { class XSpreadsheetDocument; } namespace style { class XStyle; } + namespace table { struct CellAddress; } + namespace table { struct CellRangeAddress; } + namespace table { class XCell; } + namespace table { class XCellRange; } } } } namespace oox { @@ -184,12 +185,21 @@ public: getStyleObject( const ::rtl::OUString& rStyleName, bool bPageStyle ) const; /** Creates and returns a defined name on-the-fly in the Calc document. - The name will not be buffered in this defined names buffer. + The name will not be buffered in the global defined names buffer. @param orName (in/out-parameter) Returns the resulting used name. */ ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XNamedRange > createNamedRangeObject( ::rtl::OUString& orName, sal_Int32 nNameFlags = 0 ) const; + + /** Creates and returns a database range on-the-fly in the Calc document. + The range will not be buffered in the global table buffer. + @param orName (in/out-parameter) Returns the resulting used name. */ + ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDatabaseRange > + createDatabaseRangeObject( + ::rtl::OUString& orName, + const ::com::sun::star::table::CellRangeAddress& rRangeAddr ) const; + /** Creates and returns a com.sun.star.style.Style object for cells or pages. */ ::com::sun::star::uno::Reference< ::com::sun::star::style::XStyle > createStyleObject( diff --git a/oox/inc/oox/xls/worksheetfragment.hxx b/oox/inc/oox/xls/worksheetfragment.hxx index 4a8fc9f3ef04..96d8f1229f23 100644 --- a/oox/inc/oox/xls/worksheetfragment.hxx +++ b/oox/inc/oox/xls/worksheetfragment.hxx @@ -144,6 +144,8 @@ public: virtual bool importFragment(); private: + /** Imports the AUTOFILTER and following records with auto filter settings. */ + void importAutoFilter( BiffInputStream& rStrm ); /** Imports the COLINFO record and sets column properties and formatting. */ void importColInfo( BiffInputStream& rStrm ); /** Imports the BIFF2 COLUMNDEFAULT record and sets column default formatting. */ diff --git a/oox/inc/oox/xls/worksheethelper.hxx b/oox/inc/oox/xls/worksheethelper.hxx index 6994470c34cd..d946818b0e5e 100644 --- a/oox/inc/oox/xls/worksheethelper.hxx +++ b/oox/inc/oox/xls/worksheethelper.hxx @@ -50,6 +50,7 @@ namespace com { namespace sun { namespace star { namespace oox { namespace xls { +class AutoFilterBuffer; struct BinAddress; struct BinRange; class BinRangeList; @@ -315,6 +316,8 @@ public: CondFormatBuffer& getCondFormats() const; /** Returns the buffer for all cell comments in this sheet. */ CommentsBuffer& getComments() const; + /** Returns the auto filters for the sheet. */ + AutoFilterBuffer& getAutoFilters() const; /** Returns the buffer for all web query tables in this sheet. */ QueryTableBuffer& getQueryTables() const; /** Returns the page/print settings for this sheet. */ diff --git a/oox/source/dump/biffdumper.cxx b/oox/source/dump/biffdumper.cxx index d768b08812b7..2f362af6ad2d 100644 --- a/oox/source/dump/biffdumper.cxx +++ b/oox/source/dump/biffdumper.cxx @@ -2433,6 +2433,19 @@ void WorkbookStreamObject::implDumpRecordBody() dumpString( "password-creator", BIFF_STR_8BITLENGTH, BIFF_STR_SMARTFLAGS ); break; + case BIFF_ID_FILTERCOLUMN: + { + dumpDec< sal_uInt16 >( "column-index" ); + dumpHex< sal_uInt16 >( "flags", "FILTERCOLUMN-FLAGS" ); + sal_uInt8 nStrLen1 = dumpFilterColumnOperator( "operator-1" ); + sal_uInt8 nStrLen2 = dumpFilterColumnOperator( "operator-2" ); + bool bBiff8 = eBiff == BIFF8; + rtl_TextEncoding eTextEnc = getBiffData().getTextEncoding(); + if( nStrLen1 > 0 ) writeStringItem( "string-1", bBiff8 ? rStrm.readUniStringBody( nStrLen1, true ) : rStrm.readCharArrayUC( nStrLen1, eTextEnc, true ) ); + if( nStrLen2 > 0 ) writeStringItem( "string-2", bBiff8 ? rStrm.readUniStringBody( nStrLen2, true ) : rStrm.readCharArrayUC( nStrLen2, eTextEnc, true ) ); + } + break; + case BIFF2_ID_FONT: case BIFF3_ID_FONT: dumpFontRec(); @@ -3260,6 +3273,38 @@ void WorkbookStreamObject::dumpExtGradientHead() dumpDec< double >( "pos-bottom" ); } +sal_uInt8 WorkbookStreamObject::dumpFilterColumnOperator( const String& rName ) +{ + sal_uInt8 nStrLen = 0; + writeEmptyItem( rName ); + IndentGuard aIndGuard( mxOut ); + sal_uInt8 nType = dumpDec< sal_uInt8 >( "data-type", "FILTERCOLUMN-DATATYPE" ); + dumpDec< sal_uInt8 >( "operator", "FILTERCOLUMN-OPERATOR" ); + switch( nType ) + { + case 2: + dumpRk( "value" ); + dumpUnused( 4 ); + break; + case 4: + dumpDec< double >( "value" ); + break; + case 6: + dumpUnused( 4 ); + nStrLen = dumpDec< sal_uInt8 >( "length" ); + dumpBoolean( "simple" ); + dumpUnused( 2 ); + break; + case 8: + dumpBoolErr(); + dumpUnused( 6 ); + break; + default: + dumpUnused( 8 ); + } + return nStrLen; +} + OUString WorkbookStreamObject::dumpPivotString( const String& rName, sal_uInt16 nStrLen ) { OUString aString; @@ -3289,9 +3334,9 @@ void WorkbookStreamObject::dumpBoolErr() { MultiItemsGuard aMultiGuard( mxOut ); sal_uInt8 nValue = dumpHex< sal_uInt8 >( "value" ); - bool bErrCode = dumpBool< sal_uInt8 >( "is-errorcode" ); + bool bErrCode = dumpBool< sal_uInt8 >( "is-error-code" ); if( bErrCode ) - writeErrorCodeItem( "errorcode", nValue ); + writeErrorCodeItem( "error-code", nValue ); else writeBooleanItem( "boolean", nValue ); } diff --git a/oox/source/dump/biffdumper.ini b/oox/source/dump/biffdumper.ini index 8e3e25271cc9..f32ed89334f8 100644 --- a/oox/source/dump/biffdumper.ini +++ b/oox/source/dump/biffdumper.ini @@ -344,7 +344,7 @@ multilist=RECORD-NAMES-BIFF5 0x0018=DEFINEDNAME 0x0023=EXTERNALNAME 0x0031=FONT - 0x0098=,,,FILTERMODE,,AUTOFILTERINFO,AUTOFILTER, + 0x0098=,,,FILTERMODE,,AUTOFILTER,FILTERCOLUMN, 0x00A8=,,,,,,SCENARIOS,SCENARIO 0x00B0=PTDEFINITION,PTFIELD,PTFITEM,,PTROWCOLFIELDS,PTROWCOLITEMS,PTPAGEFIELDS, 0x00B8=DOCROUTE,RECIPNAME,,,,MULTRK,MULTBLANK,TOOLBARHDR @@ -390,7 +390,7 @@ multilist=RECORD-NAMES-BIFF8 0x0860=,,SHEETEXT,BOOKEXT,,,,SHAREDFEATHEAD 0x0868=,,,CHFRLABELPROPS,,,, 0x0870=,,,,,,CONNECTION, - 0x0878=,,CFRULE12,CFRULEEXT,XFCRC,XFEXT,, + 0x0878=,,CFRULE12,CFRULEEXT,XFCRC,XFEXT,FILTERCOLUMN12,CONTINUE12 0x0888=,,,PAGELAYOUTVIEW,CHECKCOMPAT,DXF,TABLESTYLES, 0x0890=,,STYLEEXT,,,,THEME, 0x0898=,,MTHREADSETTINGS,COMPRESSPICS,HEADERFOOTER,CHFRLAYOUT,CHFREXTPROPS,CHFREXTPROPSCONT @@ -465,6 +465,7 @@ end constlist=SIMPLE-RECORDS-BIFF5 include=SIMPLE-RECORDS-BIFF4 + 0x009D=uint16,dec,column-count 0x00C9=double,dec,value 0x00CA=uint16,bool,value 0x00CB=uint16,hex,error-code,ERRORCODES @@ -1413,6 +1414,30 @@ end shortlist=FILEPASS-TYPE,0,xor,rc4 shortlist=FILEPASS-MAJOR,1,rc4,crypto-api-2003,crypto-api-2007 +# FILTERCOLUMN --------------------------------------------------------------- + +combilist=FILTERCOLUMN-FLAGS + 0x0001=!and!or + 0x0004=op-1-simple + 0x0008=op-2-simple + 0x0010=top-10 + 0x0020=!bottom!top + 0x0040=percent + 0xFF80=uint16,dec,top-10-count +end + +constlist=FILTERCOLUMN-DATATYPE + 0=none + 2=rk + 4=double + 6=string + 8=boolean + 12=blank + 14=not-blank +end + +shortlist=FILTERCOLUMN-OPERATOR,0,none,less,equal,less-equal,greater,not-equal,greater-equal + # FONT ----------------------------------------------------------------------- flagslist=FONT-FLAGS @@ -1997,7 +2022,7 @@ end flagslist=QUERYTABLESETTINGS-EXT-FLAGS 0x0001=text-query 0x0002=table-names -endif +end unitconverter=QUERYTABLESETTINGS-INTERVAL,60,sec shortlist=QUERYTABLESETTINGS-HTMLFORMAT,1,none,rtf,all diff --git a/oox/source/dump/xlsbdumper.cxx b/oox/source/dump/xlsbdumper.cxx index 79135ca1daeb..bee33566bba8 100644 --- a/oox/source/dump/xlsbdumper.cxx +++ b/oox/source/dump/xlsbdumper.cxx @@ -1010,6 +1010,10 @@ void RecordStreamObject::implDumpRecordBody() mxFmlaObj->dumpCellFormula(); break; + case BIFF12_ID_AUTOFILTER: + dumpRange( "filter-range" ); + break; + case BIFF12_ID_BINARYINDEXBLOCK: dumpRowRange( "row-range" ); dumpUnknown( 12 ); @@ -1243,6 +1247,20 @@ void RecordStreamObject::implDumpRecordBody() dumpString( "name" ); break; + case BIFF12_ID_CUSTOMFILTER: + { + sal_uInt8 nType = dumpDec< sal_uInt8 >( "data-type", "CUSTOMFILTER-DATATYPE" ); + dumpDec< sal_uInt8 >( "operator", "CUSTOMFILTER-OPERATOR" ); + switch( nType ) + { + case 4: dumpDec< double >( "value" ); break; + case 6: dumpUnused( 8 ); dumpString( "value" ); break; + case 8: dumpBoolean( "value" ); dumpUnused( 7 ); break; + default: dumpUnused( 8 ); + } + } + break; + case BIFF12_ID_DATATABLE: dumpRange( "table-range" ); dumpAddress( "ref1" ); @@ -1295,6 +1313,15 @@ void RecordStreamObject::implDumpRecordBody() dumpRange( "used-range" ); break; + case BIFF12_ID_DISCRETEFILTER: + dumpString( "value" ); + break; + + case BIFF12_ID_DISCRETEFILTERS: + dumpBool< sal_Int32 >( "show-blank" ); + dumpDec< sal_Int32 >( "calendar-type", "DISCRETEFILTERS-CALTYPE" ); + break; + case BIFF12_ID_DRAWING: dumpString( "rel-id" ); break; @@ -1508,6 +1535,11 @@ void RecordStreamObject::implDumpRecordBody() dumpString( "build-version" ); break; + case BIFF12_ID_FILTERCOLUMN: + dumpDec< sal_Int32 >( "column-index" ); + dumpHex< sal_uInt16 >( "flags", "FILTERCOLUMN-FLAGS" ); + break; + case BIFF12_ID_FONT: dumpDec< sal_uInt16 >( "height", "CONV-TWIP-TO-PT" ); dumpHex< sal_uInt16 >( "flags", "FONT-FLAGS" ); diff --git a/oox/source/dump/xlsbdumper.ini b/oox/source/dump/xlsbdumper.ini index 0624eebb3ffc..3490111c4ba5 100644 --- a/oox/source/dump/xlsbdumper.ini +++ b/oox/source/dump/xlsbdumper.ini @@ -174,8 +174,8 @@ multilist=RECORD-NAMES 0x0088=BOOKVIEWS_END,SHEETVIEW,SHEETVIEW_END,CHARTSHEETVIEWS,CHARTSHEETVIEWS_END,CHARTSHEETVIEW,CHARTSHEETVIEW_END,SHEETS 0x0090=SHEETS_END,SHEETDATA,SHEETDATA_END,SHEETPR,DIMENSION,,,PANE 0x0098=SELECTION,WORKBOOKPR,SMARTTAGPR,FILERECOVERYPR,SHEET,CALCPR,WORKBOOKVIEW,SST - 0x00A0=SST_END,AUTOFILTER,AUTOFILTER_END,FILTERCOLUMN,FILTERCOLUMN_END,FILTERS,FILTERS_END,FILTER - 0x00A8=COLORFILTER,ICONFILTER,TOP10FILTER,DYNAMICFILTER,CUSTOMFILTERS,CUSTOMFILTERS_END,CUSTOMFILTER,AUTOFILTERDATEGROUPITEM + 0x00A0=SST_END,AUTOFILTER,AUTOFILTER_END,FILTERCOLUMN,FILTERCOLUMN_END,DISCRETEFILTERS,DISCRETEFILTERS_END,DISCRETEFILTER + 0x00A8=COLORFILTER,ICONFILTER,TOP10FILTER,DYNAMICFILTER,CUSTOMFILTERS,CUSTOMFILTERS_END,CUSTOMFILTER,AFDATEGROUPITEM 0x00B0=MERGECELL,MERGECELLS,MERGECELLS_END,PCDEFINITION,PCDEFINITION_END,PCDFIELDS,PCDFIELDS_END,PCDFIELD 0x00B8=PCDFIELD_END,PCDSOURCE,PCDSOURCE_END,PCDSHEETSOURCE,PCDSHEETSOURCE_END,PCDFSHAREDITEMS,PCDFSHAREDITEMS_END,PCITEM_ARRAY 0x00C0=PCITEM_ARRAY_END,PCRECORDS,PCRECORDS_END,,,,, @@ -242,6 +242,7 @@ end constlist=SIMPLE-RECORDS 0x001A=int32,dec,item-index + 0x00AC=int32,dec,relation,CUSTOMFILTERS-RELATION 0x00B5=int32,dec,count 0x00C1=int32,dec,count 0x00DD=int32,dec,count @@ -405,6 +406,22 @@ flagslist=CONNECTION-STRINGFLAGS 0x0010=has-sso-id end +# CUSTOMFILTER --------------------------------------------------------------- + +constlist=CUSTOMFILTER-DATATYPE + 4=double + 6=string + 8=boolean + 12=blank + 14=not-blank +end + +shortlist=CUSTOMFILTER-OPERATOR,1,less,equal,less-equal,greater,not-equal,greater-equal + +# CUSTOMFILTERS -------------------------------------------------------------- + +shortlist=CUSTOMFILTERS-RELATION,0,and,or + # DATATABLE ------------------------------------------------------------------ flagslist=DATATABLE-FLAGS @@ -459,6 +476,10 @@ constlist=DEFINEDNAME-SHEETID -1=global end +# DISCRETEFILTERS -------------------------------------------------------------------- + +shortlist=DISCRETEFILTERS-CALTYPE,0,none,gregorian,gregorian-us,japan,taiwan,korea,hijri,thai,hebrew,gregorian-mideast-fr,gregorian-ar,gregorian-xlit-en,gregorian-xlit-fr + # DXF ------------------------------------------------------------------------ flagslist=DXF-FLAGS @@ -509,6 +530,13 @@ end shortlist=FILL-GRADIENTTYPE,0,linear,path +# FILTERCOLUMN --------------------------------------------------------------- + +flagslist=FILTERCOLUMN-FLAGS + 0x0001=hidden-button + 0x0002=show-button +end + # FONT ----------------------------------------------------------------------- flagslist=FONT-FLAGS diff --git a/oox/source/token/properties.txt b/oox/source/token/properties.txt index 369c5e5218db..dbbc9de4e0eb 100644 --- a/oox/source/token/properties.txt +++ b/oox/source/token/properties.txt @@ -90,6 +90,7 @@ ContainsHeader Coordinates CopyBack CopyFormulas +CopyOutputData CopyStyles CrossoverPosition CrossoverValue @@ -147,6 +148,7 @@ FillGradientName FillStyle FillTransparence Filter +FilterCriteriaSource FilterOptions FirstLineOffset FirstPageNumber @@ -212,6 +214,7 @@ InputMessage InputTitle IsActive IsAdjustHeightEnabled +IsCaseSensitive IsCellBackgroundTransparent IsChangeReadOnlyEnabled IsDate @@ -284,6 +287,7 @@ NumberingType Offset OpCodeMap Orientation +OutputPosition OverlapSequence PageScale PageStyle @@ -356,6 +360,7 @@ RotationHorizontal RotationVertical RowGrand RowLabelRanges +SaveOutputPosition ScaleMode ScaleToPages ScaleToPagesX @@ -388,6 +393,7 @@ ShowPositiveError ShowZeroValues ShrinkToFit Size +SkipDuplicates SortInfo Sound SoundOn @@ -447,6 +453,7 @@ TriState Type URL Url +UseFilterCriteriaSource UseRegularExpressions UseRings UseSelectedPage diff --git a/oox/source/xls/autofilterbuffer.cxx b/oox/source/xls/autofilterbuffer.cxx new file mode 100755 index 000000000000..15cb2f726327 --- /dev/null +++ b/oox/source/xls/autofilterbuffer.cxx @@ -0,0 +1,856 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "oox/xls/autofilterbuffer.hxx" + +#include <com/sun/star/sheet/FilterConnection.hpp> +#include <com/sun/star/sheet/FilterOperator2.hpp> +#include <com/sun/star/sheet/TableFilterField2.hpp> +#include <com/sun/star/sheet/XDatabaseRange.hpp> +#include <com/sun/star/sheet/XSheetFilterDescriptor2.hpp> +#include <com/sun/star/table/TableOrientation.hpp> +#include <rtl/ustrbuf.hxx> +#include "oox/core/namespaces.hxx" +#include "oox/helper/attributelist.hxx" +#include "oox/helper/propertyset.hxx" +#include "oox/helper/recordinputstream.hxx" +#include "oox/xls/addressconverter.hxx" +#include "oox/xls/biffinputstream.hxx" +#include "oox/xls/defnamesbuffer.hxx" +#include "properties.hxx" +#include "tokens.hxx" + +namespace oox { +namespace xls { + +using namespace ::com::sun::star::sheet; +using namespace ::com::sun::star::table; +using namespace ::com::sun::star::uno; + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +// ============================================================================ + +namespace { + +const sal_uInt8 BIFF12_TOP10FILTER_TOP = 0x01; +const sal_uInt8 BIFF12_TOP10FILTER_PERCENT = 0x02; + +const sal_uInt16 BIFF12_FILTERCOLUMN_HIDDENBUTTON = 0x0001; +const sal_uInt16 BIFF12_FILTERCOLUMN_SHOWBUTTON = 0x0002; + +const sal_uInt16 BIFF_FILTERCOLUMN_OR = 0x0001; +const sal_uInt16 BIFF_FILTERCOLUMN_TOP10FILTER = 0x0010; +const sal_uInt16 BIFF_FILTERCOLUMN_TOP = 0x0020; +const sal_uInt16 BIFF_FILTERCOLUMN_PERCENT = 0x0040; + +const sal_uInt8 BIFF_FILTER_DATATYPE_NONE = 0; +const sal_uInt8 BIFF_FILTER_DATATYPE_RK = 2; +const sal_uInt8 BIFF_FILTER_DATATYPE_DOUBLE = 4; +const sal_uInt8 BIFF_FILTER_DATATYPE_STRING = 6; +const sal_uInt8 BIFF_FILTER_DATATYPE_BOOLEAN = 8; +const sal_uInt8 BIFF_FILTER_DATATYPE_EMPTY = 12; +const sal_uInt8 BIFF_FILTER_DATATYPE_NOTEMPTY = 14; + +// ---------------------------------------------------------------------------- + +bool lclGetApiOperatorFromToken( sal_Int32& rnApiOperator, sal_Int32 nToken ) +{ + switch( nToken ) + { + case XML_lessThan: rnApiOperator = FilterOperator2::NOT_EQUAL; return true; + case XML_equal: rnApiOperator = FilterOperator2::EQUAL; return true; + case XML_lessThanOrEqual: rnApiOperator = FilterOperator2::LESS_EQUAL; return true; + case XML_greaterThan: rnApiOperator = FilterOperator2::GREATER; return true; + case XML_notEqual: rnApiOperator = FilterOperator2::NOT_EQUAL; return true; + case XML_greaterThanOrEqual: rnApiOperator = FilterOperator2::GREATER_EQUAL; return true; + } + return false; +} + +/** Removes leading asterisk characters from the passed string. + @return True = at least one asterisk character has been removed. */ +bool lclTrimLeadingAsterisks( OUString& rValue ) +{ + sal_Int32 nLength = rValue.getLength(); + sal_Int32 nPos = 0; + while( (nPos < nLength) && (rValue[ nPos ] == '*') ) + ++nPos; + if( nPos > 0 ) + { + rValue = rValue.copy( nPos ); + return true; + } + return false; +} + +/** Removes trailing asterisk characters from the passed string. + @return True = at least one asterisk character has been removed. */ +bool lclTrimTrailingAsterisks( OUString& rValue ) +{ + sal_Int32 nLength = rValue.getLength(); + sal_Int32 nPos = nLength; + while( (nPos > 0) && (rValue[ nPos - 1 ] == '*') ) + --nPos; + if( nPos < nLength ) + { + rValue = rValue.copy( 0, nPos ); + return true; + } + return false; +} + +/** Converts wildcard characters '*' and '?' to regular expressions and quotes + RE meta characters. + @return True = passed string has been changed (RE needs to be enabled). */ +bool lclConvertWildcardsToRegExp( OUString& rValue ) +{ + // check existence of the wildcard characters '*' and '?' + if( (rValue.getLength() > 0) && ((rValue.indexOf( '*' ) >= 0) || (rValue.indexOf( '?' ) >= 0)) ) + { + OUStringBuffer aBuffer; + aBuffer.ensureCapacity( rValue.getLength() + 5 ); + const sal_Unicode* pcChar = rValue.getStr(); + const sal_Unicode* pcEnd = pcChar + rValue.getLength(); + for( ; pcChar < pcEnd; ++pcChar ) + { + switch( *pcChar ) + { + case '?': + aBuffer.append( sal_Unicode( '.' ) ); + break; + case '*': + aBuffer.append( sal_Unicode( '.' ) ).append( sal_Unicode( '*' ) ); + break; + case '\\': case '.': case '|': case '(': case ')': case '^': case '$': + // quote RE meta characters + aBuffer.append( sal_Unicode( '\\' ) ).append( *pcChar ); + break; + default: + aBuffer.append( *pcChar ); + } + } + rValue = aBuffer.makeStringAndClear(); + return true; + } + return false; +} + +} // namespace + +// ============================================================================ + +ApiFilterSettings::ApiFilterSettings() +{ +} + +void ApiFilterSettings::appendField( bool bAnd, sal_Int32 nOperator, double fValue ) +{ + maFilterFields.resize( maFilterFields.size() + 1 ); + TableFilterField2& rFilterField = maFilterFields.back(); + rFilterField.Connection = bAnd ? FilterConnection_AND : FilterConnection_OR; + rFilterField.Operator = nOperator; + rFilterField.IsNumeric = sal_True; + rFilterField.NumericValue = fValue; +} + +void ApiFilterSettings::appendField( bool bAnd, sal_Int32 nOperator, const OUString& rValue ) +{ + maFilterFields.resize( maFilterFields.size() + 1 ); + TableFilterField2& rFilterField = maFilterFields.back(); + rFilterField.Connection = bAnd ? FilterConnection_AND : FilterConnection_OR; + rFilterField.Operator = nOperator; + rFilterField.IsNumeric = sal_False; + rFilterField.StringValue = rValue; +} + +// ============================================================================ + +FilterSettingsBase::FilterSettingsBase( const WorkbookHelper& rHelper ) : + WorkbookHelper( rHelper ) +{ +} + +void FilterSettingsBase::importAttribs( sal_Int32 /*nElement*/, const AttributeList& /*rAttribs*/ ) +{ +} + +void FilterSettingsBase::importRecord( sal_Int32 /*nRecId*/, RecordInputStream& /*rStrm*/ ) +{ +} + +void FilterSettingsBase::importBiffRecord( BiffInputStream& /*rStrm*/, sal_uInt16 /*nFlags*/ ) +{ +} + +ApiFilterSettings FilterSettingsBase::finalizeImport( sal_Int32 /*nMaxCount*/ ) +{ + return ApiFilterSettings(); +} + +// ============================================================================ + +DiscreteFilter::DiscreteFilter( const WorkbookHelper& rHelper ) : + FilterSettingsBase( rHelper ), + mnCalendarType( XML_none ), + mbShowBlank( false ) +{ +} + +void DiscreteFilter::importAttribs( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + switch( nElement ) + { + case XLS_TOKEN( filters ): + mnCalendarType = rAttribs.getToken( XML_calendarType, XML_none ); + mbShowBlank = rAttribs.getBool( XML_blank, false ); + break; + + case XLS_TOKEN( filter ): + { + OUString aValue = rAttribs.getXString( XML_val, OUString() ); + if( aValue.getLength() > 0 ) + maValues.push_back( aValue ); + } + break; + } +} + +void DiscreteFilter::importRecord( sal_Int32 nRecId, RecordInputStream& rStrm ) +{ + switch( nRecId ) + { + case BIFF12_ID_DISCRETEFILTERS: + { + sal_Int32 nShowBlank, nCalendarType; + rStrm >> nShowBlank >> nCalendarType; + + static const sal_Int32 spnCalendarTypes[] = { + XML_none, XML_gregorian, XML_gregorianUs, XML_japan, XML_taiwan, XML_korea, XML_hijri, XML_thai, XML_hebrew, + XML_gregorianMeFrench, XML_gregorianArabic, XML_gregorianXlitEnglish, XML_gregorianXlitFrench }; + mnCalendarType = STATIC_ARRAY_SELECT( spnCalendarTypes, nCalendarType, XML_none ); + mbShowBlank = nShowBlank != 0; + } + break; + + case BIFF12_ID_DISCRETEFILTER: + { + OUString aValue = rStrm.readString(); + if( aValue.getLength() > 0 ) + maValues.push_back( aValue ); + } + break; + } +} + +ApiFilterSettings DiscreteFilter::finalizeImport( sal_Int32 nMaxCount ) +{ + ApiFilterSettings aSettings; + if( static_cast< sal_Int32 >( maValues.size() ) <= nMaxCount ) + { + aSettings.maFilterFields.reserve( maValues.size() ); + + // insert all filter values + for( FilterValueVector::iterator aIt = maValues.begin(), aEnd = maValues.end(); aIt != aEnd; ++aIt ) + aSettings.appendField( false, FilterOperator2::EQUAL, *aIt ); + + // extra field for 'show empty' + if( mbShowBlank ) + aSettings.appendField( false, FilterOperator2::EMPTY, OUString() ); + + /* Require disabled regular expressions, filter entries may contain + any RE meta characters. */ + if( !maValues.empty() ) + aSettings.mobNeedsRegExp = false; + } + return aSettings; +} + +// ============================================================================ + +Top10Filter::Top10Filter( const WorkbookHelper& rHelper ) : + FilterSettingsBase( rHelper ), + mfValue( 0.0 ), + mbTop( true ), + mbPercent( false ) +{ +} + +void Top10Filter::importAttribs( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + if( nElement == XLS_TOKEN( top10 ) ) + { + mfValue = rAttribs.getDouble( XML_val, 0.0 ); + mbTop = rAttribs.getBool( XML_top, true ); + mbPercent = rAttribs.getBool( XML_percent, false ); + } +} + +void Top10Filter::importRecord( sal_Int32 nRecId, RecordInputStream& rStrm ) +{ + if( nRecId == BIFF12_ID_TOP10FILTER ) + { + sal_uInt8 nFlags; + rStrm >> nFlags >> mfValue; + mbTop = getFlag( nFlags, BIFF12_TOP10FILTER_TOP ); + mbPercent = getFlag( nFlags, BIFF12_TOP10FILTER_PERCENT ); + } +} + +void Top10Filter::importBiffRecord( BiffInputStream& /*rStrm*/, sal_uInt16 nFlags ) +{ + mfValue = extractValue< sal_uInt16 >( nFlags, 7, 9 ); + mbTop = getFlag( nFlags, BIFF_FILTERCOLUMN_TOP ); + mbPercent = getFlag( nFlags, BIFF_FILTERCOLUMN_PERCENT ); +} + +ApiFilterSettings Top10Filter::finalizeImport( sal_Int32 /*nMaxCount*/ ) +{ + sal_Int32 nOperator = mbTop ? + (mbPercent ? FilterOperator2::TOP_PERCENT : FilterOperator2::TOP_VALUES) : + (mbPercent ? FilterOperator2::BOTTOM_PERCENT : FilterOperator2::BOTTOM_VALUES); + ApiFilterSettings aSettings; + aSettings.appendField( true, nOperator, mfValue ); + return aSettings; +} + +// ============================================================================ + +FilterCriterionModel::FilterCriterionModel() : + mnOperator( XML_equal ), + mnDataType( BIFF_FILTER_DATATYPE_NONE ), + mnStrLen( 0 ) +{ +} + +void FilterCriterionModel::setBiffOperator( sal_uInt8 nOperator ) +{ + static const sal_Int32 spnOperators[] = { XML_TOKEN_INVALID, + XML_lessThan, XML_equal, XML_lessThanOrEqual, XML_greaterThan, XML_notEqual, XML_greaterThanOrEqual }; + mnOperator = STATIC_ARRAY_SELECT( spnOperators, nOperator, XML_TOKEN_INVALID ); +} + +void FilterCriterionModel::readBiffData( RecordInputStream& rStrm ) +{ + sal_uInt8 nOperator; + rStrm >> mnDataType >> nOperator; + setBiffOperator( nOperator ); + + switch( mnDataType ) + { + case BIFF_FILTER_DATATYPE_DOUBLE: + maValue <<= rStrm.readDouble(); + break; + case BIFF_FILTER_DATATYPE_STRING: + { + rStrm.skip( 8 ); + OUString aValue = rStrm.readString().trim(); + if( aValue.getLength() > 0 ) + maValue <<= aValue; + } + break; + case BIFF_FILTER_DATATYPE_BOOLEAN: + maValue <<= (rStrm.readuInt8() != 0); + rStrm.skip( 7 ); + break; + case BIFF_FILTER_DATATYPE_EMPTY: + rStrm.skip( 8 ); + if( mnOperator == XML_equal ) + maValue <<= OUString(); + break; + case BIFF_FILTER_DATATYPE_NOTEMPTY: + rStrm.skip( 8 ); + if( mnOperator == XML_notEqual ) + maValue <<= OUString(); + break; + default: + OSL_ENSURE( false, "FilterCriterionModel::readBiffData - unexpected data type" ); + rStrm.skip( 8 ); + } +} + +void FilterCriterionModel::readBiffData( BiffInputStream& rStrm ) +{ + sal_uInt8 nOperator; + rStrm >> mnDataType >> nOperator; + setBiffOperator( nOperator ); + + switch( mnDataType ) + { + case BIFF_FILTER_DATATYPE_NONE: + rStrm.skip( 8 ); + break; + case BIFF_FILTER_DATATYPE_RK: + maValue <<= BiffHelper::calcDoubleFromRk( rStrm.readInt32() ); + rStrm.skip( 4 ); + break; + case BIFF_FILTER_DATATYPE_DOUBLE: + maValue <<= rStrm.readDouble(); + break; + case BIFF_FILTER_DATATYPE_STRING: + rStrm.skip( 4 ); + rStrm >> mnStrLen; + rStrm.skip( 3 ); + break; + case BIFF_FILTER_DATATYPE_BOOLEAN: + { + sal_uInt8 nValue, nType; + rStrm >> nValue >> nType; + rStrm.skip( 6 ); + switch( nType ) + { + case BIFF_BOOLERR_BOOL: maValue <<= (nValue != 0); break; + case BIFF_BOOLERR_ERROR: maValue <<= BiffHelper::calcDoubleFromError( nValue ); break; + default: OSL_ENSURE( false, "FilterCriterionModel::readBiffData - unknown type" ); + } + } + break; + case BIFF_FILTER_DATATYPE_EMPTY: + rStrm.skip( 8 ); + if( mnOperator == XML_equal ) + maValue <<= OUString(); + break; + case BIFF_FILTER_DATATYPE_NOTEMPTY: + rStrm.skip( 8 ); + if( mnOperator == XML_notEqual ) + maValue <<= OUString(); + break; + default: + OSL_ENSURE( false, "FilterCriterionModel::readBiffData - unexpected data type" ); + rStrm.skip( 8 ); + } +} + +void FilterCriterionModel::readString( BiffInputStream& rStrm, BiffType eBiff, rtl_TextEncoding eTextEnc ) +{ + if( (mnDataType == BIFF_FILTER_DATATYPE_STRING) && (mnStrLen > 0) ) + { + OUString aValue = (eBiff == BIFF8) ? + rStrm.readUniStringBody( mnStrLen, true ) : + rStrm.readCharArrayUC( mnStrLen, eTextEnc, true ); + aValue = aValue.trim(); + if( aValue.getLength() > 0 ) + maValue <<= aValue; + } +} + +// ---------------------------------------------------------------------------- + +CustomFilter::CustomFilter( const WorkbookHelper& rHelper ) : + FilterSettingsBase( rHelper ), + mbAnd( false ) +{ +} + +void CustomFilter::importAttribs( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + switch( nElement ) + { + case XLS_TOKEN( customFilters ): + mbAnd = rAttribs.getBool( XML_and, false ); + break; + + case XLS_TOKEN( customFilter ): + { + FilterCriterionModel aCriterion; + aCriterion.mnOperator = rAttribs.getToken( XML_operator, XML_equal ); + OUString aValue = rAttribs.getXString( XML_val, OUString() ).trim(); + if( (aCriterion.mnOperator == XML_equal) || (aCriterion.mnOperator == XML_notEqual) || (aValue.getLength() > 0) ) + aCriterion.maValue <<= aValue; + appendCriterion( aCriterion ); + } + break; + } +} + +void CustomFilter::importRecord( sal_Int32 nRecId, RecordInputStream& rStrm ) +{ + switch( nRecId ) + { + case BIFF12_ID_CUSTOMFILTERS: + mbAnd = rStrm.readInt32() == 0; + break; + + case BIFF12_ID_CUSTOMFILTER: + { + FilterCriterionModel aCriterion; + aCriterion.readBiffData( rStrm ); + appendCriterion( aCriterion ); + } + break; + } +} + +void CustomFilter::importBiffRecord( BiffInputStream& rStrm, sal_uInt16 nFlags ) +{ + mbAnd = !getFlag( nFlags, BIFF_FILTERCOLUMN_OR ); + + FilterCriterionModel aCriterion1, aCriterion2; + aCriterion1.readBiffData( rStrm ); + aCriterion2.readBiffData( rStrm ); + aCriterion1.readString( rStrm, getBiff(), getTextEncoding() ); + aCriterion2.readString( rStrm, getBiff(), getTextEncoding() ); + appendCriterion( aCriterion1 ); + appendCriterion( aCriterion2 ); +} + +ApiFilterSettings CustomFilter::finalizeImport( sal_Int32 /*nMaxCount*/ ) +{ + ApiFilterSettings aSettings; + OSL_ENSURE( maCriteria.size() <= 2, "CustomFilter::finalizeImport - too many filter criteria" ); + for( FilterCriterionVector::iterator aIt = maCriteria.begin(), aEnd = maCriteria.end(); aIt != aEnd; ++aIt ) + { + // first extract the filter operator + sal_Int32 nOperator = 0; + bool bValidOperator = lclGetApiOperatorFromToken( nOperator, aIt->mnOperator ); + if( bValidOperator ) + { + if( aIt->maValue.has< OUString >() ) + { + // string argument + OUString aValue; + aIt->maValue >>= aValue; + // check for 'empty', 'contains', 'begins with', or 'ends with' text filters + bool bEqual = nOperator == FilterOperator2::EQUAL; + bool bNotEqual = nOperator == FilterOperator2::NOT_EQUAL; + if( bEqual || bNotEqual ) + { + if( aValue.getLength() == 0 ) + { + // empty comparison string: create empty/not empty filters + nOperator = bNotEqual ? FilterOperator2::NOT_EMPTY : FilterOperator2::EMPTY; + } + else + { + // compare to something: try to find begins/ends/contains + bool bHasLeadingAsterisk = lclTrimLeadingAsterisks( aValue ); + bool bHasTrailingAsterisk = lclTrimTrailingAsterisks( aValue ); + // just '***' matches everything, do not create a filter field + bValidOperator = aValue.getLength() > 0; + if( bValidOperator ) + { + if( bHasLeadingAsterisk && bHasTrailingAsterisk ) + nOperator = bNotEqual ? FilterOperator2::DOES_NOT_CONTAIN : FilterOperator2::CONTAINS; + else if( bHasLeadingAsterisk ) + nOperator = bNotEqual ? FilterOperator2::DOES_NOT_END_WITH : FilterOperator2::ENDS_WITH; + else if( bHasTrailingAsterisk ) + nOperator = bNotEqual ? FilterOperator2::DOES_NOT_BEGIN_WITH : FilterOperator2::BEGINS_WITH; + // else: no asterisks, stick to equal/not equal + } + } + } + + if( bValidOperator ) + { + // if wildcards are present, require RE mode, otherwise keep don't care state + if( lclConvertWildcardsToRegExp( aValue ) ) + aSettings.mobNeedsRegExp = true; + // create a new UNO API filter field + aSettings.appendField( mbAnd, nOperator, aValue ); + } + } + else if( aIt->maValue.has< double >() ) + { + // floating-point argument + double fValue; + aIt->maValue >>= fValue; + aSettings.appendField( mbAnd, nOperator, fValue ); + } + } + } + return aSettings; +} + +void CustomFilter::appendCriterion( const FilterCriterionModel& rCriterion ) +{ + if( (rCriterion.mnOperator != XML_TOKEN_INVALID) && rCriterion.maValue.hasValue() ) + maCriteria.push_back( rCriterion ); +} + +// ============================================================================ + +FilterColumn::FilterColumn( const WorkbookHelper& rHelper ) : + WorkbookHelper( rHelper ), + mnColId( -1 ), + mbHiddenButton( false ), + mbShowButton( true ) +{ +} + +void FilterColumn::importFilterColumn( const AttributeList& rAttribs ) +{ + mnColId = rAttribs.getInteger( XML_colId, -1 ); + mbHiddenButton = rAttribs.getBool( XML_hiddenButton, false ); + mbShowButton = rAttribs.getBool( XML_showButton, true ); +} + +void FilterColumn::importFilterColumn( RecordInputStream& rStrm ) +{ + sal_uInt16 nFlags; + rStrm >> mnColId >> nFlags; + mbHiddenButton = getFlag( nFlags, BIFF12_FILTERCOLUMN_HIDDENBUTTON ); + mbShowButton = getFlag( nFlags, BIFF12_FILTERCOLUMN_SHOWBUTTON ); +} + +void FilterColumn::importFilterColumn( BiffInputStream& rStrm ) +{ + sal_uInt16 nFlags; + mnColId = rStrm.readuInt16(); + rStrm >> nFlags; + + // BIFF5/BIFF8 support top-10 filters and custom filters + if( getFlag( nFlags, BIFF_FILTERCOLUMN_TOP10FILTER ) ) + createFilterSettings< Top10Filter >().importBiffRecord( rStrm, nFlags ); + else + createFilterSettings< CustomFilter >().importBiffRecord( rStrm, nFlags ); +} + +ApiFilterSettings FilterColumn::finalizeImport( sal_Int32 nMaxCount ) +{ + ApiFilterSettings aSettings; + if( (0 <= mnColId) && mxSettings.get() ) + { + // filter settings object creates a sequence of filter fields + aSettings = mxSettings->finalizeImport( nMaxCount ); + // add column index to all filter fields + for( ApiFilterSettings::FilterFieldVector::iterator aIt = aSettings.maFilterFields.begin(), aEnd = aSettings.maFilterFields.end(); aIt != aEnd; ++aIt ) + aIt->Field = mnColId; + } + return aSettings; +} + +// ============================================================================ + +AutoFilter::AutoFilter( const WorkbookHelper& rHelper ) : + WorkbookHelper( rHelper ) +{ +} + +void AutoFilter::importAutoFilter( const AttributeList& rAttribs, sal_Int16 nSheet ) +{ + OUString aRangeStr = rAttribs.getString( XML_ref, OUString() ); + getAddressConverter().convertToCellRangeUnchecked( maRange, aRangeStr, nSheet ); +} + +void AutoFilter::importAutoFilter( RecordInputStream& rStrm, sal_Int16 nSheet ) +{ + BinRange aBinRange; + rStrm >> aBinRange; + getAddressConverter().convertToCellRangeUnchecked( maRange, aBinRange, nSheet ); +} + +FilterColumn& AutoFilter::createFilterColumn() +{ + FilterColumnVector::value_type xFilterColumn( new FilterColumn( *this ) ); + maFilterColumns.push_back( xFilterColumn ); + return *xFilterColumn; +} + +void AutoFilter::finalizeImport( const Reference< XSheetFilterDescriptor2 >& rxFilterDesc ) +{ + if( rxFilterDesc.is() ) + { + // set some common properties for the auto filter range + PropertySet aDescProps( rxFilterDesc ); + aDescProps.setProperty( PROP_IsCaseSensitive, false ); + aDescProps.setProperty( PROP_SkipDuplicates, false ); + aDescProps.setProperty( PROP_Orientation, TableOrientation_ROWS ); + aDescProps.setProperty( PROP_ContainsHeader, true ); + aDescProps.setProperty( PROP_CopyOutputData, false ); + + // maximum number of UNO API filter fields + sal_Int32 nMaxCount = 0; + aDescProps.getProperty( nMaxCount, PROP_MaxFieldCount ); + OSL_ENSURE( nMaxCount > 0, "AutoFilter::finalizeImport - invalid maximum filter field count" ); + + // resulting list of all UNO API filter fields + ::std::vector< TableFilterField2 > aFilterFields; + + // track if columns require to enable or disable regular expressions + OptValue< bool > obNeedsRegExp; + + /* Track whether the filter fields of the first filter column are + connected with 'or'. In this case, other filter fields cannot be + inserted without altering the result of the entire filter, due to + Calc's precedence for the 'and' connection operator. Example: + Excel's filter conditions 'A1 and (B1 or B2) and C1' where B1 and + B2 belong to filter column B, will be evaluated by Calc as + '(A1 and B1) or (B2 and C1)'. */ + bool bHasOrConnection = false; + + // process all filter column objects, exit when 'or' connection exists + for( FilterColumnVector::iterator aIt = maFilterColumns.begin(), aEnd = maFilterColumns.end(); !bHasOrConnection && (aIt != aEnd); ++aIt ) + { + // the filter settings object creates a list of filter fields + ApiFilterSettings aSettings = (*aIt)->finalizeImport( nMaxCount ); + ApiFilterSettings::FilterFieldVector& rColumnFields = aSettings.maFilterFields; + + // new total number of filter fields + sal_Int32 nNewCount = static_cast< sal_Int32 >( aFilterFields.size() + rColumnFields.size() ); + + /* Check whether mode for regular expressions is compatible with + the global mode in obNeedsRegExp. If either one is still in + don't-care state, all is fine. If both are set, they must be + equal. */ + bool bRegExpCompatible = !obNeedsRegExp || !aSettings.mobNeedsRegExp || (obNeedsRegExp.get() == aSettings.mobNeedsRegExp.get()); + + // check whether fields are connected by 'or' (see comments above). + if( rColumnFields.size() >= 2 ) + for( ApiFilterSettings::FilterFieldVector::iterator aSIt = rColumnFields.begin() + 1, aSEnd = rColumnFields.end(); !bHasOrConnection && (aSIt != aSEnd); ++aSIt ) + bHasOrConnection = aSIt->Connection == FilterConnection_OR; + + /* Skip the column filter, if no filter fields have been created, + if the number of new filter fields would exceed the total limit + of filter fields, or if the mode for regular expressions of the + filter column does not fit. */ + if( !rColumnFields.empty() && (nNewCount <= nMaxCount) && bRegExpCompatible ) + { + /* Add 'and' connection to the first filter field to connect + it to the existing filter fields of other columns. */ + rColumnFields[ 0 ].Connection = FilterConnection_AND; + + // insert the new filter fields + aFilterFields.insert( aFilterFields.end(), rColumnFields.begin(), rColumnFields.end() ); + + // update the regular expressions mode + obNeedsRegExp.assignIfUsed( aSettings.mobNeedsRegExp ); + } + } + + // insert all filter fields to the filter descriptor + if( !aFilterFields.empty() ) + rxFilterDesc->setFilterFields2( ContainerHelper::vectorToSequence( aFilterFields ) ); + + // regular expressions + bool bUseRegExp = obNeedsRegExp.get( false ); + aDescProps.setProperty( PROP_UseRegularExpressions, bUseRegExp ); + } +} + +// ============================================================================ + +AutoFilterBuffer::AutoFilterBuffer( const WorkbookHelper& rHelper ) : + WorkbookHelper( rHelper ) +{ +} + +AutoFilter& AutoFilterBuffer::createAutoFilter() +{ + AutoFilterVector::value_type xAutoFilter( new AutoFilter( *this ) ); + maAutoFilters.push_back( xAutoFilter ); + return *xAutoFilter; +} + +void AutoFilterBuffer::finalizeImport( sal_Int16 nSheet ) +{ + // rely on existence of the defined name '_FilterDatabase' containing the range address of the filtered area + if( const DefinedName* pFilterDBName = getDefinedNames().getByBuiltinId( BIFF_DEFNAME_FILTERDATABASE, nSheet ).get() ) + { + CellRangeAddress aFilterRange; + if( pFilterDBName->getAbsoluteRange( aFilterRange ) && (aFilterRange.Sheet == nSheet) ) + { + // use the same name for the database range as used for the defined name '_FilterDatabase' + OUString aDBRangeName = pFilterDBName->getCalcName(); + Reference< XDatabaseRange > xDatabaseRange = createDatabaseRangeObject( aDBRangeName, aFilterRange ); + // first, try to create an auto filter + bool bHasAutoFilter = finalizeImport( xDatabaseRange ); + // no success: try to create an advanced filter + if( !bHasAutoFilter && xDatabaseRange.is() ) + { + // the built-in defined name 'Criteria' must exist + if( const DefinedName* pCriteriaName = getDefinedNames().getByBuiltinId( BIFF_DEFNAME_CRITERIA, nSheet ).get() ) + { + CellRangeAddress aCriteriaRange; + if( pCriteriaName->getAbsoluteRange( aCriteriaRange ) ) + { + // set some common properties for the filter descriptor + PropertySet aDescProps( xDatabaseRange->getFilterDescriptor() ); + aDescProps.setProperty( PROP_IsCaseSensitive, false ); + aDescProps.setProperty( PROP_SkipDuplicates, false ); + aDescProps.setProperty( PROP_Orientation, TableOrientation_ROWS ); + aDescProps.setProperty( PROP_ContainsHeader, true ); + // criteria range may contain wildcards, but these are incompatible with REs + aDescProps.setProperty( PROP_UseRegularExpressions, false ); + + // position of output data (if built-in defined name 'Extract' exists) + DefinedNameRef xExtractName = getDefinedNames().getByBuiltinId( BIFF_DEFNAME_EXTRACT, nSheet ); + CellRangeAddress aOutputRange; + bool bHasOutputRange = xExtractName.get() && xExtractName->getAbsoluteRange( aOutputRange ); + aDescProps.setProperty( PROP_CopyOutputData, bHasOutputRange ); + if( bHasOutputRange ) + { + aDescProps.setProperty( PROP_SaveOutputPosition, true ); + aDescProps.setProperty( PROP_OutputPosition, CellAddress( aOutputRange.Sheet, aOutputRange.StartColumn, aOutputRange.StartRow ) ); + } + + /* Properties of the database range (must be set after + modifying properties of the filter descriptor, + otherwise the 'FilterCriteriaSource' property gets + deleted). */ + PropertySet aRangeProps( xDatabaseRange ); + aRangeProps.setProperty( PROP_AutoFilter, false ); + aRangeProps.setProperty( PROP_FilterCriteriaSource, aCriteriaRange ); + } + } + } + } + } +} + +bool AutoFilterBuffer::finalizeImport( const Reference< XDatabaseRange >& rxDatabaseRange ) +{ + AutoFilter* pAutoFilter = getActiveAutoFilter(); + if( pAutoFilter && rxDatabaseRange.is() ) try + { + // the property 'AutoFilter' enables the drop-down buttons + PropertySet aRangeProps( rxDatabaseRange ); + aRangeProps.setProperty( PROP_AutoFilter, true ); + // convert filter settings using the filter descriptor of the database range + Reference< XSheetFilterDescriptor2 > xFilterDesc( rxDatabaseRange->getFilterDescriptor(), UNO_QUERY_THROW ); + pAutoFilter->finalizeImport( xFilterDesc ); + // return true to indicate enabled autofilter + return true; + } + catch( Exception& ) + { + } + return false; +} + +AutoFilter* AutoFilterBuffer::getActiveAutoFilter() +{ + // Excel expects not more than one auto filter per sheet or table + OSL_ENSURE( maAutoFilters.size() == 1, "AutoFilterBuffer::getActiveAutoFilter - too many auto filters" ); + // stick to the last imported auto filter + return maAutoFilters.empty() ? 0 : maAutoFilters.back().get(); +} + +// ============================================================================ + +} // namespace xls +} // namespace oox diff --git a/oox/source/xls/autofiltercontext.cxx b/oox/source/xls/autofiltercontext.cxx index 87514d7804c5..d88e7026b80f 100644 --- a/oox/source/xls/autofiltercontext.cxx +++ b/oox/source/xls/autofiltercontext.cxx @@ -27,745 +27,156 @@ #include "oox/xls/autofiltercontext.hxx" -#include <com/sun/star/container/XNameAccess.hpp> -#include <com/sun/star/container/XNamed.hpp> -#include <com/sun/star/i18n/XLocaleData.hpp> -#include <com/sun/star/sheet/FilterConnection.hpp> -#include <com/sun/star/sheet/FilterOperator.hpp> -#include <com/sun/star/sheet/XDatabaseRange.hpp> -#include <com/sun/star/sheet/XDatabaseRanges.hpp> -#include <com/sun/star/sheet/XSheetFilterDescriptor.hpp> -#include <com/sun/star/table/XCellRange.hpp> -#include <rtl/ustrbuf.hxx> -#include "oox/core/filterbase.hxx" -#include "oox/helper/attributelist.hxx" -#include "oox/helper/propertyset.hxx" -#include "oox/xls/addressconverter.hxx" -#include "properties.hxx" - -#define DEBUG_OOX_AUTOFILTER 0 - -#if USE_SC_MULTI_STRING_FILTER_PATCH -#include <com/sun/star/sheet/XExtendedSheetFilterDescriptor.hpp> -#include <com/sun/star/sheet/TableFilterFieldNormal.hpp> -#include <com/sun/star/sheet/TableFilterFieldMultiString.hpp> -using ::com::sun::star::sheet::TableFilterFieldNormal; -using ::com::sun::star::sheet::TableFilterFieldMultiString; -using ::com::sun::star::sheet::XExtendedSheetFilterDescriptor; -#else -#include <com/sun/star/sheet/TableFilterField.hpp> -using ::com::sun::star::sheet::TableFilterField; -#endif - -#if DEBUG_OOX_AUTOFILTER -#include <stdio.h> -#endif - -using ::rtl::OUString; -using ::rtl::OUStringBuffer; -using ::com::sun::star::uno::Reference; -using ::com::sun::star::uno::Exception; -using ::com::sun::star::uno::Sequence; -using ::com::sun::star::uno::UNO_QUERY; -using ::com::sun::star::uno::UNO_QUERY_THROW; -using ::com::sun::star::container::XNameAccess; -using ::com::sun::star::container::XNamed; -using ::com::sun::star::table::CellRangeAddress; -using ::com::sun::star::table::XCellRange; -using ::com::sun::star::sheet::XDatabaseRange; -using ::com::sun::star::sheet::XDatabaseRanges; -using ::com::sun::star::sheet::XSheetFilterDescriptor; -using ::com::sun::star::i18n::LocaleDataItem; -using ::com::sun::star::i18n::XLocaleData; -using ::com::sun::star::lang::Locale; -using ::oox::core::ContextHandlerRef; +#include "oox/xls/autofilterbuffer.hxx" +#include "oox/xls/biffinputstream.hxx" namespace oox { namespace xls { -// ============================================================================ - -FilterFieldItem::FilterFieldItem() : -#if USE_SC_MULTI_STRING_FILTER_PATCH - mpField(new TableFilterFieldNormal), -#else - mpField(new TableFilterField), -#endif - meType(NORMAL) -{ -} - -FilterFieldItem::FilterFieldItem(Type eType) : - meType(eType) -{ -#if USE_SC_MULTI_STRING_FILTER_PATCH - switch ( eType ) - { - case MULTI_STRING: - mpField.reset(new TableFilterFieldMultiString); - break; - case NORMAL: - mpField.reset(new TableFilterFieldNormal); - break; - default: - mpField.reset(new TableFilterFieldNormal); - } -#else - mpField.reset(new TableFilterField); - meType = NORMAL; -#endif -} +using ::oox::core::ContextHandlerRef; +using ::rtl::OUString; // ============================================================================ -AutoFilterContext::AutoFilterContext( WorksheetFragmentBase& rFragment ) : - WorksheetContextBase( rFragment ), - mbValidAddress( false ), - mbUseRegex( false ), - mbShowBlank( false ), - mbConnectionAnd( false ) +FilterSettingsContext::FilterSettingsContext( WorksheetContextBase& rParent, FilterSettingsBase& rFilterSettings ) : + WorksheetContextBase( rParent ), + mrFilterSettings( rFilterSettings ) { } -ContextHandlerRef AutoFilterContext::onCreateContext( sal_Int32 nElement, const AttributeList& ) +ContextHandlerRef FilterSettingsContext::onCreateContext( sal_Int32 nElement, const AttributeList& /*rAttribs*/ ) { switch( getCurrentElement() ) { - case XLS_TOKEN( autoFilter ): - switch( nElement ) - { - case XLS_TOKEN( filterColumn ): return this; - } - break; - - case XLS_TOKEN( filterColumn ): - switch( nElement ) - { - case XLS_TOKEN( filters ): - case XLS_TOKEN( customFilters ): - case XLS_TOKEN( top10 ): - case XLS_TOKEN( dynamicFilter ): return this; - } - break; - case XLS_TOKEN( filters ): - switch( nElement ) - { - case XLS_TOKEN( filter ): return this; - } + if( nElement == XLS_TOKEN( filter ) ) return this; break; - case XLS_TOKEN( customFilters ): - switch( nElement ) - { - case XLS_TOKEN( customFilter ): return this; - } + if( nElement == XLS_TOKEN( customFilter ) ) return this; break; } return 0; } -void AutoFilterContext::onStartElement( const AttributeList& rAttribs ) +void FilterSettingsContext::onStartElement( const AttributeList& rAttribs ) { - switch( getCurrentElement() ) - { - case XLS_TOKEN( autoFilter ): - importAutoFilter( rAttribs ); - break; - case XLS_TOKEN( filterColumn ): - if ( mbValidAddress ) - importFilterColumn( rAttribs ); - break; - case XLS_TOKEN( filters ): - if ( mbValidAddress ) - importFilters( rAttribs ); - break; - case XLS_TOKEN( filter ): - if ( mbValidAddress ) - importFilter( rAttribs ); - break; - case XLS_TOKEN( customFilters ): - if ( mbValidAddress ) - importCustomFilters( rAttribs ); - break; - case XLS_TOKEN( customFilter ): - if ( mbValidAddress ) - importCustomFilter( rAttribs ); - break; - case XLS_TOKEN( top10 ): - if ( mbValidAddress ) - importTop10( rAttribs ); - break; - case XLS_TOKEN( dynamicFilter ): - if ( mbValidAddress ) - importDynamicFilter( rAttribs ); - break; - } + mrFilterSettings.importAttribs( getCurrentElement(), rAttribs ); } -void AutoFilterContext::onEndElement() +ContextHandlerRef FilterSettingsContext::onCreateRecordContext( sal_Int32 nRecId, RecordInputStream& /*rStrm*/ ) { switch( getCurrentElement() ) { - case XLS_TOKEN( autoFilter ): - maybeShowBlank(); - setAutoFilter(); + case BIFF12_ID_DISCRETEFILTERS: + if( nRecId == BIFF12_ID_DISCRETEFILTER ) return this; break; - case XLS_TOKEN( filters ): - setFilterNames(); + case BIFF12_ID_CUSTOMFILTERS: + if( nRecId == BIFF12_ID_CUSTOMFILTER ) return this; break; } + return 0; } -#if DEBUG_OOX_AUTOFILTER -static void lclPrintNormalField( -#if USE_SC_MULTI_STRING_FILTER_PATCH - TableFilterFieldNormal* pField -#else - TableFilterField* pField -#endif -) +void FilterSettingsContext::onStartRecord( RecordInputStream& rStrm ) { - using namespace ::com::sun::star::sheet; - - printf(" Operator: "); - switch ( pField->Operator ) - { - case FilterOperator_EQUAL: - printf("EQUAL"); - break; - case FilterOperator_NOT_EQUAL: - printf("NOT_EQUAL"); - break; - case com::sun::star::sheet::FilterOperator_GREATER: - printf("GREATER"); - break; - case com::sun::star::sheet::FilterOperator_GREATER_EQUAL: - printf("GREATER_EQUAL"); - break; - case FilterOperator_LESS: - printf("LESS"); - break; - case FilterOperator_LESS_EQUAL: - printf("LESS_EQUAL"); - break; - case FilterOperator_NOT_EMPTY: - printf("NOT_EMPTY"); - break; - case FilterOperator_EMPTY: - printf("EMPTY"); - break; - case FilterOperator_BOTTOM_PERCENT: - printf("BOTTOM_PERCENT"); - break; - case FilterOperator_BOTTOM_VALUES: - printf("BOTTOM_VALUES"); - break; - case FilterOperator_TOP_PERCENT: - printf("TOP_PERCENT"); - break; - case FilterOperator_TOP_VALUES: - printf("TOP_VALUES"); - break; - default: - printf("other"); - } - printf("\n"); - - printf(" StringValue: %s\n", - OUStringToOString(pField->StringValue, RTL_TEXTENCODING_UTF8).getStr()); - - printf(" NumericValue: %g\n", pField->NumericValue); - - printf(" IsNumeric: "); - if (pField->IsNumeric) - printf("yes\n"); - else - printf("no\n"); + mrFilterSettings.importRecord( getCurrentElement(), rStrm ); } -static void lclPrintFieldConnection( ::com::sun::star::sheet::FilterConnection eConn ) -{ - using namespace ::com::sun::star::sheet; +// ============================================================================ - printf(" Connection: "); - switch ( eConn ) - { - case FilterConnection_AND: - printf("AND"); - break; - case FilterConnection_OR: - printf("OR"); - break; - case FilterConnection_MAKE_FIXED_SIZE: - printf("MAKE_FIXED_SIZE"); - break; - default: - printf("other"); - } - printf("\n"); +FilterColumnContext::FilterColumnContext( WorksheetContextBase& rParent, FilterColumn& rFilterColumn ) : + WorksheetContextBase( rParent ), + mrFilterColumn( rFilterColumn ) +{ } -static void lclPrintFilterField( const FilterFieldItem& aItem ) +ContextHandlerRef FilterColumnContext::onCreateContext( sal_Int32 nElement, const AttributeList& /*rAttribs*/ ) { - using namespace ::com::sun::star::sheet; - - printf("----------------------------------------\n"); -#if USE_SC_MULTI_STRING_FILTER_PATCH - { - // Print common fields first. - - TableFilterFieldBase* pField = aItem.mpField.get(); - printf(" Field: %ld\n", pField->Field); - lclPrintFieldConnection(pField->Connection); - } - switch ( aItem.meType ) + if( getCurrentElement() == XLS_TOKEN( filterColumn ) ) switch( nElement ) { - case FilterFieldItem::NORMAL: - { - TableFilterFieldNormal* pField = static_cast<TableFilterFieldNormal*>(aItem.mpField.get()); - lclPrintNormalField(pField); - } - break; - case FilterFieldItem::MULTI_STRING: - { - TableFilterFieldMultiString* pMultiStrField = static_cast<TableFilterFieldMultiString*>(aItem.mpField.get()); - sal_Int32 nSize = pMultiStrField->StringSet.getLength(); - printf(" StringSet:\n"); - for ( sal_Int32 i = 0; i < nSize; ++i ) - { - printf(" * %s\n", - OUStringToOString(pMultiStrField->StringSet[i], RTL_TEXTENCODING_UTF8).getStr()); - } - } - break; + case XLS_TOKEN( filters ): + return new FilterSettingsContext( *this, mrFilterColumn.createFilterSettings< DiscreteFilter >() ); + case XLS_TOKEN( top10 ): + return new FilterSettingsContext( *this, mrFilterColumn.createFilterSettings< Top10Filter >() ); + case XLS_TOKEN( customFilters ): + return new FilterSettingsContext( *this, mrFilterColumn.createFilterSettings< CustomFilter >() ); } -#else - TableFilterField* pField = aItem.mpField.get(); - printf(" Field: %ld\n", pField->Field); - lclPrintFieldConnection(pField->Connection); - lclPrintNormalField(pField); - -#endif - fflush(stdout); + return 0; } -#endif -void AutoFilterContext::initialize() +void FilterColumnContext::onStartElement( const AttributeList& rAttribs ) { - maFields.clear(); - maFilterNames.clear(); - mbValidAddress = mbShowBlank = mbUseRegex = mbConnectionAnd = false; + mrFilterColumn.importFilterColumn( rAttribs ); } -void AutoFilterContext::setAutoFilter() +ContextHandlerRef FilterColumnContext::onCreateRecordContext( sal_Int32 nRecId, RecordInputStream& /*rStrm*/ ) { - using namespace ::com::sun::star::sheet; - - // Name this built-in database. - OUStringBuffer sDataAreaNameBuf( CREATE_OUSTRING("Excel_BuiltIn__FilterDatabase_ ") ); - sDataAreaNameBuf.append( static_cast<sal_Int32>(getSheetIndex()+1) ); - - OUString sDataAreaName = sDataAreaNameBuf.makeStringAndClear(); - Reference< XCellRange > xCellRange = getCellRange( maAutoFilterRange ); - - // Create a new database range, add filters to it and refresh the database - // for that to take effect. - - PropertySet aDocProps( getDocument() ); - Reference< XDatabaseRanges > xDBRanges( aDocProps.getAnyProperty( PROP_DatabaseRanges ), UNO_QUERY ); - OSL_ENSURE( xDBRanges.is(), "AutoFilterContext::setAutoFilter: DBRange empty" ); - if ( !xDBRanges.is() ) - return; - - Reference< XNameAccess > xNA( xDBRanges, UNO_QUERY_THROW ); - if ( !xNA->hasByName( sDataAreaName ) ) - xDBRanges->addNewByName( sDataAreaName, maAutoFilterRange ); - - Reference< XDatabaseRange > xDB( xNA->getByName( sDataAreaName ), UNO_QUERY ); - if ( xDB.is() ) - { - PropertySet aProp( xDB ); - aProp.setProperty( PROP_AutoFilter, true ); - } - - sal_Int32 nSize = maFields.size(); - sal_Int32 nMaxFieldCount = nSize; - Reference< XSheetFilterDescriptor > xDescriptor = xDB->getFilterDescriptor(); - if ( xDescriptor.is() ) - { - PropertySet aProp( xDescriptor ); - aProp.setProperty( PROP_ContainsHeader, true ); - aProp.setProperty( PROP_UseRegularExpressions, mbUseRegex ); - aProp.getProperty( nMaxFieldCount, PROP_MaxFieldCount ); - } - else - { - OSL_ENSURE(false, "AutoFilterContext::setAutoFilter: descriptor is empty"); - return; - } - - // Unpack all column field items into a sequence. -#if USE_SC_MULTI_STRING_FILTER_PATCH - Reference< XExtendedSheetFilterDescriptor > xExtDescriptor( xDescriptor, UNO_QUERY ); - if ( !xExtDescriptor.is() ) - { - OSL_ENSURE(false, "AutoFilterContext::setAutoFilter: extended descriptor is empty"); - return; - } - - xExtDescriptor->begin(); - - ::std::list< FilterFieldItem >::const_iterator itr = maFields.begin(), itrEnd = maFields.end(); - for (sal_Int32 i = 0; itr != itrEnd && i < nMaxFieldCount; ++itr, ++i) + if( getCurrentElement() == BIFF12_ID_FILTERCOLUMN ) switch( nRecId ) { -#if DEBUG_OOX_AUTOFILTER - lclPrintFilterField(*itr); -#endif - switch ( itr->meType ) - { - case oox::xls::FilterFieldItem::MULTI_STRING: - { - // multi-string filter type - TableFilterFieldMultiString* pField = static_cast<TableFilterFieldMultiString*>( itr->mpField.get() ); - xExtDescriptor->addFilterFieldMultiString( *pField ); - } - break; - case oox::xls::FilterFieldItem::NORMAL: - default: - // normal filter type - TableFilterFieldNormal* pField = static_cast<TableFilterFieldNormal*>( itr->mpField.get() ); - xExtDescriptor->addFilterFieldNormal( *pField ); - } + case BIFF12_ID_DISCRETEFILTERS: + return new FilterSettingsContext( *this, mrFilterColumn.createFilterSettings< DiscreteFilter >() ); + case BIFF12_ID_TOP10FILTER: + return new FilterSettingsContext( *this, mrFilterColumn.createFilterSettings< Top10Filter >() ); + case BIFF12_ID_CUSTOMFILTERS: + return new FilterSettingsContext( *this, mrFilterColumn.createFilterSettings< CustomFilter >() ); } - xExtDescriptor->commit(); - -#else - Sequence< TableFilterField > aFields(nSize); - ::std::list< FilterFieldItem >::const_iterator itr = maFields.begin(), itrEnd = maFields.end(); - for (sal_Int32 i = 0; itr != itrEnd && i < nMaxFieldCount; ++itr, ++i) - { -#if DEBUG_OOX_AUTOFILTER - lclPrintFilterField( *itr ); -#endif - aFields[i] = *itr->mpField; - } - xDescriptor->setFilterFields( aFields ); -#endif - xDB->refresh(); + return 0; } -void AutoFilterContext::maybeShowBlank() +void FilterColumnContext::onStartRecord( RecordInputStream& rStrm ) { - using namespace ::com::sun::star::sheet; - - if ( !mbShowBlank ) - return; - -#if USE_SC_MULTI_STRING_FILTER_PATCH - FilterFieldItem aItem(FilterFieldItem::NORMAL); - TableFilterFieldNormal* pField = static_cast<TableFilterFieldNormal*>(aItem.mpField.get()); - pField->Field = mnCurColID; - pField->Operator = FilterOperator_EMPTY; - pField->Connection = FilterConnection_AND; - pField->IsNumeric = false; -#else - FilterFieldItem aItem; - aItem.mpField->Field = mnCurColID; - aItem.mpField->Operator = FilterOperator_EMPTY; - aItem.mpField->Connection = FilterConnection_AND; - aItem.mpField->IsNumeric = false; -#endif - maFields.push_back(aItem); + mrFilterColumn.importFilterColumn( rStrm ); } -void AutoFilterContext::setFilterNames() -{ - using namespace ::com::sun::star::sheet; - - - sal_Int32 size = maFilterNames.size(); - if ( !size ) - return; - -#if USE_SC_MULTI_STRING_FILTER_PATCH - Sequence< OUString > aStrList(size); - ::std::list< OUString >::const_iterator itr = maFilterNames.begin(), itrEnd = maFilterNames.end(); - for (sal_Int32 i = 0; itr != itrEnd; ++itr, ++i) - aStrList[i] = *itr; - - FilterFieldItem aItem(FilterFieldItem::MULTI_STRING); - TableFilterFieldMultiString* pField = static_cast<TableFilterFieldMultiString*>( aItem.mpField.get() ); - pField->Field = mnCurColID; - pField->Connection = FilterConnection_AND; - pField->StringSet = aStrList; - - maFields.push_back(aItem); -#else - static const OUString sSep = CREATE_OUSTRING("|"); - - OUStringBuffer buf; - if ( size > 1 ) - { - buf.append( CREATE_OUSTRING("^(") ); - mbUseRegex = true; - } - - ::std::list< OUString >::const_iterator itr = maFilterNames.begin(), itrEnd = maFilterNames.end(); - bool bFirst = true; - for (; itr != itrEnd; ++itr) - { - if (bFirst) - bFirst = false; - else - buf.append( sSep ); - buf.append( *itr ); - } - if ( size > 1 ) - buf.append( CREATE_OUSTRING(")$") ); - - FilterFieldItem aItem; - aItem.mpField->Field = mnCurColID; - aItem.mpField->StringValue = buf.makeStringAndClear(); - aItem.mpField->Operator = FilterOperator_EQUAL; - aItem.mpField->Connection = FilterConnection_AND; - aItem.mpField->IsNumeric = false; - maFields.push_back(aItem); -#endif -} +// ============================================================================ -void AutoFilterContext::importAutoFilter( const AttributeList& rAttribs ) +AutoFilterContext::AutoFilterContext( WorksheetFragmentBase& rFragment, AutoFilter& rAutoFilter ) : + WorksheetContextBase( rFragment ), + mrAutoFilter( rAutoFilter ) { - initialize(); - - mbValidAddress = getAddressConverter().convertToCellRange( - maAutoFilterRange, rAttribs.getString( XML_ref, OUString() ), getSheetIndex(), true, true ); } -void AutoFilterContext::importFilterColumn( const AttributeList& rAttribs ) +ContextHandlerRef AutoFilterContext::onCreateContext( sal_Int32 nElement, const AttributeList& /*rAttribs*/ ) { - // hiddenButton and showButton attributes are not used for now. - mnCurColID = rAttribs.getInteger( XML_colId, -1 ); + if( (getCurrentElement() == XLS_TOKEN( autoFilter )) && (nElement == XLS_TOKEN( filterColumn )) ) + return new FilterColumnContext( *this, mrAutoFilter.createFilterColumn() ); + return 0; } -void AutoFilterContext::importTop10( const AttributeList& rAttribs ) +void AutoFilterContext::onStartElement( const AttributeList& rAttribs ) { - using namespace ::com::sun::star::sheet; - - // filterVal attribute is not necessarily, since Calc also supports top 10 - // and top 10% filter type. - FilterFieldItem aItem; -#if USE_SC_MULTI_STRING_FILTER_PATCH - TableFilterFieldNormal* pField = static_cast<TableFilterFieldNormal*>(aItem.mpField.get()); -#else - TableFilterField* pField = aItem.mpField.get(); -#endif - pField->Field = mnCurColID; - - bool bPercent = rAttribs.getBool( XML_percent, false ); - bool bTop = rAttribs.getBool( XML_top, true ); - pField->NumericValue = rAttribs.getDouble( XML_val, 0.0 ); - pField->IsNumeric = true; - - // When top10 filter item is present, that's the only filter item for that column. - if ( bTop ) - if ( bPercent ) - pField->Operator = FilterOperator_TOP_PERCENT; - else - pField->Operator = FilterOperator_TOP_VALUES; - else - if ( bPercent ) - pField->Operator = FilterOperator_BOTTOM_PERCENT; - else - pField->Operator = FilterOperator_BOTTOM_VALUES; - - maFields.push_back(aItem); + mrAutoFilter.importAutoFilter( rAttribs, getSheetIndex() ); } -void AutoFilterContext::importCustomFilters( const AttributeList& rAttribs ) +ContextHandlerRef AutoFilterContext::onCreateRecordContext( sal_Int32 nRecId, RecordInputStream& /*rStrm*/ ) { - // OR is default when the 'and' attribute is absent. - mbConnectionAnd = rAttribs.getBool( XML_and, false ); + if( (getCurrentElement() == BIFF12_ID_AUTOFILTER) && (nRecId == BIFF12_ID_FILTERCOLUMN) ) + return new FilterColumnContext( *this, mrAutoFilter.createFilterColumn() ); + return 0; } -/** Do a best-effort guess of whether or not the given string is numerical. */ -static bool lclIsNumeric( const OUString& _str, const LocaleDataItem& aLocaleItem ) +void AutoFilterContext::onStartRecord( RecordInputStream& rStrm ) { - OUString str = _str.trim(); - sal_Int32 size = str.getLength(); - - if ( !size ) - // Empty string. This can't be a number. - return false; - - // Get the decimal separator for the current locale. - const OUString& sep = aLocaleItem.decimalSeparator; - - bool bDecimalSep = false; - for (sal_Int32 i = 0; i < size; ++i) - { - OUString c = str.copy(i, 1); - if ( !c.compareTo(sep) ) - { - if ( bDecimalSep ) - return false; - else - { - bDecimalSep = true; - continue; - } - } - if ( (0 > c.compareToAscii("0") || 0 < c.compareToAscii("9")) ) - return false; - } - - return true; + mrAutoFilter.importAutoFilter( rStrm, getSheetIndex() ); } -/** Convert wildcard characters to regex equivalent. Returns true if any - wildcard character is found. */ -static bool lclWildcard2Regex( OUString& str ) -{ - bool bWCFound = false; - OUStringBuffer buf; - sal_Int32 size = str.getLength(); - buf.ensureCapacity(size + 6); // pure heuristics. - - sal_Unicode dot = '.', star = '*', hat = '^', dollar = '$'; - buf.append(hat); - for (sal_Int32 i = 0; i < size; ++i) - { - OUString c = str.copy(i, 1); - if ( !c.compareToAscii("?") ) - { - buf.append(dot); - bWCFound = true; - } - else if ( !c.compareToAscii("*") ) - { - buf.append(dot); - buf.append(star); - bWCFound = true; - } - else - buf.append(c); - } - buf.append(dollar); - - if (bWCFound) - str = buf.makeStringAndClear(); - - return bWCFound; -} +// ============================================================================ -/** Translate Excel's filter operator to Calc's. */ -static ::com::sun::star::sheet::FilterOperator lclTranslateFilterOp( sal_Int32 nToken ) +BiffAutoFilterContext::BiffAutoFilterContext( const WorksheetHelper& rHelper, AutoFilter& rAutoFilter ) : + BiffWorksheetContextBase( rHelper ), + mrAutoFilter( rAutoFilter ) { - using namespace ::com::sun::star::sheet; - - switch ( nToken ) - { - case XML_equal: - return FilterOperator_EQUAL; - case XML_notEqual: - return FilterOperator_NOT_EQUAL; - case XML_greaterThan: - return FilterOperator_GREATER; - case XML_greaterThanOrEqual: - return FilterOperator_GREATER_EQUAL; - case XML_lessThan: - return FilterOperator_LESS; - case XML_lessThanOrEqual: - return FilterOperator_LESS_EQUAL; - } - return FilterOperator_EQUAL; } -void AutoFilterContext::importCustomFilter( const AttributeList& rAttribs ) +void BiffAutoFilterContext::importRecord( BiffInputStream& rStrm ) { - using namespace ::com::sun::star::sheet; - - sal_Int32 nToken = rAttribs.getToken( XML_operator, XML_equal ); -#if USE_SC_MULTI_STRING_FILTER_PATCH - FilterFieldItem aItem(FilterFieldItem::NORMAL); - TableFilterFieldNormal* pField = static_cast<TableFilterFieldNormal*>(aItem.mpField.get()); -#else - FilterFieldItem aItem; - TableFilterField* pField = aItem.mpField.get(); -#endif - pField->Field = mnCurColID; - pField->StringValue = rAttribs.getString( XML_val, OUString() ); - pField->NumericValue = pField->StringValue.toDouble(); - pField->Operator = lclTranslateFilterOp( nToken ); - - if ( nToken == XML_notEqual && !pField->StringValue.compareToAscii(" ") ) - { - // Special case for hiding blanks. Excel translates "hide blanks" to - // (filter if notEqual " "). So, we need to translate it back. - pField->Operator = FilterOperator_NOT_EMPTY; - pField->IsNumeric = false; - maFields.push_back(aItem); - return; - } - - switch ( nToken ) + switch( rStrm.getRecId() ) { - case XML_equal: - case XML_notEqual: - { - Reference< XLocaleData > xLocale( getGlobalFactory()->createInstance( - CREATE_OUSTRING("com.sun.star.i18n.LocaleData") ), UNO_QUERY ); - - if ( !xLocale.is() ) - return; - - LocaleDataItem aLocaleItem = xLocale->getLocaleItem( ::com::sun::star::lang::Locale() ); - pField->IsNumeric = lclIsNumeric(pField->StringValue, aLocaleItem); - - if ( !pField->IsNumeric && lclWildcard2Regex(pField->StringValue) ) - mbUseRegex = true; - - maFields.push_back(aItem); - } - break; - - case XML_greaterThan: - case XML_greaterThanOrEqual: - case XML_lessThan: - case XML_lessThanOrEqual: - { - pField->IsNumeric = true; - maFields.push_back(aItem); - } - break; - default: - OSL_ENSURE( false, "AutoFilterContext::importCustomFilter: unhandled case" ); + // nothing to read for BIFF_ID_AUTOFILTER + case BIFF_ID_FILTERCOLUMN: mrAutoFilter.createFilterColumn().importFilterColumn( rStrm ); break; } } -void AutoFilterContext::importFilters( const AttributeList& rAttribs ) -{ - // blank (boolean) and calendarType attributes can be present, but not used for now. - - mbShowBlank = rAttribs.getBool( XML_blank, false ); - maFilterNames.clear(); -} - -void AutoFilterContext::importFilter( const AttributeList& rAttribs ) -{ - if (mnCurColID == -1) - return; - - OUString value = rAttribs.getString( XML_val, OUString() ); - if ( value.getLength() ) - maFilterNames.push_back(value); -} - -void AutoFilterContext::importDynamicFilter( const AttributeList& /*rAttribs*/ ) -{ - // not implemented yet - Calc doesn't support this. -} - // ============================================================================ } // namespace xls diff --git a/oox/source/xls/connectionsbuffer.cxx b/oox/source/xls/connectionsbuffer.cxx index 8a1d2c718948..12df30fe493f 100755 --- a/oox/source/xls/connectionsbuffer.cxx +++ b/oox/source/xls/connectionsbuffer.cxx @@ -51,6 +51,9 @@ const sal_Int32 BIFF12_RECONNECT_AS_REQUIRED = 1; const sal_Int32 BIFF12_RECONNECT_ALWAYS = 2; const sal_Int32 BIFF12_RECONNECT_NEVER = 3; +const sal_uInt8 BIFF12_CONNECTION_SAVEPASSWORD_ON = 1; +const sal_uInt8 BIFF12_CONNECTION_SAVEPASSWORD_OFF = 2; + const sal_uInt16 BIFF12_CONNECTION_KEEPALIVE = 0x0001; const sal_uInt16 BIFF12_CONNECTION_NEW = 0x0002; const sal_uInt16 BIFF12_CONNECTION_DELETED = 0x0004; @@ -187,6 +190,7 @@ ConnectionModel::ConnectionModel() : mnId( -1 ), mnType( BIFF12_CONNECTION_UNKNOWN ), mnReconnectMethod( BIFF12_RECONNECT_AS_REQUIRED ), + mnCredentials( XML_integrated ), mnInterval( 0 ), mbKeepAlive( false ), mbNew( false ), @@ -194,7 +198,8 @@ ConnectionModel::ConnectionModel() : mbOnlyUseConnFile( false ), mbBackground( false ), mbRefreshOnLoad( false ), - mbSaveData( false ) + mbSaveData( false ), + mbSavePassword( false ) { } @@ -224,6 +229,7 @@ void Connection::importConnection( const AttributeList& rAttribs ) // type and reconnectionMethod are using the BIFF12 constants instead of XML tokens maModel.mnType = rAttribs.getInteger( XML_type, BIFF12_CONNECTION_UNKNOWN ); maModel.mnReconnectMethod = rAttribs.getInteger( XML_reconnectionMethod, BIFF12_RECONNECT_AS_REQUIRED ); + maModel.mnCredentials = rAttribs.getToken( XML_credentials, XML_integrated ); maModel.mnInterval = rAttribs.getInteger( XML_interval, 0 ); maModel.mbKeepAlive = rAttribs.getBool( XML_keepAlive, false ); maModel.mbNew = rAttribs.getBool( XML_new, false ); @@ -231,6 +237,8 @@ void Connection::importConnection( const AttributeList& rAttribs ) maModel.mbOnlyUseConnFile = rAttribs.getBool( XML_onlyUseConnectionFile, false ); maModel.mbBackground = rAttribs.getBool( XML_background, false ); maModel.mbRefreshOnLoad = rAttribs.getBool( XML_refreshOnLoad, false ); + maModel.mbSaveData = rAttribs.getBool( XML_saveData, false ); + maModel.mbSavePassword = rAttribs.getBool( XML_savePassword, false ); } void Connection::importWebPr( const AttributeList& rAttribs ) @@ -281,11 +289,13 @@ void Connection::importTable( const AttributeList& rAttribs, sal_Int32 nElement void Connection::importConnection( RecordInputStream& rStrm ) { - rStrm.skip( 4 ); sal_uInt16 nFlags, nStrFlags; + sal_uInt8 nSavePassword, nCredentials; + rStrm.skip( 2 ); + rStrm >> nSavePassword; + rStrm.skip( 1 ); maModel.mnInterval = rStrm.readuInt16(); - rStrm >> nFlags >> nStrFlags >> maModel.mnType >> maModel.mnReconnectMethod >> maModel.mnId; - rStrm.skip( 1 ); // credentials + rStrm >> nFlags >> nStrFlags >> maModel.mnType >> maModel.mnReconnectMethod >> maModel.mnId >> nCredentials; if( getFlag( nStrFlags, BIFF12_CONNECTION_HAS_SOURCEFILE ) ) rStrm >> maModel.maSourceFile; @@ -298,6 +308,9 @@ void Connection::importConnection( RecordInputStream& rStrm ) if( getFlag( nStrFlags, BIFF12_CONNECTION_HAS_SSOID ) ) rStrm >> maModel.maSsoId; + static const sal_Int32 spnCredentials[] = { XML_integrated, XML_none, XML_stored, XML_prompt }; + maModel.mnCredentials = STATIC_ARRAY_SELECT( spnCredentials, nCredentials, XML_integrated ); + maModel.mbKeepAlive = getFlag( nFlags, BIFF12_CONNECTION_KEEPALIVE ); maModel.mbNew = getFlag( nFlags, BIFF12_CONNECTION_NEW ); maModel.mbDeleted = getFlag( nFlags, BIFF12_CONNECTION_DELETED ); @@ -305,6 +318,7 @@ void Connection::importConnection( RecordInputStream& rStrm ) maModel.mbBackground = getFlag( nFlags, BIFF12_CONNECTION_BACKGROUND ); maModel.mbRefreshOnLoad = getFlag( nFlags, BIFF12_CONNECTION_REFRESHONLOAD ); maModel.mbSaveData = getFlag( nFlags, BIFF12_CONNECTION_SAVEDATA ); + maModel.mbSavePassword = nSavePassword == BIFF12_CONNECTION_SAVEPASSWORD_ON; } void Connection::importWebPr( RecordInputStream& rStrm ) @@ -370,6 +384,7 @@ void Connection::importDbQuery( BiffInputStream& rStrm ) // same type constants in all BIFF versions maModel.mnType = extractValue< sal_Int32 >( nFlags, 0, 3 ); + maModel.mbSavePassword = getFlag( nFlags, BIFF_DBQUERY_SAVEPASSWORD ); OSL_ENSURE( getFlag( nFlags, BIFF_DBQUERY_ODBC ) == (maModel.mnType == BIFF12_CONNECTION_ODBC), "Connection::importDbQuery - wrong ODBC flag" ); OSL_ENSURE( getFlag( nFlags, BIFF_DBQUERY_SQLQUERY ) != (maModel.mnType == BIFF12_CONNECTION_HTML), "Connection::importDbQuery - wrong SQL query flag" ); @@ -446,41 +461,39 @@ ConnectionsBuffer::ConnectionsBuffer( const WorkbookHelper& rHelper ) : { } -ConnectionRef ConnectionsBuffer::importConnection( const AttributeList& rAttribs ) +Connection& ConnectionsBuffer::createConnection() { ConnectionRef xConnection( new Connection( *this ) ); - xConnection->importConnection( rAttribs ); - insertConnection( xConnection ); - return xConnection; + maConnections.push_back( xConnection ); + return *xConnection; } -ConnectionRef ConnectionsBuffer::importConnection( RecordInputStream& rStrm ) +Connection& ConnectionsBuffer::createConnectionWithId() { - ConnectionRef xConnection( new Connection( *this ) ); - xConnection->importConnection( rStrm ); - insertConnection( xConnection ); - return xConnection; + ConnectionRef xConnection( new Connection( *this, mnUnusedId ) ); + maConnections.push_back( xConnection ); + insertConnectionToMap( xConnection ); + return *xConnection; } -ConnectionRef ConnectionsBuffer::createConnection() +void ConnectionsBuffer::finalizeImport() { - ConnectionRef xConnection( new Connection( *this, mnUnusedId ) ); - insertConnection( xConnection ); - return xConnection; + for( ConnectionVector::iterator aIt = maConnections.begin(), aEnd = maConnections.end(); aIt != aEnd; ++aIt ) + insertConnectionToMap( *aIt ); } ConnectionRef ConnectionsBuffer::getConnection( sal_Int32 nConnId ) const { - return maConnections.get( nConnId ); + return maConnectionsById.get( nConnId ); } -void ConnectionsBuffer::insertConnection( const ConnectionRef& rxConnection ) +void ConnectionsBuffer::insertConnectionToMap( const ConnectionRef& rxConnection ) { sal_Int32 nConnId = rxConnection->getConnectionId(); if( nConnId > 0 ) { - OSL_ENSURE( !maConnections.has( nConnId ), "ConnectionsBuffer::insertConnection - multiple connection identifier" ); - maConnections[ nConnId ] = rxConnection; + OSL_ENSURE( !maConnectionsById.has( nConnId ), "ConnectionsBuffer::insertConnectionToMap - multiple connection identifier" ); + maConnectionsById[ nConnId ] = rxConnection; mnUnusedId = ::std::max< sal_Int32 >( mnUnusedId, nConnId + 1 ); } } diff --git a/oox/source/xls/connectionsfragment.cxx b/oox/source/xls/connectionsfragment.cxx index ee4aaa3a059e..f83f9028faa8 100644 --- a/oox/source/xls/connectionsfragment.cxx +++ b/oox/source/xls/connectionsfragment.cxx @@ -29,6 +29,7 @@ #include "oox/helper/attributelist.hxx" #include "oox/xls/biffhelper.hxx" +#include "oox/xls/connectionsbuffer.hxx" namespace oox { namespace xls { @@ -41,11 +42,10 @@ using ::oox::core::RecordInfo; // ============================================================================ -ConnectionContext::ConnectionContext( WorkbookFragmentBase& rParent, const ConnectionRef& rxConnection ) : +ConnectionContext::ConnectionContext( WorkbookFragmentBase& rParent, Connection& rConnection ) : WorkbookContextBase( rParent ), - mxConnection( rxConnection ) + mrConnection( rConnection ) { - OSL_ENSURE( mxConnection.get(), "ConnectionContext::ConnectionContext - missing connection" ); } ContextHandlerRef ConnectionContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) @@ -55,7 +55,7 @@ ContextHandlerRef ConnectionContext::onCreateContext( sal_Int32 nElement, const case XLS_TOKEN( connection ): if( nElement == XLS_TOKEN( webPr ) ) { - mxConnection->importWebPr( rAttribs ); + mrConnection.importWebPr( rAttribs ); return this; } break; @@ -63,18 +63,24 @@ ContextHandlerRef ConnectionContext::onCreateContext( sal_Int32 nElement, const case XLS_TOKEN( webPr ): if( nElement == XLS_TOKEN( tables ) ) { - mxConnection->importTables( rAttribs ); + mrConnection.importTables( rAttribs ); return this; } break; case XLS_TOKEN( tables ): - mxConnection->importTable( rAttribs, nElement ); + mrConnection.importTable( rAttribs, nElement ); break; } return 0; } +void ConnectionContext::onStartElement( const AttributeList& rAttribs ) +{ + if( getCurrentElement() == XLS_TOKEN( connection ) ) + mrConnection.importConnection( rAttribs ); +} + ContextHandlerRef ConnectionContext::onCreateRecordContext( sal_Int32 nRecId, RecordInputStream& rStrm ) { switch( getCurrentElement() ) @@ -82,7 +88,7 @@ ContextHandlerRef ConnectionContext::onCreateRecordContext( sal_Int32 nRecId, Re case BIFF12_ID_CONNECTION: if( nRecId == BIFF12_ID_WEBPR ) { - mxConnection->importWebPr( rStrm ); + mrConnection.importWebPr( rStrm ); return this; } break; @@ -90,18 +96,24 @@ ContextHandlerRef ConnectionContext::onCreateRecordContext( sal_Int32 nRecId, Re case BIFF12_ID_WEBPR: if( nRecId == BIFF12_ID_WEBPRTABLES ) { - mxConnection->importWebPrTables( rStrm ); + mrConnection.importWebPrTables( rStrm ); return this; } break; case BIFF12_ID_WEBPRTABLES: - mxConnection->importWebPrTable( rStrm, nRecId ); + mrConnection.importWebPrTable( rStrm, nRecId ); break; } return 0; } +void ConnectionContext::onStartRecord( RecordInputStream& rStrm ) +{ + if( getCurrentElement() == BIFF12_ID_CONNECTION ) + mrConnection.importConnection( rStrm ); +} + // ============================================================================ ConnectionsFragment::ConnectionsFragment( const WorkbookHelper& rHelper, const OUString& rFragmentPath ) : @@ -109,7 +121,7 @@ ConnectionsFragment::ConnectionsFragment( const WorkbookHelper& rHelper, const O { } -ContextHandlerRef ConnectionsFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +ContextHandlerRef ConnectionsFragment::onCreateContext( sal_Int32 nElement, const AttributeList& /*rAttribs*/ ) { switch( getCurrentElement() ) { @@ -120,17 +132,13 @@ ContextHandlerRef ConnectionsFragment::onCreateContext( sal_Int32 nElement, cons case XLS_TOKEN( connections ): if( nElement == XLS_TOKEN( connection ) ) - { - ConnectionRef xConnection = getConnections().importConnection( rAttribs ); - if( xConnection.get() ) - return new ConnectionContext( *this, xConnection ); - } + return new ConnectionContext( *this, getConnections().createConnection() ); break; } return 0; } -ContextHandlerRef ConnectionsFragment::onCreateRecordContext( sal_Int32 nRecId, RecordInputStream& rStrm ) +ContextHandlerRef ConnectionsFragment::onCreateRecordContext( sal_Int32 nRecId, RecordInputStream& /*rStrm*/ ) { switch( getCurrentElement() ) { @@ -141,11 +149,7 @@ ContextHandlerRef ConnectionsFragment::onCreateRecordContext( sal_Int32 nRecId, case BIFF12_ID_CONNECTIONS: if( nRecId == BIFF12_ID_CONNECTION ) - { - ConnectionRef xConnection = getConnections().importConnection( rStrm ); - if( xConnection.get() ) - return new ConnectionContext( *this, xConnection ); - } + return new ConnectionContext( *this, getConnections().createConnection() ); break; } return 0; @@ -164,6 +168,11 @@ const RecordInfo* ConnectionsFragment::getRecordInfos() const return spRecInfos; } +void ConnectionsFragment::finalizeImport() +{ + getConnections().finalizeImport(); +} + // ============================================================================ } // namespace xls diff --git a/oox/source/xls/defnamesbuffer.cxx b/oox/source/xls/defnamesbuffer.cxx index 6ff80e0efe64..94ca1fb321bf 100644 --- a/oox/source/xls/defnamesbuffer.cxx +++ b/oox/source/xls/defnamesbuffer.cxx @@ -81,6 +81,11 @@ const sal_uInt8 BIFF2_DEFNAME_FUNC = 0x02; /// BIFF2 function/comma const sal_uInt16 BIFF_DEFNAME_GLOBAL = 0; /// 0 = Globally defined name. +const sal_uInt16 BIFF_REFFLAG_COL1REL = 0x0001; +const sal_uInt16 BIFF_REFFLAG_ROW1REL = 0x0002; +const sal_uInt16 BIFF_REFFLAG_COL2REL = 0x0004; +const sal_uInt16 BIFF_REFFLAG_ROW2REL = 0x0008; + // ---------------------------------------------------------------------------- const sal_Char* const spcLegacyPrefix = "Excel_BuiltIn_"; @@ -88,20 +93,20 @@ const sal_Char* const spcOoxPrefix = "_xlnm."; const sal_Char* const sppcBaseNames[] = { - "Consolidate_Area", /* OOXML */ + "Consolidate_Area", "Auto_Open", "Auto_Close", - "Extract", /* OOXML */ - "Database", /* OOXML */ - "Criteria", /* OOXML */ - "Print_Area", /* OOXML */ - "Print_Titles", /* OOXML */ + "Extract", + "Database", + "Criteria", + "Print_Area", + "Print_Titles", "Recorder", "Data_Form", "Auto_Activate", "Auto_Deactivate", - "Sheet_Title", /* OOXML */ - "_FilterDatabase" /* OOXML */ + "Sheet_Title", + "_FilterDatabase" }; /** Localized names for _xlnm._FilterDatabase as used in BIFF5. */ @@ -113,7 +118,7 @@ const sal_Char* const sppcFilterDbNames[] = OUString lclGetBaseName( sal_Unicode cBuiltinId ) { - OSL_ENSURE( cBuiltinId < STATIC_ARRAY_SIZE( sppcBaseNames ), "lclGetBaseName - unknown builtin name" ); + OSL_ENSURE( cBuiltinId < STATIC_ARRAY_SIZE( sppcBaseNames ), "lclGetBaseName - unsupported built-in identifier" ); OUStringBuffer aBuffer; if( cBuiltinId < STATIC_ARRAY_SIZE( sppcBaseNames ) ) aBuffer.appendAscii( sppcBaseNames[ cBuiltinId ] ); @@ -122,67 +127,52 @@ OUString lclGetBaseName( sal_Unicode cBuiltinId ) return aBuffer.makeStringAndClear(); } -OUString lclGetBuiltinName( sal_Unicode cBuiltinId ) +OUString lclGetPrefixedName( sal_Unicode cBuiltinId ) { return OUStringBuffer().appendAscii( spcOoxPrefix ).append( lclGetBaseName( cBuiltinId ) ).makeStringAndClear(); } -sal_Unicode lclGetBuiltinIdFromOox( const OUString& rOoxName ) +/** returns the built-in name identifier from a perfixed built-in name, e.g. '_xlnm.Print_Area'. */ +sal_Unicode lclGetBuiltinIdFromPrefixedName( const OUString& rModelName ) { OUString aPrefix = OUString::createFromAscii( spcOoxPrefix ); sal_Int32 nPrefixLen = aPrefix.getLength(); - if( rOoxName.matchIgnoreAsciiCase( aPrefix ) ) + if( rModelName.matchIgnoreAsciiCase( aPrefix ) ) { for( sal_Unicode cBuiltinId = 0; cBuiltinId < STATIC_ARRAY_SIZE( sppcBaseNames ); ++cBuiltinId ) { OUString aBaseName = lclGetBaseName( cBuiltinId ); sal_Int32 nBaseNameLen = aBaseName.getLength(); - if( (rOoxName.getLength() == nPrefixLen + nBaseNameLen) && rOoxName.matchIgnoreAsciiCase( aBaseName, nPrefixLen ) ) + if( (rModelName.getLength() == nPrefixLen + nBaseNameLen) && rModelName.matchIgnoreAsciiCase( aBaseName, nPrefixLen ) ) return cBuiltinId; } } return BIFF_DEFNAME_UNKNOWN; } -sal_Unicode lclGetBuiltinIdFromBiff( const OUString& rName ) +/** returns the built-in name identifier from a built-in base name, e.g. 'Print_Area'. */ +sal_Unicode lclGetBuiltinIdFromBaseName( const OUString& rModelName ) { for( sal_Unicode cBuiltinId = 0; cBuiltinId < STATIC_ARRAY_SIZE( sppcBaseNames ); ++cBuiltinId ) - if( rName.equalsIgnoreAsciiCaseAscii( sppcBaseNames[ cBuiltinId ] ) ) + if( rModelName.equalsIgnoreAsciiCaseAscii( sppcBaseNames[ cBuiltinId ] ) ) return cBuiltinId; return BIFF_DEFNAME_UNKNOWN; } -bool lclIsFilterDatabaseName( const OUString& rName ) +bool lclIsFilterDatabaseName( const OUString& rModelName ) { for( const sal_Char* const* ppcName = sppcFilterDbNames; ppcName < STATIC_ARRAY_END( sppcFilterDbNames ); ++ppcName ) - if( rName.equalsIgnoreAsciiCaseAscii( *ppcName ) ) + if( rModelName.equalsIgnoreAsciiCaseAscii( *ppcName ) ) return true; return false; } -} // namespace - -// ============================================================================ - -DefinedNameModel::DefinedNameModel() : - mnSheet( -1 ), - mnFuncGroupId( -1 ), - mbMacro( false ), - mbFunction( false ), - mbVBName( false ), - mbHidden( false ) +OUString lclGetUpcaseModelName( const OUString& rModelName ) { + // TODO: i18n? + return rModelName.toAsciiUpperCase(); } -// ============================================================================ - -namespace { - -const sal_uInt16 BIFF_REFFLAG_COL1REL = 0x0001; -const sal_uInt16 BIFF_REFFLAG_ROW1REL = 0x0002; -const sal_uInt16 BIFF_REFFLAG_COL2REL = 0x0004; -const sal_uInt16 BIFF_REFFLAG_ROW2REL = 0x0008; - void lclConvertRefFlags( sal_Int32& ornFlags, sal_Int32& ornAbsPos, sal_Int32& ornRelPos, sal_Int32 nBasePos, sal_Int32 nApiRelFlag, bool bRel ) { if( getFlag( ornFlags, nApiRelFlag ) && !bRel ) @@ -232,7 +222,19 @@ Any lclConvertReference( const Any& rRefAny, const CellAddress& rBaseAddress, sa } // namespace -// ---------------------------------------------------------------------------- +// ============================================================================ + +DefinedNameModel::DefinedNameModel() : + mnSheet( -1 ), + mnFuncGroupId( -1 ), + mbMacro( false ), + mbFunction( false ), + mbVBName( false ), + mbHidden( false ) +{ +} + +// ============================================================================ DefinedNameBase::DefinedNameBase( const WorkbookHelper& rHelper ) : WorkbookHelper( rHelper ) @@ -242,7 +244,7 @@ DefinedNameBase::DefinedNameBase( const WorkbookHelper& rHelper ) : const OUString& DefinedNameBase::getUpcaseModelName() const { if( maUpModelName.getLength() == 0 ) - maUpModelName = maModel.maName.toAsciiUpperCase(); + maUpModelName = lclGetUpcaseModelName( maModel.maName ); return maUpModelName; } @@ -325,8 +327,11 @@ void DefinedName::importDefinedName( const AttributeList& rAttribs ) maModel.mbFunction = rAttribs.getBool( XML_function, false ); maModel.mbVBName = rAttribs.getBool( XML_vbProcedure, false ); maModel.mbHidden = rAttribs.getBool( XML_hidden, false ); - mcBuiltinId = lclGetBuiltinIdFromOox( maModel.maName ); mnCalcSheet = (maModel.mnSheet >= 0) ? getWorksheets().getCalcSheetIndex( maModel.mnSheet ) : -1; + + /* Detect built-in state from name itself, there is no built-in flag. + Built-in names are prexixed with '_xlnm.' instead. */ + mcBuiltinId = lclGetBuiltinIdFromPrefixedName( maModel.maName ); } void DefinedName::setFormula( const OUString& rFormula ) @@ -349,12 +354,9 @@ void DefinedName::importDefinedName( RecordInputStream& rStrm ) maModel.mbVBName = getFlag( nFlags, BIFF12_DEFNAME_VBNAME ); maModel.mbHidden = getFlag( nFlags, BIFF12_DEFNAME_HIDDEN ); - // get builtin name index from name + // get built-in name index from name if( getFlag( nFlags, BIFF12_DEFNAME_BUILTIN ) ) - mcBuiltinId = lclGetBuiltinIdFromBiff( maModel.maName ); - // unhide built-in names (_xlnm._FilterDatabase is always hidden) - if( isBuiltinName() ) - maModel.mbHidden = false; + mcBuiltinId = lclGetBuiltinIdFromBaseName( maModel.maName ); // store token array data sal_Int64 nRecPos = rStrm.tell(); @@ -416,24 +418,22 @@ void DefinedName::importDefinedName( BiffInputStream& rStrm, sal_Int16 nCalcShee maModel.mbVBName = getFlag( nFlags, BIFF_DEFNAME_VBNAME ); maModel.mbHidden = getFlag( nFlags, BIFF_DEFNAME_HIDDEN ); - // get builtin name index from name + // get built-in name index from name if( getFlag( nFlags, BIFF_DEFNAME_BUILTIN ) ) { - OSL_ENSURE( maModel.maName.getLength() == 1, "DefinedName::importDefinedName - wrong builtin name" ); - if( maModel.maName.getLength() > 0 ) + // name may be the built-in identifier or the built-in base name + if( maModel.maName.getLength() == 1 ) mcBuiltinId = maModel.maName[ 0 ]; + else + mcBuiltinId = lclGetBuiltinIdFromBaseName( maModel.maName ); } - /* In BIFF5, _xlnm._FilterDatabase appears as hidden user name without + /* In BIFF5, '_FilterDatabase' appears as hidden user name without built-in flag, and even worse, localized. */ else if( (eBiff == BIFF5) && lclIsFilterDatabaseName( maModel.maName ) ) { mcBuiltinId = BIFF_DEFNAME_FILTERDATABASE; } - // unhide built-in names (_xlnm._FilterDatabase is always hidden) - if( isBuiltinName() ) - maModel.mbHidden = false; - // get sheet index for sheet-local names in BIFF5-BIFF8 switch( getBiff() ) { @@ -483,18 +483,13 @@ void DefinedName::importDefinedName( BiffInputStream& rStrm, sal_Int16 nCalcShee void DefinedName::createNameObject() { - // do not create names for (macro) functions + // do not create names for (macro) functions or VBA procedures // #163146# do not ignore hidden names (may be regular names created by VBA scripts) - if( /*maModel.mbHidden ||*/ maModel.mbFunction ) + if( /*maModel.mbHidden ||*/ maModel.mbFunction || maModel.mbVBName ) return; - // convert original name to final Calc name - if( maModel.mbVBName ) - maCalcName = maModel.maName; - else if( isBuiltinName() ) - maCalcName = lclGetBuiltinName( mcBuiltinId ); - else - maCalcName = maModel.maName; //! TODO convert to valid name + // convert original name to final Calc name (TODO: filter invalid characters from model name) + maCalcName = isBuiltinName() ? lclGetPrefixedName( mcBuiltinId ) : maModel.maName; // #163146# do not rename sheet-local names by default, this breaks VBA scripts #if 0 @@ -544,7 +539,7 @@ void DefinedName::convertFormula() case FILTER_UNKNOWN: break; } - // set builtin names (print ranges, repeated titles, filter ranges) + // set built-in names (print ranges, repeated titles, filter ranges) if( !isGlobalName() ) switch( mcBuiltinId ) { case BIFF_DEFNAME_PRINTAREA: @@ -652,14 +647,20 @@ void DefinedNamesBuffer::importDefinedName( BiffInputStream& rStrm ) void DefinedNamesBuffer::finalizeImport() { - // first insert all names without formula definition into the document + // first insert all names without formula definition into the document, and insert them into the maps for( DefNameVector::iterator aIt = maDefNames.begin(), aEnd = maDefNames.end(); aIt != aEnd; ++aIt ) { DefinedNameRef xDefName = *aIt; xDefName->createNameObject(); + // map by sheet index and original model name + maModelNameMap[ SheetNameKey( xDefName->getLocalCalcSheet(), xDefName->getUpcaseModelName() ) ] = xDefName; + // map by sheet index and built-in identifier + if( !xDefName->isGlobalName() && xDefName->isBuiltinName() ) + maBuiltinMap[ BuiltinKey( xDefName->getLocalCalcSheet(), xDefName->getBuiltinId() ) ] = xDefName; + // map by API formula token identifier sal_Int32 nTokenIndex = xDefName->getTokenIndex(); if( nTokenIndex >= 0 ) - maDefNameMap[ nTokenIndex ] = xDefName; + maTokenIdMap[ nTokenIndex ] = xDefName; } /* Now convert all name formulas, so that the formula parser can find all @@ -674,25 +675,22 @@ DefinedNameRef DefinedNamesBuffer::getByIndex( sal_Int32 nIndex ) const DefinedNameRef DefinedNamesBuffer::getByTokenIndex( sal_Int32 nIndex ) const { - return maDefNameMap.get( nIndex ); + return maTokenIdMap.get( nIndex ); } DefinedNameRef DefinedNamesBuffer::getByModelName( const OUString& rModelName, sal_Int16 nCalcSheet ) const { - DefinedNameRef xGlobalName; // a found global name - DefinedNameRef xLocalName; // a found local name - for( DefNameVector::const_iterator aIt = maDefNames.begin(), aEnd = maDefNames.end(); (aIt != aEnd) && !xLocalName; ++aIt ) - { - DefinedNameRef xCurrName = *aIt; - if( xCurrName->getModelName() == rModelName ) - { - if( xCurrName->getLocalCalcSheet() == nCalcSheet ) - xLocalName = xCurrName; - else if( xCurrName->isGlobalName() ) - xGlobalName = xCurrName; - } - } - return xLocalName.get() ? xLocalName : xGlobalName; + OUString aUpcaseName = lclGetUpcaseModelName( rModelName ); + DefinedNameRef xDefName = maModelNameMap.get( SheetNameKey( nCalcSheet, aUpcaseName ) ); + // lookup global name, if no local name exists + if( !xDefName && (nCalcSheet >= 0) ) + xDefName = maModelNameMap.get( SheetNameKey( -1, aUpcaseName ) ); + return xDefName; +} + +DefinedNameRef DefinedNamesBuffer::getByBuiltinId( sal_Unicode cBuiltinId, sal_Int16 nCalcSheet ) const +{ + return maBuiltinMap.get( BuiltinKey( nCalcSheet, cBuiltinId ) ); } DefinedNameRef DefinedNamesBuffer::createDefinedName() diff --git a/oox/source/xls/makefile.mk b/oox/source/xls/makefile.mk index b6d69dc5cf8c..6ca6e6a271b9 100644 --- a/oox/source/xls/makefile.mk +++ b/oox/source/xls/makefile.mk @@ -42,6 +42,7 @@ ENABLE_EXCEPTIONS=TRUE SLOFILES = \ $(SLO)$/addressconverter.obj \ + $(SLO)$/autofilterbuffer.obj \ $(SLO)$/autofiltercontext.obj \ $(SLO)$/biffcodec.obj \ $(SLO)$/biffdetector.obj \ @@ -94,7 +95,7 @@ SLOFILES = \ $(SLO)$/workbooksettings.obj \ $(SLO)$/worksheetbuffer.obj \ $(SLO)$/worksheetfragment.obj \ - $(SLO)$/worksheethelper.obj \ + $(SLO)$/worksheethelper.obj \ $(SLO)$/worksheetsettings.obj # --- Targets ------------------------------------------------------- diff --git a/oox/source/xls/pivotcachefragment.cxx b/oox/source/xls/pivotcachefragment.cxx index 3d69928f7ee8..8c4f56c7c820 100644 --- a/oox/source/xls/pivotcachefragment.cxx +++ b/oox/source/xls/pivotcachefragment.cxx @@ -387,9 +387,8 @@ bool BiffPivotCacheFragment::importFragment() // ============================================================================ -BiffPivotCacheRecordsContext::BiffPivotCacheRecordsContext( - const BiffWorkbookFragmentBase& rFragment, const PivotCache& rPivotCache ) : - BiffWorksheetContextBase( rFragment, ISegmentProgressBarRef(), SHEETTYPE_WORKSHEET, rPivotCache.getSourceRange().Sheet ), +BiffPivotCacheRecordsContext::BiffPivotCacheRecordsContext( const WorkbookHelper& rHelper, const PivotCache& rPivotCache ) : + BiffWorksheetContextBase( rHelper, ISegmentProgressBarRef(), SHEETTYPE_WORKSHEET, rPivotCache.getSourceRange().Sheet ), mrPivotCache( rPivotCache ), mnColIdx( 0 ), mnRow( 0 ), diff --git a/oox/source/xls/pivottablefragment.cxx b/oox/source/xls/pivottablefragment.cxx index 1486a600e131..1ed95b141b61 100644 --- a/oox/source/xls/pivottablefragment.cxx +++ b/oox/source/xls/pivottablefragment.cxx @@ -294,8 +294,8 @@ const RecordInfo* PivotTableFragment::getRecordInfos() const // ============================================================================ // ============================================================================ -BiffPivotTableContext::BiffPivotTableContext( const BiffWorksheetFragmentBase& rFragment ) : - BiffWorksheetContextBase( rFragment ), +BiffPivotTableContext::BiffPivotTableContext( const WorksheetHelper& rHelper ) : + BiffWorksheetContextBase( rHelper ), mrPivotTable( getPivotTables().createPivotTable() ) { } diff --git a/oox/source/xls/querytablebuffer.cxx b/oox/source/xls/querytablebuffer.cxx index 8f65fe1438db..2a4df73287ca 100644 --- a/oox/source/xls/querytablebuffer.cxx +++ b/oox/source/xls/querytablebuffer.cxx @@ -283,18 +283,14 @@ void QueryTable::importQueryTable( BiffInputStream& rStrm ) // create a new connection object that will store settings from following records OSL_ENSURE( maModel.mnConnId == -1, "QueryTable::importQueryTable - multiple call" ); - ConnectionRef xConnection = getConnections().createConnection(); - OSL_ENSURE( xConnection.get(), "QueryTable::importQueryTable - cannot create connection object" ); - if( xConnection.get() ) - { - maModel.mnConnId = xConnection->getConnectionId(); - - // a DBQUERY record with some PCITEM_STRING records must follow - bool bHasDbQuery = (rStrm.getNextRecId() == BIFF_ID_DBQUERY) && rStrm.startNextRecord(); - OSL_ENSURE( bHasDbQuery, "QueryTable::importQueryTable - missing DBQUERY record" ); - if( bHasDbQuery ) - xConnection->importDbQuery( rStrm ); - } + Connection& rConnection = getConnections().createConnectionWithId(); + maModel.mnConnId = rConnection.getConnectionId(); + + // a DBQUERY record with some PCITEM_STRING records must follow + bool bHasDbQuery = (rStrm.getNextRecId() == BIFF_ID_DBQUERY) && rStrm.startNextRecord(); + OSL_ENSURE( bHasDbQuery, "QueryTable::importQueryTable - missing DBQUERY record" ); + if( bHasDbQuery ) + rConnection.importDbQuery( rStrm ); } void QueryTable::importQueryTableRefresh( BiffInputStream& rStrm ) diff --git a/oox/source/xls/querytablefragment.cxx b/oox/source/xls/querytablefragment.cxx index 493fb22bc632..2f4b2d06ff11 100644 --- a/oox/source/xls/querytablefragment.cxx +++ b/oox/source/xls/querytablefragment.cxx @@ -84,8 +84,8 @@ const RecordInfo* QueryTableFragment::getRecordInfos() const // ============================================================================ -BiffQueryTableContext::BiffQueryTableContext( const BiffWorksheetFragmentBase& rFragment ) : - BiffWorksheetContextBase( rFragment ), +BiffQueryTableContext::BiffQueryTableContext( const WorksheetHelper& rHelper ) : + BiffWorksheetContextBase( rHelper ), mrQueryTable( getQueryTables().createQueryTable() ) { } diff --git a/oox/source/xls/sheetdatacontext.cxx b/oox/source/xls/sheetdatacontext.cxx index e132ec74b689..258ec995e9e0 100644 --- a/oox/source/xls/sheetdatacontext.cxx +++ b/oox/source/xls/sheetdatacontext.cxx @@ -77,9 +77,6 @@ const sal_uInt16 BIFF12_ROW_CUSTOMHEIGHT = 0x2000; const sal_uInt16 BIFF12_ROW_CUSTOMFORMAT = 0x4000; const sal_uInt8 BIFF12_ROW_SHOWPHONETIC = 0x01; -const sal_uInt8 BIFF_BOOLERR_BOOL = 0; -const sal_uInt8 BIFF_BOOLERR_ERROR = 1; - const sal_uInt16 BIFF_DATATABLE_ROW = 0x0004; const sal_uInt16 BIFF_DATATABLE_2D = 0x0008; const sal_uInt16 BIFF_DATATABLE_REF1DEL = 0x0010; @@ -591,8 +588,8 @@ void SheetDataContext::importDataTable( RecordInputStream& rStrm ) // ============================================================================ -BiffSheetDataContext::BiffSheetDataContext( const BiffWorksheetFragmentBase& rParent ) : - BiffWorksheetContextBase( rParent ), +BiffSheetDataContext::BiffSheetDataContext( const WorksheetHelper& rHelper ) : + BiffWorksheetContextBase( rHelper ), mnBiff2XfId( 0 ) { mnArrayIgnoreSize = (getBiff() == BIFF2) ? 1 : ((getBiff() <= BIFF4) ? 2 : 6); diff --git a/oox/source/xls/tablebuffer.cxx b/oox/source/xls/tablebuffer.cxx index 1d4444986adc..53408f366ae5 100644 --- a/oox/source/xls/tablebuffer.cxx +++ b/oox/source/xls/tablebuffer.cxx @@ -28,9 +28,7 @@ #include "oox/xls/tablebuffer.hxx" #include <com/sun/star/sheet/XDatabaseRange.hpp> -#include <com/sun/star/sheet/XDatabaseRanges.hpp> #include "oox/helper/attributelist.hxx" -#include "oox/helper/containerhelper.hxx" #include "oox/helper/propertyset.hxx" #include "oox/helper/recordinputstream.hxx" #include "oox/xls/addressconverter.hxx" @@ -61,6 +59,7 @@ TableModel::TableModel() : Table::Table( const WorkbookHelper& rHelper ) : WorkbookHelper( rHelper ), + maAutoFilters( rHelper ), mnTokenIndex( -1 ) { } @@ -91,24 +90,20 @@ void Table::importTable( RecordInputStream& rStrm, sal_Int16 nSheet ) void Table::finalizeImport() { - // validate cell range - maDestRange = maModel.maRange; - bool bValidRange = getAddressConverter().validateCellRange( maDestRange, true, true ); - // create database range - if( bValidRange && (maModel.mnId > 0) && (maModel.maDisplayName.getLength() > 0) ) try + if( (maModel.mnId > 0) && (maModel.maDisplayName.getLength() > 0) ) try { - // find an unused name - PropertySet aDocProps( getDocument() ); - Reference< XDatabaseRanges > xDatabaseRanges( aDocProps.getAnyProperty( PROP_DatabaseRanges ), UNO_QUERY_THROW ); - Reference< XNameAccess > xNameAccess( xDatabaseRanges, UNO_QUERY_THROW ); - OUString aName = ContainerHelper::getUnusedName( xNameAccess, maModel.maDisplayName, '_' ); - xDatabaseRanges->addNewByName( aName, maModel.maRange ); - Reference< XDatabaseRange > xDatabaseRange( xDatabaseRanges->getByName( aName ), UNO_QUERY_THROW ); + maDBRangeName = maModel.maDisplayName; + Reference< XDatabaseRange > xDatabaseRange( createDatabaseRangeObject( maDBRangeName, maModel.maRange ), UNO_SET_THROW ); + maDestRange = xDatabaseRange->getDataArea(); + // get formula token index of the database range PropertySet aPropSet( xDatabaseRange ); if( !aPropSet.getProperty( mnTokenIndex, PROP_TokenIndex ) ) mnTokenIndex = -1; + + // filter settings + maAutoFilters.finalizeImport( xDatabaseRange ); } catch( Exception& ) { @@ -123,24 +118,19 @@ TableBuffer::TableBuffer( const WorkbookHelper& rHelper ) : { } -TableRef TableBuffer::importTable( const AttributeList& rAttribs, sal_Int16 nSheet ) -{ - TableRef xTable( new Table( *this ) ); - xTable->importTable( rAttribs, nSheet ); - insertTable( xTable ); - return xTable; -} - -TableRef TableBuffer::importTable( RecordInputStream& rStrm, sal_Int16 nSheet ) +Table& TableBuffer::createTable() { - TableRef xTable( new Table( *this ) ); - xTable->importTable( rStrm, nSheet ); - insertTable( xTable ); - return xTable; + TableVector::value_type xTable( new Table( *this ) ); + maTables.push_back( xTable ); + return *xTable; } void TableBuffer::finalizeImport() { + // map all tables by identifier and display name + for( TableVector::iterator aIt = maTables.begin(), aEnd = maTables.end(); aIt != aEnd; ++aIt ) + insertTableToMaps( *aIt ); + // finalize all valid tables maIdTables.forEachMem( &Table::finalizeImport ); } @@ -156,15 +146,15 @@ TableRef TableBuffer::getTable( const OUString& rDispName ) const // private -------------------------------------------------------------------- -void TableBuffer::insertTable( const TableRef& rxTable ) +void TableBuffer::insertTableToMaps( const TableRef& rxTable ) { sal_Int32 nTableId = rxTable->getTableId(); const OUString& rDispName = rxTable->getDisplayName(); if( (nTableId > 0) && (rDispName.getLength() > 0) ) { - OSL_ENSURE( !maIdTables.has( nTableId ), "TableBuffer::insertTable - multiple table identifier" ); + OSL_ENSURE( !maIdTables.has( nTableId ), "TableBuffer::insertTableToMaps - multiple table identifier" ); maIdTables[ nTableId ] = rxTable; - OSL_ENSURE( !maNameTables.has( rDispName ), "TableBuffer::insertTable - multiple table name" ); + OSL_ENSURE( !maNameTables.has( rDispName ), "TableBuffer::insertTableToMaps - multiple table name" ); maNameTables[ rDispName ] = rxTable; } } diff --git a/oox/source/xls/tablefragment.cxx b/oox/source/xls/tablefragment.cxx index 54415081a288..853a3d73ecd0 100644 --- a/oox/source/xls/tablefragment.cxx +++ b/oox/source/xls/tablefragment.cxx @@ -27,6 +27,10 @@ #include "oox/xls/tablefragment.hxx" +#include "oox/xls/autofilterbuffer.hxx" +#include "oox/xls/autofiltercontext.hxx" +#include "oox/xls/tablebuffer.hxx" + namespace oox { namespace xls { @@ -39,7 +43,8 @@ using ::rtl::OUString; // ============================================================================ TableFragment::TableFragment( const WorksheetHelper& rHelper, const OUString& rFragmentPath ) : - WorksheetFragmentBase( rHelper, rFragmentPath ) + WorksheetFragmentBase( rHelper, rFragmentPath ), + mrTable( getTables().createTable() ) { } @@ -49,7 +54,14 @@ ContextHandlerRef TableFragment::onCreateContext( sal_Int32 nElement, const Attr { case XML_ROOT_CONTEXT: if( nElement == XLS_TOKEN( table ) ) - mxTable = getTables().importTable( rAttribs, getSheetIndex() ); + { + mrTable.importTable( rAttribs, getSheetIndex() ); + return this; + } + break; + case XLS_TOKEN( table ): + if( nElement == XLS_TOKEN( autoFilter ) ) + return new AutoFilterContext( *this, mrTable.createAutoFilter() ); break; } return 0; @@ -61,7 +73,14 @@ ContextHandlerRef TableFragment::onCreateRecordContext( sal_Int32 nRecId, Record { case XML_ROOT_CONTEXT: if( nRecId == BIFF12_ID_TABLE ) - mxTable = getTables().importTable( rStrm, getSheetIndex() ); + { + mrTable.importTable( rStrm, getSheetIndex() ); + return this; + } + break; + case BIFF12_ID_TABLE: + if( nRecId == BIFF12_ID_AUTOFILTER ) + return new AutoFilterContext( *this, mrTable.createAutoFilter() ); break; } return 0; @@ -71,8 +90,12 @@ const RecordInfo* TableFragment::getRecordInfos() const { static const RecordInfo spRecInfos[] = { - { BIFF12_ID_TABLE, BIFF12_ID_TABLE + 1 }, - { -1, -1 } + { BIFF12_ID_AUTOFILTER, BIFF12_ID_AUTOFILTER + 1 }, + { BIFF12_ID_CUSTOMFILTERS, BIFF12_ID_CUSTOMFILTERS + 1 }, + { BIFF12_ID_DISCRETEFILTERS, BIFF12_ID_DISCRETEFILTERS + 1 }, + { BIFF12_ID_FILTERCOLUMN, BIFF12_ID_FILTERCOLUMN + 1 }, + { BIFF12_ID_TABLE, BIFF12_ID_TABLE + 1 }, + { -1, -1 } }; return spRecInfos; } diff --git a/oox/source/xls/workbookhelper.cxx b/oox/source/xls/workbookhelper.cxx index aa29e45c1d19..e523d6e42111 100644 --- a/oox/source/xls/workbookhelper.cxx +++ b/oox/source/xls/workbookhelper.cxx @@ -30,6 +30,8 @@ #include <com/sun/star/container/XIndexAccess.hpp> #include <com/sun/star/container/XNameContainer.hpp> #include <com/sun/star/document/XActionLockable.hpp> +#include <com/sun/star/sheet/XDatabaseRange.hpp> +#include <com/sun/star/sheet/XDatabaseRanges.hpp> #include <com/sun/star/sheet/XNamedRange.hpp> #include <com/sun/star/sheet/XNamedRanges.hpp> #include <com/sun/star/sheet/XSpreadsheet.hpp> @@ -136,6 +138,8 @@ public: Reference< XStyle > getStyleObject( const OUString& rStyleName, bool bPageStyle ) const; /** Creates and returns a defined name on-the-fly in the Calc document. */ Reference< XNamedRange > createNamedRangeObject( OUString& orName, sal_Int32 nNameFlags ) const; + /** Creates and returns a database range on-the-fly in the Calc document. */ + Reference< XDatabaseRange > createDatabaseRangeObject( OUString& orName, const CellRangeAddress& rRangeAddr ) const; /** Creates and returns a com.sun.star.style.Style object for cells or pages. */ Reference< XStyle > createStyleObject( OUString& orStyleName, bool bPageStyle ) const; @@ -350,17 +354,16 @@ Reference< XStyle > WorkbookData::getStyleObject( const OUString& rStyleName, bo Reference< XNamedRange > WorkbookData::createNamedRangeObject( OUString& orName, sal_Int32 nNameFlags ) const { - // find an unused name - PropertySet aDocProps( mxDoc ); - Reference< XNamedRanges > xNamedRanges( aDocProps.getAnyProperty( PROP_NamedRanges ), UNO_QUERY ); - Reference< XNameAccess > xNameAccess( xNamedRanges, UNO_QUERY ); - if( xNameAccess.is() ) - orName = ContainerHelper::getUnusedName( xNameAccess, orName, '_' ); - // create the name and insert it into the Calc document Reference< XNamedRange > xNamedRange; - if( xNamedRanges.is() && (orName.getLength() > 0) ) try + if( orName.getLength() > 0 ) try { + // find an unused name + PropertySet aDocProps( mxDoc ); + Reference< XNamedRanges > xNamedRanges( aDocProps.getAnyProperty( PROP_NamedRanges ), UNO_QUERY_THROW ); + Reference< XNameAccess > xNameAccess( xNamedRanges, UNO_QUERY_THROW ); + orName = ContainerHelper::getUnusedName( xNameAccess, orName, '_' ); + // create the named range xNamedRanges->addNewByName( orName, OUString(), CellAddress( 0, 0, 0 ), nNameFlags ); xNamedRange.set( xNamedRanges->getByName( orName ), UNO_QUERY ); } @@ -371,6 +374,32 @@ Reference< XNamedRange > WorkbookData::createNamedRangeObject( OUString& orName, return xNamedRange; } +Reference< XDatabaseRange > WorkbookData::createDatabaseRangeObject( OUString& orName, const CellRangeAddress& rRangeAddr ) const +{ + // validate cell range + CellRangeAddress aDestRange = rRangeAddr; + bool bValidRange = getAddressConverter().validateCellRange( aDestRange, true, true ); + + // create database range and insert it into the Calc document + Reference< XDatabaseRange > xDatabaseRange; + if( bValidRange && (orName.getLength() > 0) ) try + { + // find an unused name + PropertySet aDocProps( mxDoc ); + Reference< XDatabaseRanges > xDatabaseRanges( aDocProps.getAnyProperty( PROP_DatabaseRanges ), UNO_QUERY_THROW ); + Reference< XNameAccess > xNameAccess( xDatabaseRanges, UNO_QUERY_THROW ); + orName = ContainerHelper::getUnusedName( xNameAccess, orName, '_' ); + // create the database range + xDatabaseRanges->addNewByName( orName, aDestRange ); + xDatabaseRange.set( xDatabaseRanges->getByName( orName ), UNO_QUERY ); + } + catch( Exception& ) + { + } + OSL_ENSURE( xDatabaseRange.is(), "WorkbookData::createDatabaseRangeObject - cannot create database range" ); + return xDatabaseRange; +} + Reference< XStyle > WorkbookData::createStyleObject( OUString& orStyleName, bool bPageStyle ) const { Reference< XStyle > xStyle; @@ -714,6 +743,11 @@ Reference< XNamedRange > WorkbookHelper::createNamedRangeObject( OUString& orNam return mrBookData.createNamedRangeObject( orName, nNameFlags ); } +Reference< XDatabaseRange > WorkbookHelper::createDatabaseRangeObject( OUString& orName, const CellRangeAddress& rRangeAddr ) const +{ + return mrBookData.createDatabaseRangeObject( orName, rRangeAddr ); +} + Reference< XStyle > WorkbookHelper::createStyleObject( OUString& orStyleName, bool bPageStyle ) const { return mrBookData.createStyleObject( orStyleName, bPageStyle ); diff --git a/oox/source/xls/worksheetfragment.cxx b/oox/source/xls/worksheetfragment.cxx index 19dc8e34c70f..dc51981fe230 100644 --- a/oox/source/xls/worksheetfragment.cxx +++ b/oox/source/xls/worksheetfragment.cxx @@ -32,6 +32,7 @@ #include "oox/helper/attributelist.hxx" #include "oox/helper/recordinputstream.hxx" #include "oox/xls/addressconverter.hxx" +#include "oox/xls/autofilterbuffer.hxx" #include "oox/xls/autofiltercontext.hxx" #include "oox/xls/biffinputstream.hxx" #include "oox/xls/commentsfragment.hxx" @@ -267,9 +268,10 @@ ContextHandlerRef WorksheetFragment::onCreateContext( sal_Int32 nElement, const switch( nElement ) { case XLS_TOKEN( sheetData ): return new SheetDataContext( *this ); - case XLS_TOKEN( autoFilter ): return new AutoFilterContext( *this ); case XLS_TOKEN( conditionalFormatting ): return new CondFormatContext( *this ); case XLS_TOKEN( dataValidations ): return new DataValidationsContext( *this ); + case XLS_TOKEN( autoFilter ): return new AutoFilterContext( *this, getAutoFilters().createAutoFilter() ); + case XLS_TOKEN( scenarios ): return new ScenariosContext( *this ); case XLS_TOKEN( sheetViews ): case XLS_TOKEN( cols ): @@ -292,8 +294,6 @@ ContextHandlerRef WorksheetFragment::onCreateContext( sal_Int32 nElement, const case XLS_TOKEN( picture ): getPageSettings().importPicture( getRelations(), rAttribs ); break; case XLS_TOKEN( drawing ): importDrawing( rAttribs ); break; case XLS_TOKEN( legacyDrawing ): importLegacyDrawing( rAttribs ); break; - case XLS_TOKEN( scenarios ): - return new ScenariosContext( *this ); } break; @@ -387,6 +387,7 @@ ContextHandlerRef WorksheetFragment::onCreateRecordContext( sal_Int32 nRecId, Re case BIFF12_ID_SHEETDATA: return new SheetDataContext( *this ); case BIFF12_ID_CONDFORMATTING: return new CondFormatContext( *this ); case BIFF12_ID_DATAVALIDATIONS: return new DataValidationsContext( *this ); + case BIFF12_ID_AUTOFILTER: return new AutoFilterContext( *this, getAutoFilters().createAutoFilter() ); case BIFF12_ID_SCENARIOS: return new ScenariosContext( *this ); case BIFF12_ID_SHEETVIEWS: @@ -453,16 +454,20 @@ const RecordInfo* WorksheetFragment::getRecordInfos() const { static const RecordInfo spRecInfos[] = { + { BIFF12_ID_AUTOFILTER, BIFF12_ID_AUTOFILTER + 1 }, { BIFF12_ID_CFRULE, BIFF12_ID_CFRULE + 1 }, { BIFF12_ID_COLBREAKS, BIFF12_ID_COLBREAKS + 1 }, { BIFF12_ID_COLORSCALE, BIFF12_ID_COLORSCALE + 1 }, { BIFF12_ID_COLS, BIFF12_ID_COLS + 1 }, { BIFF12_ID_CONDFORMATTING, BIFF12_ID_CONDFORMATTING + 1 }, { BIFF12_ID_CONTROLS, BIFF12_ID_CONTROLS + 2 }, + { BIFF12_ID_CUSTOMFILTERS, BIFF12_ID_CUSTOMFILTERS + 1 }, { BIFF12_ID_CUSTOMSHEETVIEW, BIFF12_ID_CUSTOMSHEETVIEW + 1 }, { BIFF12_ID_CUSTOMSHEETVIEWS, BIFF12_ID_CUSTOMSHEETVIEWS + 3 }, { BIFF12_ID_DATABAR, BIFF12_ID_DATABAR + 1 }, { BIFF12_ID_DATAVALIDATIONS, BIFF12_ID_DATAVALIDATIONS + 1 }, + { BIFF12_ID_DISCRETEFILTERS, BIFF12_ID_DISCRETEFILTERS + 1 }, + { BIFF12_ID_FILTERCOLUMN, BIFF12_ID_FILTERCOLUMN + 1 }, { BIFF12_ID_HEADERFOOTER, BIFF12_ID_HEADERFOOTER + 1 }, { BIFF12_ID_ICONSET, BIFF12_ID_ICONSET + 1 }, { BIFF12_ID_MERGECELLS, BIFF12_ID_MERGECELLS + 1 }, @@ -862,6 +867,7 @@ bool BiffWorksheetFragment::importFragment() case BIFF5: switch( nRecId ) { + case BIFF_ID_AUTOFILTER: importAutoFilter( rStrm ); break; case BIFF_ID_COLINFO: importColInfo( rStrm ); break; case BIFF3_ID_DEFROWHEIGHT: importDefRowHeight( rStrm ); break; case BIFF_ID_HCENTER: rPageSett.importHorCenter( rStrm ); break; @@ -882,6 +888,7 @@ bool BiffWorksheetFragment::importFragment() case BIFF8: switch( nRecId ) { + case BIFF_ID_AUTOFILTER: importAutoFilter( rStrm ); break; case BIFF_ID_CFHEADER: rCondFormats.importCfHeader( rStrm ); break; case BIFF_ID_CODENAME: rWorksheetSett.importCodeName( rStrm ); break; case BIFF_ID_COLINFO: importColInfo( rStrm ); break; @@ -941,6 +948,12 @@ bool BiffWorksheetFragment::importFragment() // private -------------------------------------------------------------------- +void BiffWorksheetFragment::importAutoFilter( BiffInputStream& rStrm ) +{ + mxContext.reset( new BiffAutoFilterContext( *this, getAutoFilters().createAutoFilter() ) ); + mxContext->importRecord( rStrm ); +} + void BiffWorksheetFragment::importColInfo( BiffInputStream& rStrm ) { sal_uInt16 nFirstCol, nLastCol, nWidth, nXfId, nFlags; diff --git a/oox/source/xls/worksheethelper.cxx b/oox/source/xls/worksheethelper.cxx index 48a83ab07f11..de3b540df0a8 100644 --- a/oox/source/xls/worksheethelper.cxx +++ b/oox/source/xls/worksheethelper.cxx @@ -59,6 +59,7 @@ #include "oox/helper/containerhelper.hxx" #include "oox/helper/propertyset.hxx" #include "oox/xls/addressconverter.hxx" +#include "oox/xls/autofilterbuffer.hxx" #include "oox/xls/commentsbuffer.hxx" #include "oox/xls/condformatbuffer.hxx" #include "oox/xls/drawingfragment.hxx" @@ -389,6 +390,8 @@ public: inline CondFormatBuffer& getCondFormats() { return maCondFormats; } /** Returns the buffer for all cell comments in this sheet. */ inline CommentsBuffer& getComments() { return maComments; } + /** Returns the auto filters for the sheet. */ + inline AutoFilterBuffer& getAutoFilters() { return maAutoFilters; } /** Returns the buffer for all web query tables in this sheet. */ inline QueryTableBuffer& getQueryTables() { return maQueryTables; } /** Returns the page/print settings for this sheet. */ @@ -560,6 +563,7 @@ private: SharedFormulaBuffer maSharedFmlas; /// Buffer for shared formulas in this sheet. CondFormatBuffer maCondFormats; /// Buffer for conditional formattings. CommentsBuffer maComments; /// Buffer for all cell comments in this sheet. + AutoFilterBuffer maAutoFilters; /// Sheet auto filters (not associated to a table). QueryTableBuffer maQueryTables; /// Buffer for all web query tables in this sheet. PageSettings maPageSett; /// Page/print settings for this sheet. SheetViewSettings maSheetViewSett; /// View settings for this sheet. @@ -589,6 +593,7 @@ WorksheetData::WorksheetData( const WorkbookHelper& rHelper, const ISegmentProgr maSharedFmlas( *this ), maCondFormats( *this ), maComments( *this ), + maAutoFilters( *this ), maQueryTables( *this ), maPageSett( *this ), maSheetViewSett( *this ), @@ -1050,6 +1055,7 @@ void WorksheetData::finalizeWorksheetImport() finalizeHyperlinkRanges(); finalizeValidationRanges(); finalizeMergedRanges(); + maAutoFilters.finalizeImport( getSheetIndex() ); maSheetSett.finalizeImport(); maCondFormats.finalizeImport(); maQueryTables.finalizeImport(); @@ -1842,6 +1848,11 @@ CommentsBuffer& WorksheetHelper::getComments() const return mrSheetData.getComments(); } +AutoFilterBuffer& WorksheetHelper::getAutoFilters() const +{ + return mrSheetData.getAutoFilters(); +} + QueryTableBuffer& WorksheetHelper::getQueryTables() const { return mrSheetData.getQueryTables(); |