LibreOffice Module sc (master) 1
pivotcachefragment.cxx
Go to the documentation of this file.
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
21
22#include <osl/diagnose.h>
23#include <oox/token/namespaces.hxx>
24#include <biffhelper.hxx>
25#include <formulabuffer.hxx>
26#include <pivotcachebuffer.hxx>
27#include <worksheetbuffer.hxx>
28
29namespace oox::xls {
30
31using namespace ::com::sun::star::uno;
32using namespace ::oox::core;
33
35 WorkbookContextBase( rFragment ),
36 mrCacheField( rCacheField )
37{
38}
39
41{
42 switch( getCurrentElement() )
43 {
44 case XLS_TOKEN( cacheField ):
45 if( nElement == XLS_TOKEN( sharedItems ) ) { mrCacheField.importSharedItems( rAttribs ); return this; }
46 if( nElement == XLS_TOKEN( fieldGroup ) ) { mrCacheField.importFieldGroup( rAttribs ); return this; }
47 break;
48
49 case XLS_TOKEN( fieldGroup ):
50 switch( nElement )
51 {
52 case XLS_TOKEN( rangePr ): mrCacheField.importRangePr( rAttribs ); break;
53 case XLS_TOKEN( discretePr ): return this;
54 case XLS_TOKEN( groupItems ): return this;
55 }
56 break;
57
58 case XLS_TOKEN( sharedItems ): mrCacheField.importSharedItem( nElement, rAttribs ); break;
59 case XLS_TOKEN( discretePr ): mrCacheField.importDiscretePrItem( nElement, rAttribs ); break;
60 case XLS_TOKEN( groupItems ): mrCacheField.importGroupItem( nElement, rAttribs ); break;
61 }
62 return nullptr;
63}
64
66{
67 if( isRootElement() )
69}
70
72{
73 switch( getCurrentElement() )
74 {
76 switch( nRecId )
77 {
80 }
81 break;
82
84 switch( nRecId )
85 {
87 case BIFF12_ID_PCDFDISCRETEPR: return this;
88 case BIFF12_ID_PCDFGROUPITEMS: return this;
89 }
90 break;
91
95 }
96 return nullptr;
97}
98
100{
101 if( isRootElement() )
103}
104
106 const WorkbookHelper& rHelper, const OUString& rFragmentPath, PivotCache& rPivotCache ) :
107 WorkbookFragmentBase( rHelper, rFragmentPath ),
108 mrPivotCache( rPivotCache )
109{
110}
111
113{
114 switch( getCurrentElement() )
115 {
116 case XML_ROOT_CONTEXT:
117 if( nElement == XLS_TOKEN( pivotCacheDefinition ) ) { mrPivotCache.importPivotCacheDefinition( rAttribs ); return this; }
118 break;
119
120 case XLS_TOKEN( pivotCacheDefinition ):
121 switch( nElement )
122 {
123 case XLS_TOKEN( cacheSource ): mrPivotCache.importCacheSource( rAttribs ); return this;
124 case XLS_TOKEN( cacheFields ): return this;
125 }
126 break;
127
128 case XLS_TOKEN( cacheSource ):
129 if( nElement == XLS_TOKEN( worksheetSource ) ) mrPivotCache.importWorksheetSource( rAttribs, getRelations() );
130 break;
131
132 case XLS_TOKEN( cacheFields ):
133 if( nElement == XLS_TOKEN( cacheField ) ) return new PivotCacheFieldContext( *this, mrPivotCache.createCacheField() );
134 break;
135 }
136 return nullptr;
137}
138
140{
141 switch( getCurrentElement() )
142 {
143 case XML_ROOT_CONTEXT:
144 if( nRecId == BIFF12_ID_PCDEFINITION ) { mrPivotCache.importPCDefinition( rStrm ); return this; }
145 break;
146
148 switch( nRecId )
149 {
151 case BIFF12_ID_PCDFIELDS: return this;
152 }
153 break;
154
156 if( nRecId == BIFF12_ID_PCDSHEETSOURCE ) mrPivotCache.importPCDSheetSource( rStrm, getRelations() );
157 break;
158
160 if( nRecId == BIFF12_ID_PCDFIELD ) return new PivotCacheFieldContext( *this, mrPivotCache.createCacheField() );
161 break;
162 }
163 return nullptr;
164}
165
167{
168 static const RecordInfo spRecInfos[] =
169 {
181 { -1, -1 }
182 };
183 return spRecInfos;
184}
185
187{
188 // finalize the cache (check source range etc.)
190
191 // load the cache records, if the cache is based on a deleted or an external worksheet
193 {
194 OUString aRecFragmentPath = getRelations().getFragmentPathFromRelId( mrPivotCache.getRecordsRelId() );
195 if( !aRecFragmentPath.isEmpty() )
196 {
199 if( xSheetGlob )
200 importOoxFragment( new PivotCacheRecordsFragment( *xSheetGlob, aRecFragmentPath, mrPivotCache ) );
201 }
202 }
203}
204
206 const OUString& rFragmentPath, const PivotCache& rPivotCache ) :
207 WorksheetFragmentBase( rHelper, rFragmentPath ),
208 mrPivotCache( rPivotCache ),
209 mnColIdx( 0 ),
210 mnRowIdx( 0 ),
211 mbInRecord( false )
212{
213 sal_Int32 nSheetCount = rPivotCache.getWorksheets().getAllSheetCount();
214
215 // prepare sheet: insert column header names into top row
216 rPivotCache.writeSourceHeaderCells( *this );
217 // resize formula buffers since we've added a new dummy sheet
218 rHelper.getFormulaBuffer().SetSheetCount( nSheetCount );
219}
220
222{
223 switch( getCurrentElement() )
224 {
225 case XML_ROOT_CONTEXT:
226 if( nElement == XLS_TOKEN( pivotCacheRecords ) ) return this;
227 break;
228
229 case XLS_TOKEN( pivotCacheRecords ):
230 if( nElement == XLS_TOKEN( r ) ) { startCacheRecord(); return this; }
231 break;
232
233 case XLS_TOKEN( r ):
234 {
235 PivotCacheItem aItem;
236 switch( nElement )
237 {
238 case XLS_TOKEN( m ): break;
239 case XLS_TOKEN( s ): aItem.readString( rAttribs ); break;
240 case XLS_TOKEN( n ): aItem.readNumeric( rAttribs ); break;
241 case XLS_TOKEN( d ): aItem.readDate( rAttribs ); break;
242 case XLS_TOKEN( b ): aItem.readBool( rAttribs ); break;
243 case XLS_TOKEN( e ): aItem.readError( rAttribs ); break;
244 case XLS_TOKEN( x ): aItem.readIndex( rAttribs ); break;
245 default: OSL_FAIL( "OoxPivotCacheRecordsFragment::onCreateContext - unexpected element" );
246 }
248 ++mnColIdx;
249 }
250 break;
251 }
252 return nullptr;
253}
254
256{
257 switch( getCurrentElement() )
258 {
259 case XML_ROOT_CONTEXT:
260 if( nRecId == BIFF12_ID_PCRECORDS ) return this;
261 break;
262
264 switch( nRecId )
265 {
268 default: importPCRecordItem( nRecId, rStrm ); break;
269 }
270 break;
271 }
272 return nullptr;
273}
274
276{
277 static const RecordInfo spRecInfos[] =
278 {
280 { -1, -1 }
281 };
282 return spRecInfos;
283}
284
285// private --------------------------------------------------------------------
286
288{
289 mnColIdx = 0;
290 ++mnRowIdx;
291 mbInRecord = true;
292}
293
295{
298 mbInRecord = false;
299}
300
302{
303 if( !mbInRecord )
304 return;
305
306 PivotCacheItem aItem;
307 switch( nRecId )
308 {
309 case BIFF12_ID_PCITEM_MISSING: break;
310 case BIFF12_ID_PCITEM_STRING: aItem.readString( rStrm ); break;
311 case BIFF12_ID_PCITEM_DOUBLE: aItem.readDouble( rStrm ); break;
312 case BIFF12_ID_PCITEM_DATE: aItem.readDate( rStrm ); break;
313 case BIFF12_ID_PCITEM_BOOL: aItem.readBool( rStrm ); break;
315 case BIFF12_ID_PCITEM_INDEX: aItem.readIndex( rStrm ); break;
316 default: OSL_FAIL( "OoxPivotCacheRecordsFragment::importPCRecordItem - unexpected record" );
317 }
319 ++mnColIdx;
320}
321
322
323} // namespace oox::xls
324
325/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
double d
SCTAB Tab() const
Definition: address.hxx:283
ScAddress aStart
Definition: address.hxx:497
void SetSheetCount(SCTAB nSheets)
ensure sizes of vectors matches the number of sheets
PivotCacheDefinitionFragment(const WorkbookHelper &rHelper, const OUString &rFragmentPath, PivotCache &rPivotCache)
virtual const ::oox::core::RecordInfo * getRecordInfos() const override
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
virtual ::oox::core::ContextHandlerRef onCreateRecordContext(sal_Int32 nRecId, SequenceInputStream &rStrm) override
PivotCacheFieldContext(WorkbookFragmentBase &rFragment, PivotCacheField &rCacheField)
virtual void onStartRecord(SequenceInputStream &rStrm) override
virtual void onStartElement(const AttributeList &rAttribs) override
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
virtual ::oox::core::ContextHandlerRef onCreateRecordContext(sal_Int32 nRecId, SequenceInputStream &rStrm) override
void importPCDFSharedItem(sal_Int32 nRecId, SequenceInputStream &rStrm)
Imports one or more shared items from the passed record.
void importPCDFGroupItem(sal_Int32 nRecId, SequenceInputStream &rStrm)
Imports one or more group items from the passed record.
void importFieldGroup(const AttributeList &rAttribs)
Imports grouping settings from the fieldGroup element.
void importPCDFSharedItems(SequenceInputStream &rStrm)
Imports shared items settings from the PCDFSHAREDITEMS record.
void importGroupItem(sal_Int32 nElement, const AttributeList &rAttribs)
Imports a group item from the passed element.
void importCacheField(const AttributeList &rAttribs)
Imports pivot cache field settings from the cacheField element.
void importSharedItem(sal_Int32 nElement, const AttributeList &rAttribs)
Imports a shared item from the passed element.
void importDiscretePrItem(sal_Int32 nElement, const AttributeList &rAttribs)
Imports an item of the mapping between group items and base items from the passed element.
void importRangePr(const AttributeList &rAttribs)
Imports numeric grouping settings from the rangePr element.
void importPCDField(SequenceInputStream &rStrm)
Imports pivot cache field settings from the PCDFIELD record.
void importSharedItems(const AttributeList &rAttribs)
Imports shared items settings from the sharedItems element.
void importPCDFDiscretePrItem(sal_Int32 nRecId, SequenceInputStream &rStrm)
Imports an item of the mapping between group items and base items from the passed record.
void importPCDFRangePr(SequenceInputStream &rStrm)
Imports numeric grouping settings from the PCDFRANGEPR record.
void importPCDFieldGroup(SequenceInputStream &rStrm)
Imports grouping settings from the PCDFIELDGROUP record.
void readString(const AttributeList &rAttribs)
Reads the string value from a pivot cache item.
void readBool(const AttributeList &rAttribs)
Reads the boolean value from a pivot cache item.
void readIndex(const AttributeList &rAttribs)
Reads the index of a shared item.
void readDate(const AttributeList &rAttribs)
Reads the date/time value from a pivot cache item.
void readError(const AttributeList &rAttribs)
Reads the error code value from a pivot cache item.
void readNumeric(const AttributeList &rAttribs)
Reads the double value from a pivot cache item.
void readDouble(SequenceInputStream &rStrm)
Reads the double value from a pivot cache item.
bool mbInRecord
Relative row index in source data.
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
PivotCacheRecordsFragment(const WorksheetHelper &rHelper, const OUString &rFragmentPath, const PivotCache &rPivotCache)
virtual const ::oox::core::RecordInfo * getRecordInfos() const override
void importPCRecord(SequenceInputStream &rStrm)
sal_Int32 mnRowIdx
Relative column index in source data.
void importPCRecordItem(sal_Int32 nRecId, SequenceInputStream &rStrm)
virtual ::oox::core::ContextHandlerRef onCreateRecordContext(sal_Int32 nRecId, SequenceInputStream &rStrm) override
void importPCDSheetSource(SequenceInputStream &rStrm, const ::oox::core::Relations &rRelations)
Reads sheet source settings from the PCDSHEETSOURCE record.
void importPivotCacheDefinition(const AttributeList &rAttribs)
Reads pivot cache global settings from the pivotCacheDefinition element.
void importPCRecord(SequenceInputStream &rStrm, const WorksheetHelper &rSheetHelper, sal_Int32 nRowIdx) const
Reads a PCRECORD record and writes all item values to the passed sheet.
void importPCDefinition(SequenceInputStream &rStrm)
Reads pivot cache global settings from the PCDEFINITION record.
bool isBasedOnDummySheet() const
Returns true, if the pivot cache is based on a dummy sheet created in finalizeImport.
void importCacheSource(const AttributeList &rAttribs)
Reads cache source settings from the cacheSource element.
const ScRange & getSourceRange() const
Returns the internal cell range the cache is based on.
bool isValidDataSource() const
Returns true, if the pivot cache is based on a valid data source, so that pivot tables can be created...
PivotCacheField & createCacheField()
Creates and returns a new pivot cache field.
void finalizeImport()
Checks validity of source data and creates a dummy data sheet for external sheet sources.
void importPCDSource(SequenceInputStream &rStrm)
Reads cache source settings from the PCDSOURCE record.
const OUString & getRecordsRelId() const
Returns the relation identifier of the pivot cache records fragment.
void importWorksheetSource(const AttributeList &rAttribs, const ::oox::core::Relations &rRelations)
Reads sheet source settings from the worksheetSource element.
void writeSourceHeaderCells(const WorksheetHelper &rSheetHelper) const
Writes the titles of all source fields into the passed sheet.
void writeSourceDataCell(const WorksheetHelper &rSheetHelper, sal_Int32 nColIdx, sal_Int32 nRowIdx, const PivotCacheItem &rItem) const
Writes a source field item value into the passed sheet.
Context handler derived from the WorkbookHelper helper class.
Fragment handler derived from the WorkbookHelper helper class.
Helper class to provide access to global workbook data.
bool importOoxFragment(const rtl::Reference< oox::core::FragmentHandler > &rxHandler)
Imports a fragment using the passed fragment handler, which contains the full path to the fragment st...
WorksheetBuffer & getWorksheets() const
Returns the worksheet buffer containing sheet names and properties.
FormulaBuffer & getFormulaBuffer() const
UnitConverter & getUnitConverter() const
Returns the measurement unit converter.
sal_Int32 getAllSheetCount() const
Returns the number of all sheets, workbook + dummy ones (pivot table cache records )
Fragment handler derived from the WorksheetHelper helper class.
static WorksheetGlobalsRef constructGlobals(const WorkbookHelper &rHelper, const ISegmentProgressBarRef &rxProgressBar, WorksheetType eSheetType, SCTAB nSheet)
float x
sal_Int64 n
void SvStream & rStrm
m
const sal_Int32 XML_ROOT_CONTEXT
const sal_Int32 BIFF12_ID_PCITEM_ARRAY
Definition: biffhelper.hxx:165
const sal_Int32 BIFF12_ID_PCDFDISCRETEPR
Definition: biffhelper.hxx:156
const sal_Int32 BIFF12_ID_PCDSHEETSOURCE
Definition: biffhelper.hxx:163
const sal_Int32 BIFF12_ID_PCDFGROUPITEMS
Definition: biffhelper.hxx:157
const sal_Int32 BIFF12_ID_PCITEM_INDEX
Definition: biffhelper.hxx:170
const sal_Int32 BIFF12_ID_PCITEM_MISSING
Definition: biffhelper.hxx:171
const sal_Int32 BIFF12_ID_PCDSOURCE
Definition: biffhelper.hxx:164
const sal_Int32 BIFF12_ID_PCDFIELDS
Definition: biffhelper.hxx:160
const sal_Int32 BIFF12_ID_PCITEM_BOOL
Definition: biffhelper.hxx:166
const sal_Int32 BIFF12_ID_PCITEM_DATE
Definition: biffhelper.hxx:167
const sal_Int32 BIFF12_ID_PCRECORD
Definition: biffhelper.hxx:179
const sal_Int32 BIFF12_ID_PCITEM_DOUBLE
Definition: biffhelper.hxx:168
const sal_Int32 BIFF12_ID_PCDFSHAREDITEMS
Definition: biffhelper.hxx:162
const sal_Int32 BIFF12_ID_PCDFIELD
Definition: biffhelper.hxx:158
const sal_Int32 BIFF12_ID_PCITEM_ERROR
Definition: biffhelper.hxx:169
std::shared_ptr< WorksheetGlobals > WorksheetGlobalsRef
const sal_Int32 BIFF12_ID_PCRECORDS
Definition: biffhelper.hxx:181
const sal_Int32 BIFF12_ID_PCRECORDDT
Definition: biffhelper.hxx:180
const sal_Int32 BIFF12_ID_PCDFIELDGROUP
Definition: biffhelper.hxx:159
const sal_Int32 BIFF12_ID_PCDFRANGEPR
Definition: biffhelper.hxx:161
const sal_Int32 BIFF12_ID_PCITEM_STRING
Definition: biffhelper.hxx:172
const sal_Int32 BIFF12_ID_PCDEFINITION
Definition: biffhelper.hxx:155
std::shared_ptr< ISegmentProgressBar > ISegmentProgressBarRef
sal_Int16 SCTAB
Definition: types.hxx:22