1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: pivottablefragment.cxx,v $
9 * last change: $Author: rt $ $Date: 2008-01-17 08:06:09 $
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
34 ************************************************************************/
36 #include "oox/xls/pivottablefragment.hxx"
37 #include "oox/helper/attributelist.hxx"
38 #include "oox/helper/propertyset.hxx"
39 #include "oox/xls/addressconverter.hxx"
41 #define DEBUG_OOX_PIVOTTABLE 1
45 #if DEBUG_OOX_PIVOTTABLE
49 using ::rtl::OUString
;
50 using ::com::sun::star::uno::Any
;
51 using ::com::sun::star::uno::Reference
;
52 using ::com::sun::star::uno::Sequence
;
53 using ::com::sun::star::uno::Exception
;
54 using ::com::sun::star::uno::RuntimeException
;
55 using ::com::sun::star::uno::UNO_QUERY
;
56 using ::com::sun::star::uno::UNO_QUERY_THROW
;
57 using ::com::sun::star::table::CellRangeAddress
;
58 using ::com::sun::star::xml::sax::SAXException
;
63 OoxPivotTableFragment::OoxPivotTableFragment(
64 const WorksheetHelper
& rHelper
, const OUString
& rFragmentPath
) :
65 OoxWorksheetFragmentBase( rHelper
, rFragmentPath
),
70 bool OoxPivotTableFragment::onCanCreateContext( sal_Int32 nElement
) const
72 switch( getCurrentContext() )
74 case XML_ROOT_CONTEXT
: return (nElement
== XLS_TOKEN( pivotTableDefinition
));
75 case XLS_TOKEN( pivotTableDefinition
): return (nElement
== XLS_TOKEN( location
)) ||
76 (nElement
== XLS_TOKEN( pivotFields
)) ||
77 (nElement
== XLS_TOKEN( rowFields
)) ||
78 (nElement
== XLS_TOKEN( rowItems
)) ||
79 (nElement
== XLS_TOKEN( colFields
)) ||
80 (nElement
== XLS_TOKEN( colItems
)) ||
81 (nElement
== XLS_TOKEN( pageFields
)) ||
82 (nElement
== XLS_TOKEN( dataFields
)) ||
83 (nElement
== XLS_TOKEN( pivotTableStyleInfo
));
84 case XLS_TOKEN( pivotFields
): return (nElement
== XLS_TOKEN( pivotField
));
85 case XLS_TOKEN( pivotField
): return (nElement
== XLS_TOKEN( items
));
86 case XLS_TOKEN( items
): return (nElement
== XLS_TOKEN( item
));
87 case XLS_TOKEN( rowFields
): return (nElement
== XLS_TOKEN( field
));
88 case XLS_TOKEN( colFields
): return (nElement
== XLS_TOKEN( field
));
89 case XLS_TOKEN( pageFields
): return (nElement
== XLS_TOKEN( pageField
));
90 case XLS_TOKEN( dataFields
): return (nElement
== XLS_TOKEN( dataField
));
91 case XLS_TOKEN( colItems
): return (nElement
== XLS_TOKEN( i
));
92 case XLS_TOKEN( rowItems
): return (nElement
== XLS_TOKEN( i
));
97 void OoxPivotTableFragment::onStartElement( const AttributeList
& rAttribs
)
99 switch ( getCurrentContext() )
101 case XLS_TOKEN( pivotTableDefinition
):
102 importPivotTableDefinition( rAttribs
);
104 case XLS_TOKEN( location
):
105 importLocation( rAttribs
);
107 case XLS_TOKEN( pivotFields
):
108 importPivotFields( rAttribs
);
110 case XLS_TOKEN( pivotField
):
111 importPivotField( rAttribs
);
116 void OoxPivotTableFragment::finalizeImport()
119 getPivotTables().setPivotTable( maName
, maData
);
122 void OoxPivotTableFragment::importLocation( const AttributeList
& rAttribs
)
124 CellRangeAddress aRange
;
125 OUString aRangeName
= rAttribs
.getString( XML_ref
);
126 mbValidRange
= getAddressConverter().convertToCellRange(
127 aRange
, aRangeName
, getSheetIndex(), true );
130 maData
.maRange
= aRange
;
133 void OoxPivotTableFragment::importPivotTableDefinition( const AttributeList
& rAttribs
)
135 if ( !rAttribs
.hasAttribute( XML_cacheId
) )
138 maName
= rAttribs
.getString( XML_name
);
139 maData
.mnCacheId
= rAttribs
.getInteger( XML_cacheId
, 0 );
141 // name="PivotTable3"
143 // applyNumberFormats="0"
144 // applyBorderFormats="0"
145 // applyFontFormats="0"
146 // applyPatternFormats="0"
147 // applyAlignmentFormats="0"
148 // applyWidthHeightFormats="1"
149 // dataCaption="Values"
150 // updatedVersion="3"
151 // minRefreshableVersion="3"
153 // useAutoFormatting="1"
154 // itemPrintTitles="1"
155 // createdVersion="3"
159 // multipleFieldFilters="0"
162 void OoxPivotTableFragment::importPivotFields( const AttributeList
& rAttribs
)
164 maData
.maFields
.reserve( rAttribs
.getUnsignedInteger( XML_count
, 1 ) );
167 void OoxPivotTableFragment::importPivotField( const AttributeList
& rAttribs
)
169 maData
.maFields
.push_back( PivotTableField() );
170 PivotTableField
& rField
= maData
.maFields
.back();
171 rField
.mbDataField
= rAttribs
.getBool( XML_dataField
, false );
173 // Possible values are: axisCol, axisRow, axisPage, axisValues
174 switch ( rAttribs
.getToken( XML_axis
) )
177 rField
.meAxis
= PivotTableField::COLUMN
;
180 rField
.meAxis
= PivotTableField::ROW
;
183 rField
.meAxis
= PivotTableField::PAGE
;
186 rField
.meAxis
= PivotTableField::VALUES
;