Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "pivottablebuffer.hxx"
21 :
22 : #include <set>
23 : #include <com/sun/star/container/XIndexAccess.hpp>
24 : #include <com/sun/star/container/XNameAccess.hpp>
25 : #include <com/sun/star/sheet/CellFlags.hpp>
26 : #include <com/sun/star/sheet/DataPilotFieldAutoShowInfo.hpp>
27 : #include <com/sun/star/sheet/DataPilotFieldLayoutInfo.hpp>
28 : #include <com/sun/star/sheet/DataPilotFieldLayoutMode.hpp>
29 : #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
30 : #include <com/sun/star/sheet/DataPilotFieldReference.hpp>
31 : #include <com/sun/star/sheet/DataPilotFieldReferenceItemType.hpp>
32 : #include <com/sun/star/sheet/DataPilotFieldReferenceType.hpp>
33 : #include <com/sun/star/sheet/DataPilotFieldShowItemsMode.hpp>
34 : #include <com/sun/star/sheet/DataPilotFieldSortInfo.hpp>
35 : #include <com/sun/star/sheet/DataPilotFieldSortMode.hpp>
36 : #include <com/sun/star/sheet/GeneralFunction.hpp>
37 : #include <com/sun/star/sheet/XDataPilotDataLayoutFieldSupplier.hpp>
38 : #include <com/sun/star/sheet/XDataPilotField.hpp>
39 : #include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp>
40 : #include <com/sun/star/sheet/XSheetOperation.hpp>
41 : #include "oox/helper/attributelist.hxx"
42 : #include "oox/helper/containerhelper.hxx"
43 : #include "oox/helper/propertyset.hxx"
44 : #include "oox/token/properties.hxx"
45 : #include "addressconverter.hxx"
46 : #include "biffinputstream.hxx"
47 :
48 : #include "dapiuno.hxx"
49 : #include "dpobject.hxx"
50 : #include "dpsave.hxx"
51 :
52 : namespace oox {
53 : namespace xls {
54 :
55 : using namespace ::com::sun::star::container;
56 : using namespace ::com::sun::star::sheet;
57 : using namespace ::com::sun::star::table;
58 : using namespace ::com::sun::star::uno;
59 : using namespace com::sun::star;
60 :
61 :
62 : namespace {
63 :
64 : const sal_Int32 OOX_PT_DATALAYOUTFIELD = -2; /// Placeholder index of data layout field.
65 :
66 : const sal_Int32 OOX_PT_PREVIOUS_ITEM = 0x001000FC; /// Calculation of data item result is based on previous item.
67 : const sal_Int32 OOX_PT_NEXT_ITEM = 0x001000FD; /// Calculation of data item result is based on next item.
68 :
69 : const sal_uInt32 BIFF12_PTFIELD_DATAFIELD = 0x00000008;
70 : const sal_uInt32 BIFF12_PTFIELD_DEFAULT = 0x00000100;
71 : const sal_uInt32 BIFF12_PTFIELD_SUM = 0x00000200;
72 : const sal_uInt32 BIFF12_PTFIELD_COUNTA = 0x00000400;
73 : const sal_uInt32 BIFF12_PTFIELD_AVERAGE = 0x00000800;
74 : const sal_uInt32 BIFF12_PTFIELD_MAX = 0x00001000;
75 : const sal_uInt32 BIFF12_PTFIELD_MIN = 0x00002000;
76 : const sal_uInt32 BIFF12_PTFIELD_PRODUCT = 0x00004000;
77 : const sal_uInt32 BIFF12_PTFIELD_COUNT = 0x00008000;
78 : const sal_uInt32 BIFF12_PTFIELD_STDDEV = 0x00010000;
79 : const sal_uInt32 BIFF12_PTFIELD_STDDEVP = 0x00020000;
80 : const sal_uInt32 BIFF12_PTFIELD_VAR = 0x00040000;
81 : const sal_uInt32 BIFF12_PTFIELD_VARP = 0x00080000;
82 :
83 : const sal_uInt32 BIFF12_PTFIELD_SHOWALL = 0x00000020;
84 : const sal_uInt32 BIFF12_PTFIELD_OUTLINE = 0x00000040;
85 : const sal_uInt32 BIFF12_PTFIELD_INSERTBLANKROW = 0x00000080;
86 : const sal_uInt32 BIFF12_PTFIELD_SUBTOTALTOP = 0x00000100;
87 : const sal_uInt32 BIFF12_PTFIELD_INSERTPAGEBREAK = 0x00000800;
88 : const sal_uInt32 BIFF12_PTFIELD_AUTOSORT = 0x00001000;
89 : const sal_uInt32 BIFF12_PTFIELD_SORTASCENDING = 0x00002000;
90 : const sal_uInt32 BIFF12_PTFIELD_AUTOSHOW = 0x00004000;
91 : const sal_uInt32 BIFF12_PTFIELD_AUTOSHOWTOP = 0x00008000;
92 : const sal_uInt32 BIFF12_PTFIELD_MULTIPAGEITEMS = 0x00080000;
93 :
94 : const sal_uInt16 BIFF12_PTFITEM_HIDDEN = 0x0001;
95 : const sal_uInt16 BIFF12_PTFITEM_HIDEDETAILS = 0x0002;
96 :
97 : const sal_uInt8 BIFF12_PTPAGEFIELD_HASNAME = 0x01;
98 : const sal_Int32 BIFF12_PTPAGEFIELD_MULTIITEMS = 0x001000FE;
99 :
100 : const sal_uInt16 BIFF12_PTFILTER_HASNAME = 0x0001;
101 : const sal_uInt16 BIFF12_PTFILTER_HASDESCRIPTION = 0x0002;
102 : const sal_uInt16 BIFF12_PTFILTER_HASSTRVALUE1 = 0x0004;
103 : const sal_uInt16 BIFF12_PTFILTER_HASSTRVALUE2 = 0x0008;
104 :
105 : const sal_uInt8 BIFF12_TOP10FILTER_TOP = 0x01;
106 : const sal_uInt8 BIFF12_TOP10FILTER_PERCENT = 0x02;
107 :
108 : const sal_uInt32 BIFF12_PTDEF_SHOWITEMS = 0x00000100;
109 : const sal_uInt32 BIFF12_PTDEF_DISABLEFIELDLIST = 0x00000400;
110 : const sal_uInt32 BIFF12_PTDEF_HIDECALCMEMBERS = 0x00001000;
111 : const sal_uInt32 BIFF12_PTDEF_WITHHIDDENTOTALS = 0x00002000;
112 : const sal_uInt32 BIFF12_PTDEF_HIDEDRILL = 0x00100000;
113 : const sal_uInt32 BIFF12_PTDEF_PRINTDRILL = 0x00200000;
114 : const sal_uInt32 BIFF12_PTDEF_HIDEHEADERS = 0x80000000;
115 :
116 : const sal_uInt32 BIFF12_PTDEF_SHOWEMPTYROW = 0x00000004;
117 : const sal_uInt32 BIFF12_PTDEF_SHOWEMPTYCOL = 0x00000008;
118 : const sal_uInt32 BIFF12_PTDEF_ENABLEDRILL = 0x00000020;
119 : const sal_uInt32 BIFF12_PTDEF_PRESERVEFORMATTING = 0x00000080;
120 : const sal_uInt32 BIFF12_PTDEF_USEAUTOFORMAT = 0x00000100;
121 : const sal_uInt32 BIFF12_PTDEF_SHOWERROR = 0x00000200;
122 : const sal_uInt32 BIFF12_PTDEF_SHOWMISSING = 0x00000400;
123 : const sal_uInt32 BIFF12_PTDEF_PAGEOVERTHENDOWN = 0x00000800;
124 : const sal_uInt32 BIFF12_PTDEF_SUBTOTALHIDDENITEMS = 0x00001000;
125 : const sal_uInt32 BIFF12_PTDEF_ROWGRANDTOTALS = 0x00002000;
126 : const sal_uInt32 BIFF12_PTDEF_COLGRANDTOTALS = 0x00004000;
127 : const sal_uInt32 BIFF12_PTDEF_FIELDPRINTTITLES = 0x00008000;
128 : const sal_uInt32 BIFF12_PTDEF_ITEMPRINTTITLES = 0x00020000;
129 : const sal_uInt32 BIFF12_PTDEF_MERGEITEM = 0x00040000;
130 : const sal_uInt32 BIFF12_PTDEF_HASDATACAPTION = 0x00080000;
131 : const sal_uInt32 BIFF12_PTDEF_HASGRANDTOTALCAPTION = 0x00100000;
132 : const sal_uInt32 BIFF12_PTDEF_HASPAGESTYLE = 0x00200000;
133 : const sal_uInt32 BIFF12_PTDEF_HASPIVOTTABLESTYLE = 0x00400000;
134 : const sal_uInt32 BIFF12_PTDEF_HASVACATEDSTYLE = 0x00800000;
135 : const sal_uInt32 BIFF12_PTDEF_APPLYNUMFMT = 0x01000000;
136 : const sal_uInt32 BIFF12_PTDEF_APPLYFONT = 0x02000000;
137 : const sal_uInt32 BIFF12_PTDEF_APPLYALIGNMENT = 0x04000000;
138 : const sal_uInt32 BIFF12_PTDEF_APPLYBORDER = 0x08000000;
139 : const sal_uInt32 BIFF12_PTDEF_APPLYFILL = 0x10000000;
140 : const sal_uInt32 BIFF12_PTDEF_APPLYPROTECTION = 0x20000000;
141 : const sal_uInt32 BIFF12_PTDEF_HASTAG = 0x40000000;
142 :
143 : const sal_uInt32 BIFF12_PTDEF_NOERRORCAPTION = 0x00000040;
144 : const sal_uInt32 BIFF12_PTDEF_NOMISSINGCAPTION = 0x00000080;
145 : const sal_uInt32 BIFF12_PTDEF_HASROWHEADERCAPTION = 0x00000400;
146 : const sal_uInt32 BIFF12_PTDEF_HASCOLHEADERCAPTION = 0x00000800;
147 : const sal_uInt32 BIFF12_PTDEF_FIELDLISTSORTASC = 0x00001000;
148 : const sal_uInt32 BIFF12_PTDEF_NOCUSTOMLISTSORT = 0x00004000;
149 :
150 : const sal_uInt8 BIFF12_PTDEF_ROWAXIS = 1;
151 : const sal_uInt8 BIFF12_PTDEF_COLAXIS = 2;
152 :
153 : } // namespace
154 :
155 0 : PTFieldItemModel::PTFieldItemModel() :
156 : mnCacheItem( -1 ),
157 : mnType( XML_data ),
158 : mbShowDetails( true ),
159 0 : mbHidden( false )
160 : {
161 0 : }
162 :
163 0 : void PTFieldItemModel::setBiffType( sal_uInt16 nType )
164 : {
165 : static const sal_Int32 spnTypes[] = { XML_data, XML_default,
166 : XML_sum, XML_countA, XML_avg, XML_max, XML_min, XML_product, XML_count,
167 : XML_stdDev, XML_stdDevP, XML_var, XML_varP, XML_grand, XML_blank };
168 0 : mnType = STATIC_ARRAY_SELECT( spnTypes, nType, XML_data );
169 0 : }
170 :
171 0 : PTFieldModel::PTFieldModel() :
172 : mnAxis( XML_TOKEN_INVALID ),
173 : mnNumFmtId( 0 ),
174 : mnAutoShowItems( 10 ),
175 : mnAutoShowRankBy( -1 ),
176 : mnSortType( XML_manual ),
177 : mnSortRefField( -1 ),
178 : mnSortRefItem( -1 ),
179 : mbDataField( false ),
180 : mbDefaultSubtotal( true ),
181 : mbSumSubtotal( false ),
182 : mbCountASubtotal( false ),
183 : mbAverageSubtotal( false ),
184 : mbMaxSubtotal( false ),
185 : mbMinSubtotal( false ),
186 : mbProductSubtotal( false ),
187 : mbCountSubtotal( false ),
188 : mbStdDevSubtotal( false ),
189 : mbStdDevPSubtotal( false ),
190 : mbVarSubtotal( false ),
191 : mbVarPSubtotal( false ),
192 : mbShowAll( true ),
193 : mbOutline( true ),
194 : mbSubtotalTop( true ),
195 : mbInsertBlankRow( false ),
196 : mbInsertPageBreak( false ),
197 : mbAutoShow( false ),
198 : mbTopAutoShow( true ),
199 0 : mbMultiPageItems( false )
200 : {
201 0 : }
202 :
203 0 : void PTFieldModel::setBiffAxis( sal_uInt8 nAxis )
204 : {
205 : /* Weird. The axis field is organized as bit field, but only one of the
206 : row/col/page flags are allowed at the same time and refer to the values
207 : 'axisRow', 'axisCol', and 'axisPage' of the XML attribute
208 : 'pivotField@axis'. Additionally, the fourth bit determines if the field
209 : is a data field, which may appear combined with the row/col/page flags.
210 : Therefore, this bit is unrelated to the 'axisValues' value of the
211 : 'pivotField@axis' attribute, but refers to the 'pivotField@dataField'
212 : boolean attribute. */
213 : static const sal_Int32 spnAxisIds[] = { XML_TOKEN_INVALID, XML_axisRow, XML_axisCol, XML_TOKEN_INVALID, XML_axisPage };
214 0 : mnAxis = STATIC_ARRAY_SELECT( spnAxisIds, nAxis, XML_TOKEN_INVALID );
215 0 : }
216 :
217 0 : PTPageFieldModel::PTPageFieldModel() :
218 : mnField( -1 ),
219 0 : mnItem( BIFF12_PTPAGEFIELD_MULTIITEMS )
220 : {
221 0 : }
222 :
223 0 : PTDataFieldModel::PTDataFieldModel() :
224 : mnField( -1 ),
225 : mnSubtotal( XML_sum ),
226 : mnShowDataAs( XML_normal ),
227 : mnBaseField( -1 ),
228 : mnBaseItem( -1 ),
229 0 : mnNumFmtId( 0 )
230 : {
231 0 : }
232 :
233 0 : void PTDataFieldModel::setBiffSubtotal( sal_Int32 nSubtotal )
234 : {
235 : static const sal_Int32 spnSubtotals[] = { XML_sum, XML_count, XML_average, XML_max, XML_min, XML_product, XML_countNums, XML_stdDev, XML_stdDevp, XML_var, XML_varp };
236 0 : mnSubtotal = STATIC_ARRAY_SELECT( spnSubtotals, nSubtotal, XML_TOKEN_INVALID );
237 0 : }
238 :
239 0 : void PTDataFieldModel::setBiffShowDataAs( sal_Int32 nShowDataAs )
240 : {
241 : static const sal_Int32 spnShowDataAs[] = { XML_normal, XML_difference, XML_percent, XML_percentDiff, XML_runTotal, XML_percentOfRow, XML_percentOfCol, XML_percentOfTotal, XML_index };
242 0 : mnShowDataAs = STATIC_ARRAY_SELECT( spnShowDataAs, nShowDataAs, XML_TOKEN_INVALID );
243 0 : }
244 :
245 0 : PivotTableField::PivotTableField( PivotTable& rPivotTable, sal_Int32 nFieldIndex ) :
246 : WorkbookHelper( rPivotTable ),
247 : mrPivotTable( rPivotTable ),
248 0 : mnFieldIndex( nFieldIndex )
249 : {
250 0 : }
251 :
252 0 : void PivotTableField::importPivotField( const AttributeList& rAttribs )
253 : {
254 : /* The documentation mentions a value 'axisValues' for the attribute
255 : 'pivotField@axis'. But this value is not used to mark a data field, as
256 : data fields may be inserted in one of the row/column/page dimensions at
257 : the same time. Therefore, the boolean attribute 'pivotField@dataField'
258 : is really used to mark data fields. */
259 0 : maModel.mnAxis = rAttribs.getToken( XML_axis, XML_TOKEN_INVALID );
260 0 : maModel.mnNumFmtId = rAttribs.getInteger( XML_numFmtId, 0 );
261 0 : maModel.mnAutoShowItems = rAttribs.getInteger( XML_itemPageCount, 10 );
262 0 : maModel.mnAutoShowRankBy = rAttribs.getInteger( XML_rankBy, -1 );
263 0 : maModel.mnSortType = rAttribs.getToken( XML_sortType, XML_manual );
264 0 : maModel.mbDataField = rAttribs.getBool( XML_dataField, false );
265 0 : maModel.mbDefaultSubtotal = rAttribs.getBool( XML_defaultSubtotal, true );
266 0 : maModel.mbSumSubtotal = rAttribs.getBool( XML_sumSubtotal, false );
267 0 : maModel.mbCountASubtotal = rAttribs.getBool( XML_countASubtotal, false );
268 0 : maModel.mbAverageSubtotal = rAttribs.getBool( XML_avgSubtotal, false );
269 0 : maModel.mbMaxSubtotal = rAttribs.getBool( XML_maxSubtotal, false );
270 0 : maModel.mbMinSubtotal = rAttribs.getBool( XML_minSubtotal, false );
271 0 : maModel.mbProductSubtotal = rAttribs.getBool( XML_productSubtotal, false );
272 0 : maModel.mbCountSubtotal = rAttribs.getBool( XML_countSubtotal, false );
273 0 : maModel.mbStdDevSubtotal = rAttribs.getBool( XML_stdDevSubtotal, false );
274 0 : maModel.mbStdDevPSubtotal = rAttribs.getBool( XML_stdDevPSubtotal, false );
275 0 : maModel.mbVarSubtotal = rAttribs.getBool( XML_varSubtotal, false );
276 0 : maModel.mbVarPSubtotal = rAttribs.getBool( XML_varPSubtotal, false );
277 0 : maModel.mbShowAll = rAttribs.getBool( XML_showAll, true );
278 0 : maModel.mbOutline = rAttribs.getBool( XML_outline, true );
279 0 : maModel.mbSubtotalTop = rAttribs.getBool( XML_subtotalTop, true );
280 0 : maModel.mbInsertBlankRow = rAttribs.getBool( XML_insertBlankRow, false );
281 0 : maModel.mbInsertPageBreak = rAttribs.getBool( XML_insertPageBreak, false );
282 0 : maModel.mbAutoShow = rAttribs.getBool( XML_autoShow, false );
283 0 : maModel.mbTopAutoShow = rAttribs.getBool( XML_topAutoShow, true );
284 0 : maModel.mbMultiPageItems = rAttribs.getBool( XML_multipleItemSelectionAllowed, false );
285 0 : }
286 :
287 0 : void PivotTableField::importItem( const AttributeList& rAttribs )
288 : {
289 0 : PTFieldItemModel aModel;
290 0 : aModel.mnCacheItem = rAttribs.getInteger( XML_x, -1 );
291 0 : aModel.mnType = rAttribs.getToken( XML_t, XML_data );
292 0 : aModel.mbShowDetails = rAttribs.getBool( XML_sd, true );
293 0 : aModel.mbHidden = rAttribs.getBool( XML_h, false );
294 0 : aModel.msCaption = rAttribs.getXString( XML_n, OUString() );
295 0 : maItems.push_back( aModel );
296 0 : }
297 :
298 0 : void PivotTableField::importReference( const AttributeList& rAttribs )
299 : {
300 : // field index is stored as unsigned integer
301 0 : maModel.mnSortRefField = static_cast< sal_Int32 >( rAttribs.getUnsigned( XML_field, SAL_MAX_UINT32 ) );
302 0 : }
303 :
304 0 : void PivotTableField::importReferenceItem( const AttributeList& rAttribs )
305 : {
306 0 : maModel.mnSortRefItem = rAttribs.getInteger( XML_v, -1 );
307 0 : }
308 :
309 0 : void PivotTableField::importPTField( SequenceInputStream& rStrm )
310 : {
311 : sal_uInt32 nFlags1, nFlags2;
312 0 : rStrm >> nFlags1 >> maModel.mnNumFmtId >> nFlags2 >> maModel.mnAutoShowItems >> maModel.mnAutoShowRankBy;
313 :
314 0 : maModel.setBiffAxis( extractValue< sal_uInt8 >( nFlags1, 0, 3 ) );
315 0 : maModel.mbDataField = getFlag( nFlags1, BIFF12_PTFIELD_DATAFIELD );
316 0 : maModel.mbDefaultSubtotal = getFlag( nFlags1, BIFF12_PTFIELD_DEFAULT );
317 0 : maModel.mbSumSubtotal = getFlag( nFlags1, BIFF12_PTFIELD_SUM );
318 0 : maModel.mbCountASubtotal = getFlag( nFlags1, BIFF12_PTFIELD_COUNTA );
319 0 : maModel.mbAverageSubtotal = getFlag( nFlags1, BIFF12_PTFIELD_AVERAGE );
320 0 : maModel.mbMaxSubtotal = getFlag( nFlags1, BIFF12_PTFIELD_MAX );
321 0 : maModel.mbMinSubtotal = getFlag( nFlags1, BIFF12_PTFIELD_MIN );
322 0 : maModel.mbProductSubtotal = getFlag( nFlags1, BIFF12_PTFIELD_PRODUCT );
323 0 : maModel.mbCountSubtotal = getFlag( nFlags1, BIFF12_PTFIELD_COUNT );
324 0 : maModel.mbStdDevSubtotal = getFlag( nFlags1, BIFF12_PTFIELD_STDDEV );
325 0 : maModel.mbStdDevPSubtotal = getFlag( nFlags1, BIFF12_PTFIELD_STDDEVP );
326 0 : maModel.mbVarSubtotal = getFlag( nFlags1, BIFF12_PTFIELD_VAR );
327 0 : maModel.mbVarPSubtotal = getFlag( nFlags1, BIFF12_PTFIELD_VARP );
328 :
329 0 : maModel.mbShowAll = getFlag( nFlags2, BIFF12_PTFIELD_SHOWALL );
330 0 : maModel.mbOutline = getFlag( nFlags2, BIFF12_PTFIELD_OUTLINE );
331 0 : maModel.mbSubtotalTop = getFlag( nFlags2, BIFF12_PTFIELD_SUBTOTALTOP );
332 0 : maModel.mbInsertBlankRow = getFlag( nFlags2, BIFF12_PTFIELD_INSERTBLANKROW );
333 0 : maModel.mbInsertPageBreak = getFlag( nFlags2, BIFF12_PTFIELD_INSERTPAGEBREAK );
334 0 : maModel.mbAutoShow = getFlag( nFlags2, BIFF12_PTFIELD_AUTOSHOW );
335 0 : maModel.mbTopAutoShow = getFlag( nFlags2, BIFF12_PTFIELD_AUTOSHOWTOP );
336 0 : maModel.mbMultiPageItems = getFlag( nFlags2, BIFF12_PTFIELD_MULTIPAGEITEMS );
337 :
338 0 : bool bAutoSort = getFlag( nFlags2, BIFF12_PTFIELD_AUTOSORT );
339 0 : bool bAscending = getFlag( nFlags2, BIFF12_PTFIELD_SORTASCENDING );
340 0 : maModel.mnSortType = bAutoSort ? (bAscending ? XML_ascending : XML_descending) : XML_manual;
341 0 : }
342 :
343 0 : void PivotTableField::importPTFItem( SequenceInputStream& rStrm )
344 : {
345 0 : PTFieldItemModel aModel;
346 : sal_uInt8 nType;
347 : sal_uInt16 nFlags;
348 0 : rStrm >> nType >> nFlags >> aModel.mnCacheItem;
349 :
350 0 : aModel.setBiffType( nType );
351 0 : aModel.mbShowDetails = !getFlag( nFlags, BIFF12_PTFITEM_HIDEDETAILS );
352 0 : aModel.mbHidden = getFlag( nFlags, BIFF12_PTFITEM_HIDDEN );
353 :
354 0 : maItems.push_back( aModel );
355 0 : }
356 :
357 0 : void PivotTableField::importPTReference( SequenceInputStream& rStrm )
358 : {
359 0 : rStrm >> maModel.mnSortRefField;
360 0 : }
361 :
362 0 : void PivotTableField::importPTReferenceItem( SequenceInputStream& rStrm )
363 : {
364 0 : rStrm >> maModel.mnSortRefItem;
365 0 : }
366 :
367 0 : void PivotTableField::finalizeImport( const Reference< XDataPilotDescriptor >& rxDPDesc )
368 : {
369 : /* Process all fields based on source data, other fields (e.g. group
370 : fields) are processed from here. PivotCacahe::getDatabaseIndex()
371 : returns -1 for all fields not based on source data. */
372 0 : Reference< XDataPilotField > xDPField;
373 0 : sal_Int32 nDatabaseIdx = mrPivotTable.getCacheDatabaseIndex( mnFieldIndex );
374 0 : if( (nDatabaseIdx >= 0) && rxDPDesc.is() ) try
375 : {
376 : // try to get the source field and its name from passed DataPilot descriptor
377 0 : Reference< XIndexAccess > xDPFieldsIA( rxDPDesc->getDataPilotFields(), UNO_SET_THROW );
378 0 : xDPField.set( xDPFieldsIA->getByIndex( nDatabaseIdx ), UNO_QUERY_THROW );
379 0 : Reference< XNamed > xDPFieldName( xDPField, UNO_QUERY_THROW );
380 0 : maDPFieldName = xDPFieldName->getName();
381 : OSL_ENSURE( !maDPFieldName.isEmpty(), "PivotTableField::finalizeImport - no field name in source data found" );
382 :
383 : // try to convert grouping settings
384 0 : if( const PivotCacheField* pCacheField = mrPivotTable.getCacheField( mnFieldIndex ) )
385 : {
386 : // numeric grouping is done inplace, no nested group fields will appear
387 0 : if( pCacheField->hasNumericGrouping() )
388 : {
389 0 : pCacheField->convertNumericGrouping( xDPField );
390 : }
391 0 : else if( pCacheField->hasDateGrouping() )
392 : {
393 : // first date group settings are inplace
394 0 : pCacheField->createDateGroupField( xDPField );
395 : // create all nested group fields (if any)
396 0 : mrPivotTable.finalizeDateGroupingImport( xDPField, mnFieldIndex );
397 : }
398 0 : else if( pCacheField->hasParentGrouping() )
399 : {
400 :
401 : // create a list of all item names, needed to map between original and group items
402 0 : ::std::vector< OUString > aItems;
403 0 : pCacheField->getCacheItemNames( aItems );
404 0 : PivotCacheGroupItemVector aItemNames;
405 0 : for( ::std::vector< OUString >::iterator aIt = aItems.begin(), aEnd = aItems.end(); aIt != aEnd; ++aIt )
406 0 : aItemNames.push_back( PivotCacheGroupItem( *aIt ) );
407 : // create all nested group fields (if any)
408 0 : mrPivotTable.finalizeParentGroupingImport( xDPField, *pCacheField, aItemNames );
409 : }
410 0 : }
411 : }
412 0 : catch( Exception& )
413 : {
414 0 : }
415 0 : }
416 :
417 0 : void PivotTableField::finalizeDateGroupingImport( const Reference< XDataPilotField >& rxBaseDPField, sal_Int32 nBaseFieldIdx )
418 : {
419 0 : if( maDPFieldName.isEmpty() ) // prevent endless loops if file format is broken
420 : {
421 0 : if( const PivotCacheField* pCacheField = mrPivotTable.getCacheField( mnFieldIndex ) )
422 : {
423 0 : if( !pCacheField->isDatabaseField() && pCacheField->hasDateGrouping() && (pCacheField->getGroupBaseField() == nBaseFieldIdx) )
424 : {
425 0 : maDPFieldName = pCacheField->createDateGroupField( rxBaseDPField );
426 : OSL_ENSURE( !maDPFieldName.isEmpty(), "PivotTableField::finalizeDateGroupingImport - cannot create date group field" );
427 : }
428 : }
429 : }
430 0 : }
431 :
432 0 : void PivotTableField::finalizeParentGroupingImport( const Reference< XDataPilotField >& rxBaseDPField, const PivotCacheField& rBaseCacheField, PivotCacheGroupItemVector& orItemNames )
433 : {
434 0 : if( maDPFieldName.isEmpty() ) // prevent endless loops if file format is broken
435 : {
436 0 : if( const PivotCacheField* pCacheField = mrPivotTable.getCacheField( mnFieldIndex ) )
437 : {
438 : // data field can have user defined groupname captions, apply them
439 : // if they do
440 0 : IdCaptionPairList captionList;
441 0 : for( ItemModelVector::iterator aIt = maItems.begin(), aEnd = maItems.end(); aIt != aEnd; ++aIt )
442 : {
443 0 : if ( aIt->mnType == XML_data && aIt->msCaption.getLength() )
444 0 : captionList.push_back( IdCaptionPair( aIt->mnCacheItem, aIt->msCaption ) );
445 : }
446 : // #FIXME find another way out of this const nightmare prison
447 0 : if ( !captionList.empty() )
448 0 : const_cast<PivotCacheField*>( pCacheField )->applyItemCaptions( captionList );
449 0 : maDPFieldName = pCacheField->createParentGroupField( rxBaseDPField, rBaseCacheField, orItemNames );
450 : // on success, try to create nested group fields
451 0 : Reference< XDataPilotField > xDPField = mrPivotTable.getDataPilotField( maDPFieldName );
452 0 : if( xDPField.is() )
453 0 : mrPivotTable.finalizeParentGroupingImport( xDPField, *pCacheField, orItemNames );
454 : }
455 : }
456 0 : }
457 :
458 0 : void PivotTableField::convertRowField()
459 : {
460 0 : convertRowColPageField( XML_axisRow );
461 0 : }
462 :
463 0 : void PivotTableField::convertColField()
464 : {
465 0 : convertRowColPageField( XML_axisCol );
466 0 : }
467 :
468 0 : void PivotTableField::convertHiddenField()
469 : {
470 0 : convertRowColPageField( XML_TOKEN_INVALID );
471 0 : }
472 :
473 0 : void PivotTableField::convertPageField( const PTPageFieldModel& rPageField )
474 : {
475 : OSL_ENSURE( rPageField.mnField == mnFieldIndex, "PivotTableField::convertPageField - wrong field index" );
476 : // convert all settings common for row/column/page fields
477 0 : Reference< XDataPilotField > xDPField = convertRowColPageField( XML_axisPage );
478 :
479 0 : if( xDPField.is() )
480 : {
481 0 : PropertySet aPropSet( xDPField );
482 : using namespace ::com::sun::star::sheet;
483 :
484 : // find cache item used as 'selected page'
485 0 : sal_Int32 nCacheItem = -1;
486 0 : if( maModel.mbMultiPageItems )
487 : {
488 : // multiple items may be selected
489 : OSL_ENSURE( rPageField.mnItem == BIFF12_PTPAGEFIELD_MULTIITEMS, "PivotTableField::convertPageField - unexpected cache item index" );
490 : // try to find a single visible item
491 0 : bool bHasMultiItems = false;
492 0 : for( ItemModelVector::iterator aIt = maItems.begin(), aEnd = maItems.end(); (aIt != aEnd) && !bHasMultiItems; ++aIt )
493 : {
494 0 : if( (aIt->mnType == XML_data) && !aIt->mbHidden )
495 : {
496 0 : bHasMultiItems = nCacheItem >= 0;
497 0 : nCacheItem = bHasMultiItems ? -1 : aIt->mnCacheItem;
498 : }
499 : }
500 : }
501 : else
502 : {
503 : // single item may be selected
504 0 : if( (0 <= rPageField.mnItem) && (rPageField.mnItem < static_cast< sal_Int32 >( maItems.size() )) )
505 0 : nCacheItem = maItems[ rPageField.mnItem ].mnCacheItem;
506 : }
507 :
508 0 : if( nCacheItem >= 0 )
509 : {
510 0 : if( const PivotCacheField* pCacheField = mrPivotTable.getCacheField( mnFieldIndex ) )
511 : {
512 0 : if( const PivotCacheItem* pSharedItem = pCacheField->getCacheItem( nCacheItem ) )
513 : {
514 0 : OUString aSelectedPage = pSharedItem->getName();
515 0 : aPropSet.setProperty( PROP_SelectedPage, aSelectedPage );
516 : }
517 : }
518 0 : }
519 0 : }
520 0 : }
521 :
522 0 : void PivotTableField::convertDataField( const PTDataFieldModel& rDataField )
523 : {
524 : OSL_ENSURE( rDataField.mnField == mnFieldIndex, "PivotTableField::convertDataField - wrong field index" );
525 : OSL_ENSURE( maModel.mbDataField, "PivotTableField::convertDataField - not a data field" );
526 0 : Reference< XDataPilotField > xDPField = mrPivotTable.getDataPilotField( maDPFieldName );
527 0 : if( xDPField.is() )
528 : {
529 0 : PropertySet aPropSet( xDPField );
530 : using namespace ::com::sun::star::sheet;
531 :
532 : // field orientation
533 0 : aPropSet.setProperty( PROP_Orientation, DataPilotFieldOrientation_DATA );
534 :
535 : /* Field aggregation function. Documentation is a little bit confused
536 : about which names to use for the count functions. The name 'count'
537 : means 'count all', and 'countNum' means 'count numbers'. On the
538 : other hand, for subtotals, 'countA' means 'count all', and 'count'
539 : means 'count numbers' (see above). */
540 0 : GeneralFunction eAggFunc = GeneralFunction_SUM;
541 0 : switch( rDataField.mnSubtotal )
542 : {
543 0 : case XML_sum: eAggFunc = GeneralFunction_SUM; break;
544 0 : case XML_count: eAggFunc = GeneralFunction_COUNT; break;
545 0 : case XML_average: eAggFunc = GeneralFunction_AVERAGE; break;
546 0 : case XML_max: eAggFunc = GeneralFunction_MAX; break;
547 0 : case XML_min: eAggFunc = GeneralFunction_MIN; break;
548 0 : case XML_product: eAggFunc = GeneralFunction_PRODUCT; break;
549 0 : case XML_countNums: eAggFunc = GeneralFunction_COUNTNUMS; break;
550 0 : case XML_stdDev: eAggFunc = GeneralFunction_STDEV; break;
551 0 : case XML_stdDevp: eAggFunc = GeneralFunction_STDEVP; break;
552 0 : case XML_var: eAggFunc = GeneralFunction_VAR; break;
553 0 : case XML_varp: eAggFunc = GeneralFunction_VARP; break;
554 : default: OSL_FAIL( "PivotTableField::convertDataField - unknown aggregation function" );
555 : }
556 0 : aPropSet.setProperty( PROP_Function, eAggFunc );
557 :
558 : // field reference ('show data as')
559 0 : DataPilotFieldReference aReference;
560 0 : aReference.ReferenceType = DataPilotFieldReferenceType::NONE;
561 0 : switch( rDataField.mnShowDataAs )
562 : {
563 0 : case XML_difference: aReference.ReferenceType = DataPilotFieldReferenceType::ITEM_DIFFERENCE; break;
564 0 : case XML_percent: aReference.ReferenceType = DataPilotFieldReferenceType::ITEM_PERCENTAGE; break;
565 0 : case XML_percentDiff: aReference.ReferenceType = DataPilotFieldReferenceType::ITEM_PERCENTAGE_DIFFERENCE; break;
566 0 : case XML_runTotal: aReference.ReferenceType = DataPilotFieldReferenceType::RUNNING_TOTAL; break;
567 0 : case XML_percentOfRow: aReference.ReferenceType = DataPilotFieldReferenceType::ROW_PERCENTAGE; break;
568 0 : case XML_percentOfCol: aReference.ReferenceType = DataPilotFieldReferenceType::COLUMN_PERCENTAGE; break;
569 0 : case XML_percentOfTotal: aReference.ReferenceType = DataPilotFieldReferenceType::TOTAL_PERCENTAGE; break;
570 0 : case XML_index: aReference.ReferenceType = DataPilotFieldReferenceType::INDEX; break;
571 : }
572 0 : if( aReference.ReferenceType != DataPilotFieldReferenceType::NONE )
573 : {
574 0 : if( const PivotCacheField* pCacheField = mrPivotTable.getCacheField( rDataField.mnBaseField ) )
575 : {
576 0 : aReference.ReferenceField = pCacheField->getName();
577 0 : switch( rDataField.mnBaseItem )
578 : {
579 : case OOX_PT_PREVIOUS_ITEM:
580 0 : aReference.ReferenceItemType = DataPilotFieldReferenceItemType::PREVIOUS;
581 0 : break;
582 : case OOX_PT_NEXT_ITEM:
583 0 : aReference.ReferenceItemType = DataPilotFieldReferenceItemType::NEXT;
584 0 : break;
585 : default:
586 0 : aReference.ReferenceItemType = DataPilotFieldReferenceItemType::NAMED;
587 0 : if( const PivotCacheItem* pCacheItem = pCacheField->getCacheItem( rDataField.mnBaseItem ) )
588 0 : aReference.ReferenceItemName = pCacheItem->getName();
589 : }
590 0 : aPropSet.setProperty( PROP_Reference, aReference );
591 : }
592 0 : }
593 0 : }
594 0 : }
595 :
596 : // private --------------------------------------------------------------------
597 :
598 0 : Reference< XDataPilotField > PivotTableField::convertRowColPageField( sal_Int32 nAxis )
599 : {
600 0 : bool bDataLayout = mnFieldIndex == OOX_PT_DATALAYOUTFIELD;
601 0 : Reference< XDataPilotField > xDPField = bDataLayout ? mrPivotTable.getDataLayoutField() : mrPivotTable.getDataPilotField( maDPFieldName );
602 : OSL_ENSURE( bDataLayout || (nAxis == maModel.mnAxis), "PivotTableField::convertRowColPageField - field axis mismatch" );
603 :
604 0 : if( xDPField.is() )
605 : {
606 : // TODO: Use this to set properties directly, bypassing the slow uno layer.
607 0 : ScDPObject* pDPObj = mrPivotTable.getDPObject();
608 :
609 0 : PropertySet aPropSet( xDPField );
610 : using namespace ::com::sun::star::sheet;
611 :
612 : // field orientation
613 0 : DataPilotFieldOrientation eFieldOrient = DataPilotFieldOrientation_HIDDEN;
614 0 : switch( nAxis )
615 : {
616 0 : case XML_axisRow: eFieldOrient = DataPilotFieldOrientation_ROW; break;
617 0 : case XML_axisCol: eFieldOrient = DataPilotFieldOrientation_COLUMN; break;
618 0 : case XML_axisPage: eFieldOrient = DataPilotFieldOrientation_PAGE; break;
619 : }
620 0 : if( eFieldOrient != DataPilotFieldOrientation_HIDDEN )
621 0 : aPropSet.setProperty( PROP_Orientation, eFieldOrient );
622 :
623 : // all other settings not for the data layout field
624 0 : if( !bDataLayout )
625 : {
626 : /* Field subtotal functions. Ignore the 'defaultSubtotal' flag, if
627 : explicit functions are set. This is different behaviour between
628 : XML (where 'defaultSubtotal' is set regardless of other
629 : functions) and binary formats (where 'defaultSubtotal' is not
630 : set if other functions are set). */
631 0 : ::std::vector< GeneralFunction > aSubtotals;
632 : /* Order of subtotals is fixed in Excel. Documentation is a little
633 : bit confused about which names to use for the count functions.
634 : For subtotals, 'countA' means 'count all', and 'count' means
635 : 'count numbers'. On the other hand, for the data field
636 : aggregation function, 'count' means 'count all', and 'countNum'
637 : means 'count numbers' (see below). */
638 0 : if( maModel.mbSumSubtotal ) aSubtotals.push_back( GeneralFunction_SUM );
639 0 : if( maModel.mbCountASubtotal ) aSubtotals.push_back( GeneralFunction_COUNT );
640 0 : if( maModel.mbAverageSubtotal ) aSubtotals.push_back( GeneralFunction_AVERAGE );
641 0 : if( maModel.mbMaxSubtotal ) aSubtotals.push_back( GeneralFunction_MAX );
642 0 : if( maModel.mbMinSubtotal ) aSubtotals.push_back( GeneralFunction_MIN );
643 0 : if( maModel.mbProductSubtotal ) aSubtotals.push_back( GeneralFunction_PRODUCT );
644 0 : if( maModel.mbCountSubtotal ) aSubtotals.push_back( GeneralFunction_COUNTNUMS );
645 0 : if( maModel.mbStdDevSubtotal ) aSubtotals.push_back( GeneralFunction_STDEV );
646 0 : if( maModel.mbStdDevPSubtotal ) aSubtotals.push_back( GeneralFunction_STDEVP );
647 0 : if( maModel.mbVarSubtotal ) aSubtotals.push_back( GeneralFunction_VAR );
648 0 : if( maModel.mbVarPSubtotal ) aSubtotals.push_back( GeneralFunction_VARP );
649 : // if no function is set manually, check the 'defaultSubtotal' flag
650 0 : if( aSubtotals.empty() && maModel.mbDefaultSubtotal )
651 0 : aSubtotals.push_back( GeneralFunction_AUTO );
652 0 : aPropSet.setProperty( PROP_Subtotals, ContainerHelper::vectorToSequence( aSubtotals ) );
653 :
654 : // layout settings
655 0 : DataPilotFieldLayoutInfo aLayoutInfo;
656 : aLayoutInfo.LayoutMode = maModel.mbOutline ?
657 : (maModel.mbSubtotalTop ? DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_TOP : DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_BOTTOM) :
658 0 : DataPilotFieldLayoutMode::TABULAR_LAYOUT;
659 0 : aLayoutInfo.AddEmptyLines = maModel.mbInsertBlankRow;
660 0 : aPropSet.setProperty( PROP_LayoutInfo, aLayoutInfo );
661 0 : aPropSet.setProperty( PROP_ShowEmpty, maModel.mbShowAll );
662 :
663 : // auto show (OOXML/BIFF12 only)
664 0 : if( maModel.mbAutoShow )
665 : {
666 0 : DataPilotFieldAutoShowInfo aAutoShowInfo;
667 0 : aAutoShowInfo.IsEnabled = sal_True;
668 0 : aAutoShowInfo.ShowItemsMode = maModel.mbTopAutoShow ? DataPilotFieldShowItemsMode::FROM_TOP : DataPilotFieldShowItemsMode::FROM_BOTTOM;
669 0 : aAutoShowInfo.ItemCount = maModel.mnAutoShowItems;
670 0 : if( const PivotCacheField* pCacheField = mrPivotTable.getCacheFieldOfDataField( maModel.mnAutoShowRankBy ) )
671 0 : aAutoShowInfo.DataField = pCacheField->getName();
672 0 : aPropSet.setProperty( PROP_AutoShowInfo, aAutoShowInfo );
673 : }
674 :
675 : // auto sort
676 0 : DataPilotFieldSortInfo aSortInfo;
677 0 : aSortInfo.IsAscending = maModel.mnSortType == XML_ascending;
678 0 : if( (maModel.mnSortType != XML_ascending) && (maModel.mnSortType != XML_descending) )
679 : {
680 0 : aSortInfo.Mode = DataPilotFieldSortMode::MANUAL;
681 : }
682 : else
683 : {
684 0 : const PivotCacheField* pCacheField = (maModel.mnSortRefField == OOX_PT_DATALAYOUTFIELD) ?
685 0 : mrPivotTable.getCacheFieldOfDataField( maModel.mnSortRefItem ) : 0;
686 0 : if( pCacheField )
687 : {
688 0 : aSortInfo.Mode = DataPilotFieldSortMode::DATA;
689 0 : aSortInfo.Field = pCacheField->getName();
690 : }
691 : else
692 : {
693 0 : aSortInfo.Mode = DataPilotFieldSortMode::NAME;
694 : }
695 : }
696 0 : aPropSet.setProperty( PROP_SortInfo, aSortInfo );
697 :
698 : // item settings
699 0 : if (const PivotCacheField* pCacheField = mrPivotTable.getCacheField(mnFieldIndex))
700 : {
701 0 : ScDPSaveData* pSaveData = pDPObj->GetSaveData();
702 0 : ScDPSaveDimension* pDim = pSaveData->GetDimensionByName(pCacheField->getName());
703 :
704 : try
705 : {
706 0 : for( ItemModelVector::iterator aIt = maItems.begin(), aEnd = maItems.end(); aIt != aEnd; ++aIt )
707 : {
708 0 : if (aIt->mnType != XML_data)
709 0 : continue;
710 :
711 0 : const PivotCacheItem* pSharedItem = pCacheField->getCacheItem(aIt->mnCacheItem);
712 0 : if (!pSharedItem)
713 0 : continue;
714 :
715 : try
716 : {
717 0 : ScDPSaveMember* pMem = pDim->GetMemberByName(pSharedItem->getName());
718 0 : pMem->SetShowDetails(aIt->mbShowDetails);
719 0 : pMem->SetIsVisible(!aIt->mbHidden);
720 : }
721 0 : catch( Exception& )
722 : {
723 : // catch every failed container access to be able to process following items
724 : }
725 : }
726 : }
727 0 : catch (const Exception&) {}
728 0 : }
729 0 : }
730 : }
731 0 : return xDPField;
732 : }
733 :
734 0 : PTFilterModel::PTFilterModel() :
735 : mfValue( 0.0 ),
736 : mnField( -1 ),
737 : mnMemPropField( -1 ),
738 : mnType( XML_TOKEN_INVALID ),
739 : mnEvalOrder( 0 ),
740 : mnId( -1 ),
741 : mnMeasureField( -1 ),
742 : mnMeasureHier( -1 ),
743 0 : mbTopFilter( true )
744 : {
745 0 : }
746 :
747 0 : PivotTableFilter::PivotTableFilter( const PivotTable& rPivotTable ) :
748 : WorkbookHelper( rPivotTable ),
749 0 : mrPivotTable( rPivotTable )
750 : {
751 0 : }
752 :
753 0 : void PivotTableFilter::importFilter( const AttributeList& rAttribs )
754 : {
755 0 : maModel.maName = rAttribs.getXString( XML_name, OUString() );
756 0 : maModel.maDescription = rAttribs.getXString( XML_description, OUString() );
757 0 : maModel.maStrValue1 = rAttribs.getXString( XML_stringValue1, OUString() );
758 0 : maModel.maStrValue2 = rAttribs.getXString( XML_stringValue2, OUString() );
759 0 : maModel.mnField = rAttribs.getInteger( XML_fld, -1 );
760 0 : maModel.mnMemPropField = rAttribs.getInteger( XML_mpFld, -1 );
761 0 : maModel.mnType = rAttribs.getToken( XML_type, XML_TOKEN_INVALID );
762 0 : maModel.mnEvalOrder = rAttribs.getInteger( XML_evalOrder, 0 );
763 0 : maModel.mnId = rAttribs.getInteger( XML_id, -1 );
764 0 : maModel.mnMeasureField = rAttribs.getInteger( XML_iMeasureFld, -1 );
765 0 : maModel.mnMeasureHier = rAttribs.getInteger( XML_iMeasureHier, -1 );
766 0 : }
767 :
768 0 : void PivotTableFilter::importTop10( const AttributeList& rAttribs )
769 : {
770 : OSL_ENSURE( rAttribs.getBool( XML_percent, false ) == (maModel.mnType == XML_percent),
771 : "PivotTableFilter::importTop10 - unexpected value of percent attribute" );
772 0 : maModel.mfValue = rAttribs.getDouble( XML_val, 0.0 );
773 0 : maModel.mbTopFilter = rAttribs.getBool( XML_top, true );
774 0 : }
775 :
776 0 : void PivotTableFilter::importPTFilter( SequenceInputStream& rStrm )
777 : {
778 : sal_Int32 nType;
779 : sal_uInt16 nFlags;
780 0 : rStrm >> maModel.mnField >> maModel.mnMemPropField >> nType;
781 0 : rStrm.skip( 4 ); // unused
782 0 : rStrm >> maModel.mnId >> maModel.mnMeasureField >> maModel.mnMeasureHier >> nFlags;
783 0 : if( getFlag( nFlags, BIFF12_PTFILTER_HASNAME ) )
784 0 : rStrm >> maModel.maName;
785 0 : if( getFlag( nFlags, BIFF12_PTFILTER_HASDESCRIPTION ) )
786 0 : rStrm >> maModel.maDescription;
787 0 : if( getFlag( nFlags, BIFF12_PTFILTER_HASSTRVALUE1 ) )
788 0 : rStrm >> maModel.maStrValue1;
789 0 : if( getFlag( nFlags, BIFF12_PTFILTER_HASSTRVALUE2 ) )
790 0 : rStrm >> maModel.maStrValue2;
791 :
792 : static const sal_Int32 spnTypes[] =
793 : {
794 : XML_unknown,
795 : // data field top10 filter (1-3)
796 : XML_count, XML_percent, XML_sum,
797 : // caption filter (4-17)
798 : XML_captionEqual, XML_captionNotEqual,
799 : XML_captionBeginsWith, XML_captionNotBeginsWith, XML_captionEndsWith, XML_captionNotEndsWith,
800 : XML_captionContains, XML_captionNotContains, XML_captionGreaterThan, XML_captionGreaterThanOrEqual,
801 : XML_captionLessThan, XML_captionLessThanOrEqual, XML_captionBetween, XML_captionNotBetween,
802 : // value filter (18-25)
803 : XML_valueEqual, XML_valueNotEqual, XML_valueGreaterThan, XML_valueGreaterThanOrEqual,
804 : XML_valueLessThan, XML_valueLessThanOrEqual, XML_valueBetween, XML_valueNotBetween,
805 : // date filter (26-65)
806 : XML_dateEqual, XML_dateOlderThan, XML_dateNewerThan, XML_dateBetween,
807 : XML_tomorrow, XML_today, XML_yesterday, XML_nextWeek, XML_thisWeek, XML_lastWeek,
808 : XML_nextMonth, XML_thisMonth, XML_lastMonth, XML_nextQuarter, XML_thisQuarter, XML_lastQuarter,
809 : XML_nextYear, XML_thisYear, XML_lastYear, XML_yearToDate, XML_Q1, XML_Q2, XML_Q3, XML_Q4,
810 : XML_M1, XML_M2, XML_M3, XML_M4, XML_M5, XML_M6, XML_M7, XML_M8, XML_M9, XML_M10, XML_M11, XML_M12,
811 : XML_dateNotEqual, XML_dateOlderThanOrEqual, XML_dateNewerThanOrEqual, XML_dateNotBetween
812 : };
813 0 : maModel.mnType = STATIC_ARRAY_SELECT( spnTypes, nType, XML_TOKEN_INVALID );
814 0 : }
815 :
816 0 : void PivotTableFilter::importTop10Filter( SequenceInputStream& rStrm )
817 : {
818 : sal_uInt8 nFlags;
819 0 : rStrm >> nFlags >> maModel.mfValue;
820 :
821 : SAL_WARN_IF(
822 : getFlag(nFlags, BIFF12_TOP10FILTER_PERCENT) != (maModel.mnType == XML_percent),
823 : "sc.filter",
824 : "PivotTableFilter::importTop10 - unexpected value of percent attribute");
825 0 : maModel.mbTopFilter = getFlag( nFlags, BIFF12_TOP10FILTER_TOP );
826 0 : }
827 :
828 0 : void PivotTableFilter::finalizeImport()
829 : {
830 : // only simple top10 filter supported
831 0 : if( maModel.mnType == XML_count )
832 : {
833 0 : PropertySet aPropSet( mrPivotTable.getDataPilotField( maModel.mnField ) );
834 0 : if( aPropSet.is() )
835 : {
836 : using namespace ::com::sun::star::sheet;
837 0 : DataPilotFieldAutoShowInfo aAutoShowInfo;
838 0 : aAutoShowInfo.IsEnabled = sal_True;
839 0 : aAutoShowInfo.ShowItemsMode = maModel.mbTopFilter ? DataPilotFieldShowItemsMode::FROM_TOP : DataPilotFieldShowItemsMode::FROM_BOTTOM;
840 0 : aAutoShowInfo.ItemCount = getLimitedValue< sal_Int32, double >( maModel.mfValue, 0, SAL_MAX_INT32 );
841 0 : if( const PivotCacheField* pCacheField = mrPivotTable.getCacheFieldOfDataField( maModel.mnMeasureField ) )
842 0 : aAutoShowInfo.DataField = pCacheField->getName();
843 0 : aPropSet.setProperty( PROP_AutoShowInfo, aAutoShowInfo );
844 0 : }
845 : }
846 0 : }
847 :
848 0 : PTDefinitionModel::PTDefinitionModel() :
849 : mnCacheId( -1 ),
850 : mnDataPosition( 0 ),
851 : mnPageWrap( 0 ),
852 : mnIndent( 1 ),
853 : mnChartFormat( 0 ),
854 : mnRowFields( 0 ),
855 : mnColFields( 0 ),
856 : mbDataOnRows( false ),
857 : mbShowError( false ),
858 : mbShowMissing( true ),
859 : mbShowItems( true ),
860 : mbDisableFieldList( false ),
861 : mbShowCalcMembers( true ),
862 : mbVisualTotals( true ),
863 : mbShowDrill( true ),
864 : mbPrintDrill( false ),
865 : mbEnableDrill( true ),
866 : mbPreserveFormatting( true ),
867 : mbUseAutoFormat( false ),
868 : mbPageOverThenDown( false ),
869 : mbSubtotalHiddenItems( false ),
870 : mbRowGrandTotals( true ),
871 : mbColGrandTotals( true ),
872 : mbFieldPrintTitles( false ),
873 : mbItemPrintTitles( false ),
874 : mbMergeItem( false ),
875 : mbShowEmptyRow( false ),
876 : mbShowEmptyCol( false ),
877 : mbShowHeaders( true ),
878 : mbFieldListSortAsc( false ),
879 0 : mbCustomListSort( true )
880 : {
881 0 : }
882 :
883 0 : PTLocationModel::PTLocationModel() :
884 : mnFirstHeaderRow( 0 ),
885 : mnFirstDataRow( 0 ),
886 : mnFirstDataCol( 0 ),
887 : mnRowPageCount( 0 ),
888 0 : mnColPageCount( 0 )
889 : {
890 0 : }
891 :
892 0 : PivotTable::PivotTable( const WorkbookHelper& rHelper ) :
893 : WorkbookHelper( rHelper ),
894 : mpDPObject(NULL),
895 : maDataField( *this, OOX_PT_DATALAYOUTFIELD ),
896 0 : mpPivotCache( 0 )
897 : {
898 0 : }
899 :
900 0 : void PivotTable::importPivotTableDefinition( const AttributeList& rAttribs )
901 : {
902 0 : maDefModel.maName = rAttribs.getXString( XML_name, OUString() );
903 0 : maDefModel.maDataCaption = rAttribs.getXString( XML_dataCaption , OUString() );
904 0 : maDefModel.maGrandTotalCaption = rAttribs.getXString( XML_grandTotalCaption, OUString() );
905 0 : maDefModel.maRowHeaderCaption = rAttribs.getXString( XML_rowHeaderCaption, OUString() );
906 0 : maDefModel.maColHeaderCaption = rAttribs.getXString( XML_colHeaderCaption, OUString() );
907 0 : maDefModel.maErrorCaption = rAttribs.getXString( XML_errorCaption, OUString() );
908 0 : maDefModel.maMissingCaption = rAttribs.getXString( XML_missingCaption, OUString() );
909 0 : maDefModel.maPageStyle = rAttribs.getXString( XML_pageStyle, OUString() );
910 0 : maDefModel.maPivotTableStyle = rAttribs.getXString( XML_pivotTableStyle, OUString() );
911 0 : maDefModel.maVacatedStyle = rAttribs.getXString( XML_vacatedStyle, OUString() );
912 0 : maDefModel.maTag = rAttribs.getXString( XML_tag, OUString() );
913 0 : maDefModel.mnCacheId = rAttribs.getInteger( XML_cacheId, -1 );
914 0 : maDefModel.mnDataPosition = rAttribs.getInteger( XML_dataPosition, 0 );
915 0 : maDefModel.mnPageWrap = rAttribs.getInteger( XML_pageWrap, 0 );
916 0 : maDefModel.mnIndent = rAttribs.getInteger( XML_indent, 1 );
917 0 : maDefModel.mnChartFormat = rAttribs.getInteger( XML_chartFormat, 0 );
918 0 : maDefModel.mnAutoFormatId = rAttribs.getInteger( XML_autoFormatId, 0 );
919 0 : maDefModel.mbDataOnRows = rAttribs.getBool( XML_dataOnRows, false );
920 0 : maDefModel.mbShowError = rAttribs.getBool( XML_showError, false );
921 0 : maDefModel.mbShowMissing = rAttribs.getBool( XML_showMissing, true );
922 0 : maDefModel.mbShowItems = rAttribs.getBool( XML_showItems, true );
923 0 : maDefModel.mbDisableFieldList = rAttribs.getBool( XML_disableFieldList, false );
924 0 : maDefModel.mbShowCalcMembers = rAttribs.getBool( XML_showCalcMbrs, true );
925 0 : maDefModel.mbVisualTotals = rAttribs.getBool( XML_visualTotals, true );
926 0 : maDefModel.mbShowDrill = rAttribs.getBool( XML_showDrill, true );
927 0 : maDefModel.mbPrintDrill = rAttribs.getBool( XML_printDrill, false );
928 0 : maDefModel.mbEnableDrill = rAttribs.getBool( XML_enableDrill, true );
929 0 : maDefModel.mbPreserveFormatting = rAttribs.getBool( XML_preserveFormatting, true );
930 0 : maDefModel.mbUseAutoFormat = rAttribs.getBool( XML_useAutoFormatting, false );
931 0 : maDefModel.mbPageOverThenDown = rAttribs.getBool( XML_pageOverThenDown, false );
932 0 : maDefModel.mbSubtotalHiddenItems = rAttribs.getBool( XML_subtotalHiddenItems, false );
933 0 : maDefModel.mbRowGrandTotals = rAttribs.getBool( XML_rowGrandTotals, true );
934 0 : maDefModel.mbColGrandTotals = rAttribs.getBool( XML_colGrandTotals, true );
935 0 : maDefModel.mbFieldPrintTitles = rAttribs.getBool( XML_fieldPrintTitles, false );
936 0 : maDefModel.mbItemPrintTitles = rAttribs.getBool( XML_itemPrintTitles, false );
937 0 : maDefModel.mbMergeItem = rAttribs.getBool( XML_mergeItem, false );
938 0 : maDefModel.mbShowEmptyRow = rAttribs.getBool( XML_showEmptyRow, false );
939 0 : maDefModel.mbShowEmptyCol = rAttribs.getBool( XML_showEmptyCol, false );
940 0 : maDefModel.mbShowHeaders = rAttribs.getBool( XML_showHeaders, true );
941 0 : maDefModel.mbFieldListSortAsc = rAttribs.getBool( XML_fieldListSortAscending, false );
942 0 : maDefModel.mbCustomListSort = rAttribs.getBool( XML_customListSort, true );
943 0 : maDefModel.mbApplyNumFmt = rAttribs.getBool( XML_applyNumberFormats, false );
944 0 : maDefModel.mbApplyFont = rAttribs.getBool( XML_applyFontFormats, false );
945 0 : maDefModel.mbApplyAlignment = rAttribs.getBool( XML_applyAlignmentFormats, false );
946 0 : maDefModel.mbApplyBorder = rAttribs.getBool( XML_applyBorderFormats, false );
947 0 : maDefModel.mbApplyFill = rAttribs.getBool( XML_applyPatternFormats, false );
948 : // OOXML and BIFF12 documentation differ: OOXML mentions width/height, BIFF12 mentions protection
949 0 : maDefModel.mbApplyProtection = rAttribs.getBool( XML_applyWidthHeightFormats, false );
950 0 : }
951 :
952 0 : void PivotTable::importLocation( const AttributeList& rAttribs, sal_Int16 nSheet )
953 : {
954 0 : getAddressConverter().convertToCellRangeUnchecked( maLocationModel.maRange, rAttribs.getString( XML_ref, OUString() ), nSheet );
955 0 : maLocationModel.mnFirstHeaderRow = rAttribs.getInteger( XML_firstHeaderRow, 0 );
956 0 : maLocationModel.mnFirstDataRow = rAttribs.getInteger( XML_firstDataRow, 0 );
957 0 : maLocationModel.mnFirstDataCol = rAttribs.getInteger( XML_firstDataCol, 0 );
958 0 : maLocationModel.mnRowPageCount = rAttribs.getInteger( XML_rowPageCount, 0 );
959 0 : maLocationModel.mnColPageCount = rAttribs.getInteger( XML_colPageCount, 0 );
960 0 : }
961 :
962 0 : void PivotTable::importRowField( const AttributeList& rAttribs )
963 : {
964 0 : importField( maRowFields, rAttribs );
965 0 : }
966 :
967 0 : void PivotTable::importColField( const AttributeList& rAttribs )
968 : {
969 0 : importField( maColFields, rAttribs );
970 0 : }
971 :
972 0 : void PivotTable::importPageField( const AttributeList& rAttribs )
973 : {
974 0 : PTPageFieldModel aModel;
975 0 : aModel.maName = rAttribs.getXString( XML_name, OUString() );
976 0 : aModel.mnField = rAttribs.getInteger( XML_fld, -1 );
977 : // specification is wrong, XML_item is not the cache item, but the field item
978 0 : aModel.mnItem = rAttribs.getInteger( XML_item, BIFF12_PTPAGEFIELD_MULTIITEMS );
979 0 : maPageFields.push_back( aModel );
980 0 : }
981 :
982 0 : void PivotTable::importDataField( const AttributeList& rAttribs )
983 : {
984 0 : PTDataFieldModel aModel;
985 0 : aModel.maName = rAttribs.getXString( XML_name, OUString() );
986 0 : aModel.mnField = rAttribs.getInteger( XML_fld, -1 );
987 0 : aModel.mnSubtotal = rAttribs.getToken( XML_subtotal, XML_sum );
988 0 : aModel.mnShowDataAs = rAttribs.getToken( XML_showDataAs, XML_normal );
989 0 : aModel.mnBaseField = rAttribs.getInteger( XML_baseField, -1 );
990 0 : aModel.mnBaseItem = rAttribs.getInteger( XML_baseItem, -1 );
991 0 : aModel.mnNumFmtId = rAttribs.getInteger( XML_numFmtId, 0 );
992 0 : maDataFields.push_back( aModel );
993 0 : }
994 :
995 0 : void PivotTable::importPTDefinition( SequenceInputStream& rStrm )
996 : {
997 : sal_uInt32 nFlags1, nFlags2, nFlags3;
998 : sal_uInt8 nDataAxis;
999 0 : rStrm >> nFlags1 >> nFlags2 >> nFlags3 >> nDataAxis;
1000 0 : maDefModel.mnPageWrap = rStrm.readuInt8();
1001 0 : rStrm.skip( 2 ); // refresh versions
1002 0 : rStrm >> maDefModel.mnDataPosition;
1003 0 : maDefModel.mnAutoFormatId = rStrm.readuInt16();
1004 0 : rStrm.skip( 2 ); // unused
1005 0 : rStrm >> maDefModel.mnChartFormat >> maDefModel.mnCacheId >> maDefModel.maName;
1006 0 : if( getFlag( nFlags2, BIFF12_PTDEF_HASDATACAPTION ) )
1007 0 : rStrm >> maDefModel.maDataCaption;
1008 0 : if( getFlag( nFlags2, BIFF12_PTDEF_HASGRANDTOTALCAPTION ) )
1009 0 : rStrm >> maDefModel.maGrandTotalCaption;
1010 0 : if( !getFlag( nFlags3, BIFF12_PTDEF_NOERRORCAPTION ) ) // missing flag indicates existing string
1011 0 : rStrm >> maDefModel.maErrorCaption;
1012 0 : if( !getFlag( nFlags3, BIFF12_PTDEF_NOMISSINGCAPTION ) ) // missing flag indicates existing string
1013 0 : rStrm >> maDefModel.maMissingCaption;
1014 0 : if( getFlag( nFlags2, BIFF12_PTDEF_HASPAGESTYLE ) )
1015 0 : rStrm >> maDefModel.maPageStyle;
1016 0 : if( getFlag( nFlags2, BIFF12_PTDEF_HASPIVOTTABLESTYLE ) )
1017 0 : rStrm >> maDefModel.maPivotTableStyle;
1018 0 : if( getFlag( nFlags2, BIFF12_PTDEF_HASVACATEDSTYLE ) )
1019 0 : rStrm >> maDefModel.maVacatedStyle;
1020 0 : if( getFlag( nFlags2, BIFF12_PTDEF_HASTAG ) )
1021 0 : rStrm >> maDefModel.maTag;
1022 0 : if( getFlag( nFlags3, BIFF12_PTDEF_HASCOLHEADERCAPTION ) ) // TODO: right order (col/row)? spec is unclear
1023 0 : rStrm >> maDefModel.maColHeaderCaption;
1024 0 : if( getFlag( nFlags3, BIFF12_PTDEF_HASROWHEADERCAPTION ) )
1025 0 : rStrm >> maDefModel.maRowHeaderCaption;
1026 :
1027 : SAL_WARN_IF(
1028 : (nDataAxis != BIFF12_PTDEF_ROWAXIS) && (nDataAxis != BIFF12_PTDEF_COLAXIS),
1029 : "sc.filter",
1030 : "PivotTable::importPTDefinition - unexpected axis position for data field");
1031 :
1032 0 : maDefModel.mnIndent = extractValue< sal_uInt8 >( nFlags1, 24, 7 );
1033 0 : maDefModel.mbDataOnRows = nDataAxis == BIFF12_PTDEF_ROWAXIS;
1034 0 : maDefModel.mbShowError = getFlag( nFlags2, BIFF12_PTDEF_SHOWERROR );
1035 0 : maDefModel.mbShowMissing = getFlag( nFlags2, BIFF12_PTDEF_SHOWMISSING );
1036 0 : maDefModel.mbShowItems = getFlag( nFlags1, BIFF12_PTDEF_SHOWITEMS );
1037 0 : maDefModel.mbDisableFieldList = getFlag( nFlags1, BIFF12_PTDEF_DISABLEFIELDLIST );
1038 0 : maDefModel.mbShowCalcMembers = !getFlag( nFlags1, BIFF12_PTDEF_HIDECALCMEMBERS );
1039 0 : maDefModel.mbVisualTotals = !getFlag( nFlags1, BIFF12_PTDEF_WITHHIDDENTOTALS );
1040 0 : maDefModel.mbShowDrill = !getFlag( nFlags1, BIFF12_PTDEF_HIDEDRILL );
1041 0 : maDefModel.mbPrintDrill = getFlag( nFlags1, BIFF12_PTDEF_PRINTDRILL );
1042 0 : maDefModel.mbEnableDrill = getFlag( nFlags2, BIFF12_PTDEF_ENABLEDRILL );
1043 0 : maDefModel.mbPreserveFormatting = getFlag( nFlags2, BIFF12_PTDEF_PRESERVEFORMATTING );
1044 0 : maDefModel.mbUseAutoFormat = getFlag( nFlags2, BIFF12_PTDEF_USEAUTOFORMAT );
1045 0 : maDefModel.mbPageOverThenDown = getFlag( nFlags2, BIFF12_PTDEF_PAGEOVERTHENDOWN );
1046 0 : maDefModel.mbSubtotalHiddenItems = getFlag( nFlags2, BIFF12_PTDEF_SUBTOTALHIDDENITEMS );
1047 0 : maDefModel.mbRowGrandTotals = getFlag( nFlags2, BIFF12_PTDEF_ROWGRANDTOTALS );
1048 0 : maDefModel.mbColGrandTotals = getFlag( nFlags2, BIFF12_PTDEF_COLGRANDTOTALS );
1049 0 : maDefModel.mbFieldPrintTitles = getFlag( nFlags2, BIFF12_PTDEF_FIELDPRINTTITLES );
1050 0 : maDefModel.mbItemPrintTitles = getFlag( nFlags2, BIFF12_PTDEF_ITEMPRINTTITLES );
1051 0 : maDefModel.mbMergeItem = getFlag( nFlags2, BIFF12_PTDEF_MERGEITEM );
1052 0 : maDefModel.mbApplyNumFmt = getFlag( nFlags2, BIFF12_PTDEF_APPLYNUMFMT );
1053 0 : maDefModel.mbApplyFont = getFlag( nFlags2, BIFF12_PTDEF_APPLYFONT );
1054 0 : maDefModel.mbApplyAlignment = getFlag( nFlags2, BIFF12_PTDEF_APPLYALIGNMENT );
1055 0 : maDefModel.mbApplyBorder = getFlag( nFlags2, BIFF12_PTDEF_APPLYBORDER );
1056 0 : maDefModel.mbApplyFill = getFlag( nFlags2, BIFF12_PTDEF_APPLYFILL );
1057 0 : maDefModel.mbApplyProtection = getFlag( nFlags2, BIFF12_PTDEF_APPLYPROTECTION );
1058 0 : maDefModel.mbShowEmptyRow = getFlag( nFlags2, BIFF12_PTDEF_SHOWEMPTYROW );
1059 0 : maDefModel.mbShowEmptyCol = getFlag( nFlags2, BIFF12_PTDEF_SHOWEMPTYCOL );
1060 0 : maDefModel.mbShowHeaders = !getFlag( nFlags1, BIFF12_PTDEF_HIDEHEADERS );
1061 0 : maDefModel.mbFieldListSortAsc = getFlag( nFlags3, BIFF12_PTDEF_FIELDLISTSORTASC );
1062 0 : maDefModel.mbCustomListSort = !getFlag( nFlags3, BIFF12_PTDEF_NOCUSTOMLISTSORT );
1063 0 : }
1064 :
1065 0 : void PivotTable::importPTLocation( SequenceInputStream& rStrm, sal_Int16 nSheet )
1066 : {
1067 0 : BinRange aBinRange;
1068 0 : rStrm >> aBinRange >> maLocationModel.mnFirstHeaderRow
1069 0 : >> maLocationModel.mnFirstDataRow >> maLocationModel.mnFirstDataCol
1070 0 : >> maLocationModel.mnRowPageCount >> maLocationModel.mnColPageCount;
1071 0 : getAddressConverter().convertToCellRangeUnchecked( maLocationModel.maRange, aBinRange, nSheet );
1072 0 : }
1073 :
1074 0 : void PivotTable::importPTRowFields( SequenceInputStream& rStrm )
1075 : {
1076 0 : importFields( maRowFields, rStrm );
1077 0 : }
1078 :
1079 0 : void PivotTable::importPTColFields( SequenceInputStream& rStrm )
1080 : {
1081 0 : importFields( maColFields, rStrm );
1082 0 : }
1083 :
1084 0 : void PivotTable::importPTPageField( SequenceInputStream& rStrm )
1085 : {
1086 0 : PTPageFieldModel aModel;
1087 : sal_uInt8 nFlags;
1088 0 : rStrm >> aModel.mnField >> aModel.mnItem;
1089 0 : rStrm.skip( 4 ); // hierarchy
1090 0 : rStrm >> nFlags;
1091 0 : if( getFlag( nFlags, BIFF12_PTPAGEFIELD_HASNAME ) )
1092 0 : rStrm >> aModel.maName;
1093 0 : maPageFields.push_back( aModel );
1094 0 : }
1095 :
1096 0 : void PivotTable::importPTDataField( SequenceInputStream& rStrm )
1097 : {
1098 0 : PTDataFieldModel aModel;
1099 : sal_Int32 nSubtotal, nShowDataAs;
1100 : sal_uInt8 nHasName;
1101 0 : rStrm >> aModel.mnField >> nSubtotal >> nShowDataAs >> aModel.mnBaseField >> aModel.mnBaseItem >> aModel.mnNumFmtId >> nHasName;
1102 0 : if( nHasName == 1 )
1103 0 : rStrm >> aModel.maName;
1104 0 : aModel.setBiffSubtotal( nSubtotal );
1105 0 : aModel.setBiffShowDataAs( nShowDataAs );
1106 0 : maDataFields.push_back( aModel );
1107 0 : }
1108 :
1109 0 : PivotTableField& PivotTable::createTableField()
1110 : {
1111 0 : sal_Int32 nFieldIndex = static_cast< sal_Int32 >( maFields.size() );
1112 0 : PivotTableFieldVector::value_type xTableField( new PivotTableField( *this, nFieldIndex ) );
1113 0 : maFields.push_back( xTableField );
1114 0 : return *xTableField;
1115 : }
1116 :
1117 0 : PivotTableFilter& PivotTable::createTableFilter()
1118 : {
1119 0 : PivotTableFilterVector::value_type xTableFilter( new PivotTableFilter( *this ) );
1120 0 : maFilters.push_back( xTableFilter );
1121 0 : return *xTableFilter;
1122 : }
1123 :
1124 0 : void PivotTable::finalizeImport()
1125 : {
1126 0 : if( getAddressConverter().validateCellRange( maLocationModel.maRange, true, true ) )
1127 : {
1128 0 : mpPivotCache = getPivotCaches().importPivotCacheFragment( maDefModel.mnCacheId );
1129 0 : if( mpPivotCache && mpPivotCache->isValidDataSource() && !maDefModel.maName.isEmpty() )
1130 : {
1131 : // clear destination area of the original pivot table
1132 : try
1133 : {
1134 0 : Reference< XSheetOperation > xSheetOp( getCellRangeFromDoc( maLocationModel.maRange ), UNO_QUERY_THROW );
1135 : using namespace ::com::sun::star::sheet::CellFlags;
1136 0 : xSheetOp->clearContents( VALUE | DATETIME | STRING | FORMULA | HARDATTR | STYLES | EDITATTR | FORMATTED );
1137 : }
1138 0 : catch( Exception& )
1139 : {
1140 : }
1141 :
1142 : try
1143 : {
1144 : // create a new data pilot descriptor based on the source data
1145 0 : Reference< XDataPilotTablesSupplier > xDPTablesSupp( getSheetFromDoc( maLocationModel.maRange.Sheet ), UNO_QUERY_THROW );
1146 0 : Reference< XDataPilotTables > xDPTables( xDPTablesSupp->getDataPilotTables(), UNO_SET_THROW );
1147 0 : mxDPDescriptor.set( xDPTables->createDataPilotDescriptor(), UNO_SET_THROW );
1148 0 : mxDPDescriptor->setSourceRange( mpPivotCache->getSourceRange() );
1149 0 : mxDPDescriptor->setTag( maDefModel.maTag );
1150 :
1151 : // TODO: This is a hack. Eventually we need to convert the whole thing to the internal API.
1152 0 : ScDataPilotDescriptorBase* pImpl = ScDataPilotDescriptorBase::getImplementation(mxDPDescriptor);
1153 0 : if (!pImpl)
1154 0 : return;
1155 :
1156 0 : mpDPObject = pImpl->GetDPObject();
1157 0 : if (!mpDPObject)
1158 0 : return;
1159 :
1160 : // global data pilot properties
1161 0 : PropertySet aDescProp( mxDPDescriptor );
1162 0 : aDescProp.setProperty( PROP_ColumnGrand, maDefModel.mbColGrandTotals );
1163 0 : aDescProp.setProperty( PROP_RowGrand, maDefModel.mbRowGrandTotals );
1164 0 : aDescProp.setProperty( PROP_ShowFilterButton, false );
1165 0 : aDescProp.setProperty( PROP_DrillDownOnDoubleClick, maDefModel.mbEnableDrill );
1166 :
1167 : // finalize all fields, this finds field names and creates grouping fields
1168 0 : maFields.forEachMem( &PivotTableField::finalizeImport, ::boost::cref( mxDPDescriptor ) );
1169 :
1170 : // all row fields
1171 0 : for( IndexVector::iterator aIt = maRowFields.begin(), aEnd = maRowFields.end(); aIt != aEnd; ++aIt )
1172 0 : if( PivotTableField* pField = getTableField( *aIt ) )
1173 0 : pField->convertRowField();
1174 :
1175 : // all column fields
1176 0 : for( IndexVector::iterator aIt = maColFields.begin(), aEnd = maColFields.end(); aIt != aEnd; ++aIt )
1177 0 : if( PivotTableField* pField = getTableField( *aIt ) )
1178 0 : pField->convertColField();
1179 :
1180 : // all page fields
1181 0 : for( PageFieldVector::iterator aIt = maPageFields.begin(), aEnd = maPageFields.end(); aIt != aEnd; ++aIt )
1182 0 : if( PivotTableField* pField = getTableField( aIt->mnField ) )
1183 0 : pField->convertPageField( *aIt );
1184 :
1185 : // all hidden fields
1186 0 : ::std::set< sal_Int32 > aVisFields;
1187 0 : aVisFields.insert( maRowFields.begin(), maRowFields.end() );
1188 0 : aVisFields.insert( maColFields.begin(), maColFields.end() );
1189 0 : for( PageFieldVector::iterator aIt = maPageFields.begin(), aEnd = maPageFields.end(); aIt != aEnd; ++aIt )
1190 0 : aVisFields.insert( aIt->mnField );
1191 0 : for( PivotTableFieldVector::iterator aBeg = maFields.begin(), aIt = aBeg, aEnd = maFields.end(); aIt != aEnd; ++aIt )
1192 0 : if( aVisFields.count( static_cast< sal_Int32 >( aIt - aBeg ) ) == 0 )
1193 0 : (*aIt)->convertHiddenField();
1194 :
1195 : // all data fields
1196 0 : for( DataFieldVector::iterator aIt = maDataFields.begin(), aEnd = maDataFields.end(); aIt != aEnd; ++aIt )
1197 : {
1198 0 : if( const PivotCacheField* pCacheField = getCacheField( aIt->mnField ) )
1199 : {
1200 0 : if ( pCacheField-> getGroupBaseField() != -1 )
1201 0 : aIt->mnField = pCacheField-> getGroupBaseField();
1202 : }
1203 0 : if( PivotTableField* pField = getTableField( aIt->mnField ) )
1204 0 : pField->convertDataField( *aIt );
1205 : }
1206 :
1207 : // filters
1208 0 : maFilters.forEachMem( &PivotTableFilter::finalizeImport );
1209 :
1210 : // calculate base position of table
1211 0 : CellAddress aPos( maLocationModel.maRange.Sheet, maLocationModel.maRange.StartColumn, maLocationModel.maRange.StartRow );
1212 : /* If page fields exist, include them into the destination
1213 : area (they are excluded in Excel). Add an extra blank row. */
1214 0 : if( !maPageFields.empty() )
1215 0 : aPos.Row = ::std::max< sal_Int32 >( static_cast< sal_Int32 >( aPos.Row - maPageFields.size() - 1 ), 0 );
1216 :
1217 : // insert the DataPilot table into the sheet
1218 0 : xDPTables->insertNewByName( maDefModel.maName, aPos, mxDPDescriptor );
1219 : }
1220 0 : catch( Exception& )
1221 : {
1222 : OSL_FAIL( "PivotTable::finalizeImport - exception while creating the DataPilot table" );
1223 : }
1224 : }
1225 : }
1226 : }
1227 :
1228 0 : void PivotTable::finalizeDateGroupingImport( const Reference< XDataPilotField >& rxBaseDPField, sal_Int32 nBaseFieldIdx )
1229 : {
1230 : // process all fields, there is no chaining information in the cache fields
1231 0 : maFields.forEachMem( &PivotTableField::finalizeDateGroupingImport, ::boost::cref( rxBaseDPField ), nBaseFieldIdx );
1232 0 : }
1233 :
1234 0 : void PivotTable::finalizeParentGroupingImport( const Reference< XDataPilotField >& rxBaseDPField,
1235 : const PivotCacheField& rBaseCacheField, PivotCacheGroupItemVector& orItemNames )
1236 : {
1237 : // try to create parent group fields that group the items of the passed base field
1238 0 : if( PivotTableField* pParentTableField = maFields.get( rBaseCacheField.getParentGroupField() ).get() )
1239 0 : pParentTableField->finalizeParentGroupingImport( rxBaseDPField, rBaseCacheField, orItemNames );
1240 0 : }
1241 :
1242 0 : Reference< XDataPilotField > PivotTable::getDataPilotField( const OUString& rFieldName ) const
1243 : {
1244 0 : Reference< XDataPilotField > xDPField;
1245 0 : if( !rFieldName.isEmpty() && mxDPDescriptor.is() ) try
1246 : {
1247 0 : Reference< XNameAccess > xDPFieldsNA( mxDPDescriptor->getDataPilotFields(), UNO_QUERY_THROW );
1248 0 : xDPField.set( xDPFieldsNA->getByName( rFieldName ), UNO_QUERY );
1249 : }
1250 0 : catch( Exception& )
1251 : {
1252 : }
1253 0 : return xDPField;
1254 : }
1255 :
1256 0 : Reference< XDataPilotField > PivotTable::getDataPilotField( sal_Int32 nFieldIdx ) const
1257 : {
1258 0 : Reference< XDataPilotField > xDPField;
1259 0 : if( const PivotTableField* pTableField = maFields.get( nFieldIdx ).get() )
1260 0 : xDPField = getDataPilotField( pTableField->getDPFieldName() );
1261 0 : return xDPField;
1262 : }
1263 :
1264 0 : Reference< XDataPilotField > PivotTable::getDataLayoutField() const
1265 : {
1266 0 : Reference< XDataPilotField > xDPField;
1267 : try
1268 : {
1269 0 : Reference< XDataPilotDataLayoutFieldSupplier > xDPDataFieldSupp( mxDPDescriptor, UNO_QUERY_THROW );
1270 0 : xDPField = xDPDataFieldSupp->getDataLayoutField();
1271 : }
1272 0 : catch( Exception& )
1273 : {
1274 : }
1275 0 : return xDPField;
1276 : }
1277 :
1278 0 : const PivotCacheField* PivotTable::getCacheField( sal_Int32 nFieldIdx ) const
1279 : {
1280 0 : return mpPivotCache ? mpPivotCache->getCacheField( nFieldIdx ) : 0;
1281 : }
1282 :
1283 0 : const PivotCacheField* PivotTable::getCacheFieldOfDataField( sal_Int32 nDataItemIdx ) const
1284 : {
1285 0 : const PTDataFieldModel* pDataField = ContainerHelper::getVectorElement( maDataFields, nDataItemIdx );
1286 0 : return pDataField ? getCacheField( pDataField->mnField ) : 0;
1287 : }
1288 :
1289 0 : sal_Int32 PivotTable::getCacheDatabaseIndex( sal_Int32 nFieldIdx ) const
1290 : {
1291 0 : return mpPivotCache ? mpPivotCache->getCacheDatabaseIndex( nFieldIdx ) : -1;
1292 : }
1293 :
1294 0 : ScDPObject* PivotTable::getDPObject()
1295 : {
1296 0 : return mpDPObject;
1297 : }
1298 :
1299 : // private --------------------------------------------------------------------
1300 :
1301 0 : PivotTableField* PivotTable::getTableField( sal_Int32 nFieldIdx )
1302 : {
1303 0 : return (nFieldIdx == OOX_PT_DATALAYOUTFIELD) ? &maDataField : maFields.get( nFieldIdx ).get();
1304 : }
1305 :
1306 0 : void PivotTable::importField( IndexVector& orFields, const AttributeList& rAttribs )
1307 : {
1308 0 : orFields.push_back( rAttribs.getInteger( XML_x, -1 ) );
1309 0 : }
1310 :
1311 0 : void PivotTable::importFields( IndexVector& orFields, SequenceInputStream& rStrm )
1312 : {
1313 : OSL_ENSURE( orFields.empty(), "PivotTable::importFields - multiple record instances" );
1314 0 : orFields.clear();
1315 0 : sal_Int32 nCount = rStrm.readInt32();
1316 : OSL_ENSURE( 4 * nCount == rStrm.getRemaining(), "PivotTable::importFields - invalid field count" );
1317 0 : nCount = static_cast< sal_Int32 >( rStrm.getRemaining() / 4 );
1318 0 : for( sal_Int32 nIdx = 0; nIdx < nCount; ++nIdx )
1319 0 : orFields.push_back( rStrm.readInt32() );
1320 0 : }
1321 :
1322 44 : PivotTableBuffer::PivotTableBuffer( const WorkbookHelper& rHelper ) :
1323 44 : WorkbookHelper( rHelper )
1324 : {
1325 44 : }
1326 :
1327 0 : PivotTable& PivotTableBuffer::createPivotTable()
1328 : {
1329 0 : PivotTableVector::value_type xTable( new PivotTable( *this ) );
1330 0 : maTables.push_back( xTable );
1331 0 : return *xTable;
1332 : }
1333 :
1334 44 : void PivotTableBuffer::finalizeImport()
1335 : {
1336 44 : maTables.forEachMem( &PivotTable::finalizeImport );
1337 44 : }
1338 :
1339 : } // namespace xls
1340 18 : } // namespace oox
1341 :
1342 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|