LibreOffice Module sc (master)  1
xepivot.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 
20 #include <xepivot.hxx>
21 #include <xehelper.hxx>
22 #include <com/sun/star/sheet/DataPilotFieldSortInfo.hpp>
23 #include <com/sun/star/sheet/DataPilotFieldAutoShowInfo.hpp>
24 #include <com/sun/star/sheet/DataPilotFieldLayoutInfo.hpp>
25 #include <com/sun/star/sheet/DataPilotFieldReference.hpp>
26 #include <com/sun/star/sheet/DataPilotFieldReferenceItemType.hpp>
27 #include <com/sun/star/sheet/DataPilotFieldGroupBy.hpp>
28 #include <com/sun/star/sheet/DataPilotFieldSortMode.hpp>
29 
30 #include <algorithm>
31 #include <math.h>
32 
33 #include <osl/diagnose.h>
34 #include <sot/storage.hxx>
35 #include <document.hxx>
36 #include <dpcache.hxx>
37 #include <dpgroup.hxx>
38 #include <dpobject.hxx>
39 #include <dpsave.hxx>
40 #include <dpdimsave.hxx>
41 #include <dpshttab.hxx>
42 #include <globstr.hrc>
43 #include <scresid.hxx>
44 #include <xestring.hxx>
45 #include <xelink.hxx>
46 #include <dputil.hxx>
47 #include <generalfunction.hxx>
48 
49 using namespace ::oox;
50 
51 using ::com::sun::star::sheet::DataPilotFieldOrientation;
52 using ::com::sun::star::sheet::DataPilotFieldOrientation_ROW;
53 using ::com::sun::star::sheet::DataPilotFieldOrientation_COLUMN;
54 using ::com::sun::star::sheet::DataPilotFieldOrientation_PAGE;
55 using ::com::sun::star::sheet::DataPilotFieldOrientation_DATA;
56 using ::com::sun::star::sheet::DataPilotFieldSortInfo;
57 using ::com::sun::star::sheet::DataPilotFieldAutoShowInfo;
58 using ::com::sun::star::sheet::DataPilotFieldLayoutInfo;
59 using ::com::sun::star::sheet::DataPilotFieldReference;
60 
61 // Pivot cache
62 
63 namespace {
64 
65 // constants to track occurrence of specific data types
66 const sal_uInt16 EXC_PCITEM_DATA_STRING = 0x0001;
67 const sal_uInt16 EXC_PCITEM_DATA_DOUBLE = 0x0002;
68 const sal_uInt16 EXC_PCITEM_DATA_INTEGER = 0x0004;
69 const sal_uInt16 EXC_PCITEM_DATA_DATE = 0x0008;
70 
72 const sal_uInt16 spnPCItemFlags[] =
73 { // STR DBL INT DAT
80  EXC_SXFIELD_DATA_INT, // x x
81  EXC_SXFIELD_DATA_STR_INT, // x x x
89  EXC_SXFIELD_DATA_DATE_STR // x x x x
90 };
91 
92 } // namespace
93 
94 XclExpPCItem::XclExpPCItem( const OUString& rText ) :
95  XclExpRecord( (!rText.isEmpty()) ? EXC_ID_SXSTRING : EXC_ID_SXEMPTY, 0 ),
96  mnTypeFlag( EXC_PCITEM_DATA_STRING )
97 {
98  if( !rText.isEmpty() )
99  SetText( rText );
100  else
101  SetEmpty();
102 }
103 
104 XclExpPCItem::XclExpPCItem( double fValue, const OUString& rText ) :
106 {
107  SetDouble( fValue, rText );
108  mnTypeFlag = (fValue - floor( fValue ) == 0.0) ?
109  EXC_PCITEM_DATA_INTEGER : EXC_PCITEM_DATA_DOUBLE;
110 }
111 
112 XclExpPCItem::XclExpPCItem( const DateTime& rDateTime, const OUString& rText ) :
114 {
115  SetDateTime( rDateTime, rText );
116  mnTypeFlag = EXC_PCITEM_DATA_DATE;
117 }
118 
119 XclExpPCItem::XclExpPCItem( sal_Int16 nValue ) :
121  mnTypeFlag( EXC_PCITEM_DATA_INTEGER )
122 {
123  SetInteger( nValue );
124 }
125 
126 XclExpPCItem::XclExpPCItem( bool bValue, const OUString& rText ) :
128  mnTypeFlag( EXC_PCITEM_DATA_STRING )
129 {
130  SetBool( bValue, rText );
131 }
132 
133 bool XclExpPCItem::EqualsText( const OUString& rText ) const
134 {
135  return rText.isEmpty() ? IsEmpty() : (GetText() && (*GetText() == rText));
136 }
137 
138 bool XclExpPCItem::EqualsDouble( double fValue ) const
139 {
140  return GetDouble() && (*GetDouble() == fValue);
141 }
142 
143 bool XclExpPCItem::EqualsDateTime( const DateTime& rDateTime ) const
144 {
145  return GetDateTime() && (*GetDateTime() == rDateTime);
146 }
147 
148 bool XclExpPCItem::EqualsBool( bool bValue ) const
149 {
150  return GetBool() && (*GetBool() == bValue);
151 }
152 
154 {
155  if( const OUString* pText = GetText() )
156  {
157  rStrm << XclExpString( *pText );
158  }
159  else if( const double* pfValue = GetDouble() )
160  {
161  rStrm << *pfValue;
162  }
163  else if( const sal_Int16* pnValue = GetInteger() )
164  {
165  rStrm << *pnValue;
166  }
167  else if( const DateTime* pDateTime = GetDateTime() )
168  {
169  sal_uInt16 nYear = static_cast< sal_uInt16 >( pDateTime->GetYear() );
170  sal_uInt16 nMonth = pDateTime->GetMonth();
171  sal_uInt8 nDay = static_cast< sal_uInt8 >( pDateTime->GetDay() );
172  sal_uInt8 nHour = static_cast< sal_uInt8 >( pDateTime->GetHour() );
173  sal_uInt8 nMin = static_cast< sal_uInt8 >( pDateTime->GetMin() );
174  sal_uInt8 nSec = static_cast< sal_uInt8 >( pDateTime->GetSec() );
175  if( nYear < 1900 ) { nYear = 1900; nMonth = 1; nDay = 0; }
176  rStrm << nYear << nMonth << nDay << nHour << nMin << nSec;
177  }
178  else if( const bool* pbValue = GetBool() )
179  {
180  rStrm << static_cast< sal_uInt16 >( *pbValue ? 1 : 0 );
181  }
182  else
183  {
184  // nothing to do for SXEMPTY
185  OSL_ENSURE( IsEmpty(), "XclExpPCItem::WriteBody - no data found" );
186  }
187 }
188 
190  const XclExpRoot& rRoot, sal_uInt16 nFieldIdx,
191  const ScDPObject& rDPObj, const ScRange& rRange ) :
193  XclPCField( EXC_PCFIELD_STANDARD, nFieldIdx ),
194  XclExpRoot( rRoot ),
195  mnTypeFlags( 0 )
196 {
197  // general settings for the standard field, insert all items from source range
198  InitStandardField( rRange );
199 
200  // add special settings for inplace numeric grouping
201  if( const ScDPSaveData* pSaveData = rDPObj.GetSaveData() )
202  {
203  if( const ScDPDimensionSaveData* pSaveDimData = pSaveData->GetExistingDimensionData() )
204  {
205  if( const ScDPSaveNumGroupDimension* pNumGroupDim = pSaveDimData->GetNumGroupDim( GetFieldName() ) )
206  {
207  const ScDPNumGroupInfo& rNumInfo = pNumGroupDim->GetInfo();
208  const ScDPNumGroupInfo& rDateInfo = pNumGroupDim->GetDateInfo();
209  OSL_ENSURE( !rNumInfo.mbEnable || !rDateInfo.mbEnable,
210  "XclExpPCField::XclExpPCField - numeric and date grouping enabled" );
211 
212  if( rNumInfo.mbEnable )
213  InitNumGroupField( rDPObj, rNumInfo );
214  else if( rDateInfo.mbEnable )
215  InitDateGroupField( rDPObj, rDateInfo, pNumGroupDim->GetDatePart() );
216  }
217  }
218  }
219 
220  // final settings (flags, item numbers)
221  Finalize();
222 }
223 
225  const XclExpRoot& rRoot, sal_uInt16 nFieldIdx,
226  const ScDPObject& rDPObj, const ScDPSaveGroupDimension& rGroupDim, const XclExpPCField& rBaseField ) :
228  XclPCField( EXC_PCFIELD_STDGROUP, nFieldIdx ),
229  XclExpRoot( rRoot ),
230  mnTypeFlags( 0 )
231 {
232  // add base field info (always using first base field, not predecessor of this field) ***
233  OSL_ENSURE( rBaseField.GetFieldName() == rGroupDim.GetSourceDimName(),
234  "XclExpPCField::FillFromGroup - wrong base cache field" );
235  maFieldInfo.maName = rGroupDim.GetGroupDimName();
236  maFieldInfo.mnGroupBase = rBaseField.GetFieldIndex();
237 
238  // add standard group info or date group info
239  const ScDPNumGroupInfo& rDateInfo = rGroupDim.GetDateInfo();
240  if( rDateInfo.mbEnable && (rGroupDim.GetDatePart() != 0) )
241  InitDateGroupField( rDPObj, rDateInfo, rGroupDim.GetDatePart() );
242  else
243  InitStdGroupField( rBaseField, rGroupDim );
244 
245  // final settings (flags, item numbers)
246  Finalize();
247 }
248 
250 {
251 }
252 
254 {
256  "XclExpPCField::SetGroupChildIndex - field already has a grouping child field" );
258  maFieldInfo.mnGroupChild = rChildField.GetFieldIndex();
259 }
260 
261 sal_uInt16 XclExpPCField::GetItemCount() const
262 {
263  return static_cast< sal_uInt16 >( GetVisItemList().GetSize() );
264 }
265 
266 const XclExpPCItem* XclExpPCField::GetItem( sal_uInt16 nItemIdx ) const
267 {
268  return GetVisItemList().GetRecord( nItemIdx );
269 }
270 
271 sal_uInt16 XclExpPCField::GetItemIndex( const OUString& rItemName ) const
272 {
273  const XclExpPCItemList& rItemList = GetVisItemList();
274  for( size_t nPos = 0, nSize = rItemList.GetSize(); nPos < nSize; ++nPos )
275  if( rItemList.GetRecord( nPos )->ConvertToText() == rItemName )
276  return static_cast< sal_uInt16 >( nPos );
277  return EXC_PC_NOITEM;
278 }
279 
280 std::size_t XclExpPCField::GetIndexSize() const
281 {
282  return Has16BitIndexes() ? 2 : 1;
283 }
284 
285 void XclExpPCField::WriteIndex( XclExpStream& rStrm, sal_uInt32 nSrcRow ) const
286 {
287  // only standard fields write item indexes
288  if( nSrcRow < maIndexVec.size() )
289  {
290  sal_uInt16 nIndex = maIndexVec[ nSrcRow ];
291  if( Has16BitIndexes() )
292  rStrm << nIndex;
293  else
294  rStrm << static_cast< sal_uInt8 >( nIndex );
295  }
296 }
297 
299 {
300  OSL_ENSURE( IsSupportedField(), "XclExpPCField::Save - unknown field type" );
301  // SXFIELD
302  XclExpRecord::Save( rStrm );
303  // SXFDBTYPE
305  // list of grouping items
306  maGroupItemList.Save( rStrm );
307  // SXGROUPINFO
308  WriteSxgroupinfo( rStrm );
309  // SXNUMGROUP and additional grouping items (grouping limit settings)
310  WriteSxnumgroup( rStrm );
311  // list of original items
312  maOrigItemList.Save( rStrm );
313 }
314 
315 // private --------------------------------------------------------------------
316 
318 {
319  OSL_ENSURE( IsStandardField() == maGroupItemList.IsEmpty(),
320  "XclExpPCField::GetVisItemList - unexpected additional items in standard field" );
322 }
323 
325 {
326  OSL_ENSURE( IsStandardField(), "XclExpPCField::InitStandardField - only for standard fields" );
327  OSL_ENSURE( rRange.aStart.Col() == rRange.aEnd.Col(), "XclExpPCField::InitStandardField - cell range with multiple columns" );
328 
329  ScDocument& rDoc = GetDoc();
330  SvNumberFormatter& rFormatter = GetFormatter();
331 
332  // field name is in top cell of the range
333  ScAddress aPos( rRange.aStart );
334  maFieldInfo.maName = rDoc.GetString(aPos.Col(), aPos.Row(), aPos.Tab());
335  // #i76047# maximum field name length in pivot cache is 255
336  if (maFieldInfo.maName.getLength() > EXC_PC_MAXSTRLEN)
338 
339  // loop over all cells, create pivot cache items
340  for( aPos.IncRow(); (aPos.Row() <= rRange.aEnd.Row()) && (maOrigItemList.GetSize() < EXC_PC_MAXITEMCOUNT); aPos.IncRow() )
341  {
342  OUString aText = rDoc.GetString(aPos.Col(), aPos.Row(), aPos.Tab());
343  if( rDoc.HasValueData( aPos.Col(), aPos.Row(), aPos.Tab() ) )
344  {
345  double fValue = rDoc.GetValue( aPos );
346  SvNumFormatType nFmtType = rFormatter.GetType( rDoc.GetNumberFormat( rDoc.GetNonThreadedContext(), aPos ) );
347  if( nFmtType == SvNumFormatType::LOGICAL )
348  InsertOrigBoolItem( fValue != 0, aText );
349  else if( nFmtType & SvNumFormatType::DATETIME )
350  InsertOrigDateTimeItem( GetDateTimeFromDouble( ::std::max( fValue, 0.0 ) ), aText );
351  else
352  InsertOrigDoubleItem( fValue, aText );
353  }
354  else
355  {
356  InsertOrigTextItem( aText );
357  }
358  }
359 }
360 
361 void XclExpPCField::InitStdGroupField( const XclExpPCField& rBaseField, const ScDPSaveGroupDimension& rGroupDim )
362 {
363  OSL_ENSURE( IsGroupField(), "XclExpPCField::InitStdGroupField - only for standard grouping fields" );
364 
365  maFieldInfo.mnBaseItems = rBaseField.GetItemCount();
367 
368  // loop over all groups of this field
369  for( long nGroupIdx = 0, nGroupCount = rGroupDim.GetGroupCount(); nGroupIdx < nGroupCount; ++nGroupIdx )
370  {
371  const ScDPSaveGroupItem& rGroupItem = rGroupDim.GetGroupByIndex( nGroupIdx );
372  // the index of the new item containing the grouping name
373  sal_uInt16 nGroupItemIdx = EXC_PC_NOITEM;
374  // loop over all elements of one group
375  for( size_t nElemIdx = 0, nElemCount = rGroupItem.GetElementCount(); nElemIdx < nElemCount; ++nElemIdx )
376  {
377  if (const OUString* pElemName = rGroupItem.GetElementByIndex(nElemIdx))
378  {
379  // try to find the item that is part of the group in the base field
380  sal_uInt16 nBaseItemIdx = rBaseField.GetItemIndex( *pElemName );
381  if( nBaseItemIdx < maFieldInfo.mnBaseItems )
382  {
383  // add group name item only if there are any valid base items
384  if( nGroupItemIdx == EXC_PC_NOITEM )
385  nGroupItemIdx = InsertGroupItem( new XclExpPCItem( rGroupItem.GetGroupName() ) );
386  maGroupOrder[ nBaseItemIdx ] = nGroupItemIdx;
387  }
388  }
389  }
390  }
391 
392  // add items and base item indexes of all ungrouped elements
393  for( sal_uInt16 nBaseItemIdx = 0; nBaseItemIdx < maFieldInfo.mnBaseItems; ++nBaseItemIdx )
394  // items that are not part of a group still have the EXC_PC_NOITEM entry
395  if( maGroupOrder[ nBaseItemIdx ] == EXC_PC_NOITEM )
396  // try to find the base item
397  if( const XclExpPCItem* pBaseItem = rBaseField.GetItem( nBaseItemIdx ) )
398  // create a clone of the base item, insert its index into item order list
399  maGroupOrder[ nBaseItemIdx ] = InsertGroupItem( new XclExpPCItem( *pBaseItem ) );
400 }
401 
402 void XclExpPCField::InitNumGroupField( const ScDPObject& rDPObj, const ScDPNumGroupInfo& rNumInfo )
403 {
404  OSL_ENSURE( IsStandardField(), "XclExpPCField::InitNumGroupField - only for standard fields" );
405  OSL_ENSURE( rNumInfo.mbEnable, "XclExpPCField::InitNumGroupField - numeric grouping not enabled" );
406 
407  // new field type, date type, limit settings (min/max/step/auto)
408  if( rNumInfo.mbDateValues )
409  {
410  // special case: group by days with step count
412  maNumGroupInfo.SetScDateType( css::sheet::DataPilotFieldGroupBy::DAYS );
413  SetDateGroupLimit( rNumInfo, true );
414  }
415  else
416  {
419  SetNumGroupLimit( rNumInfo );
420  }
421 
422  // generate visible items
423  InsertNumDateGroupItems( rDPObj, rNumInfo );
424 }
425 
426 void XclExpPCField::InitDateGroupField( const ScDPObject& rDPObj, const ScDPNumGroupInfo& rDateInfo, sal_Int32 nDatePart )
427 {
428  OSL_ENSURE( IsStandardField() || IsStdGroupField(), "XclExpPCField::InitDateGroupField - only for standard fields" );
429  OSL_ENSURE( rDateInfo.mbEnable, "XclExpPCField::InitDateGroupField - date grouping not enabled" );
430 
431  // new field type
433 
434  // date type, limit settings (min/max/step/auto)
435  maNumGroupInfo.SetScDateType( nDatePart );
436  SetDateGroupLimit( rDateInfo, false );
437 
438  // generate visible items
439  InsertNumDateGroupItems( rDPObj, rDateInfo, nDatePart );
440 }
441 
442 void XclExpPCField::InsertItemArrayIndex( size_t nListPos )
443 {
444  OSL_ENSURE( IsStandardField(), "XclExpPCField::InsertItemArrayIndex - only for standard fields" );
445  maIndexVec.push_back( static_cast< sal_uInt16 >( nListPos ) );
446 }
447 
449 {
450  size_t nItemIdx = maOrigItemList.GetSize();
451  maOrigItemList.AppendNewRecord( pNewItem );
452  InsertItemArrayIndex( nItemIdx );
453  mnTypeFlags |= pNewItem->GetTypeFlag();
454 }
455 
456 void XclExpPCField::InsertOrigTextItem( const OUString& rText )
457 {
458  size_t nPos = 0;
459  bool bFound = false;
460  // #i76047# maximum item text length in pivot cache is 255
461  OUString aShortText = rText.copy( 0, ::std::min(rText.getLength(), EXC_PC_MAXSTRLEN ) );
462  for( size_t nSize = maOrigItemList.GetSize(); !bFound && (nPos < nSize); ++nPos )
463  if( (bFound = maOrigItemList.GetRecord( nPos )->EqualsText( aShortText )) )
464  InsertItemArrayIndex( nPos );
465  if( !bFound )
466  InsertOrigItem( new XclExpPCItem( aShortText ) );
467 }
468 
469 void XclExpPCField::InsertOrigDoubleItem( double fValue, const OUString& rText )
470 {
471  size_t nPos = 0;
472  bool bFound = false;
473  for( size_t nSize = maOrigItemList.GetSize(); !bFound && (nPos < nSize); ++nPos )
474  if( (bFound = maOrigItemList.GetRecord( nPos )->EqualsDouble( fValue )) )
475  InsertItemArrayIndex( nPos );
476  if( !bFound )
477  InsertOrigItem( new XclExpPCItem( fValue, rText ) );
478 }
479 
480 void XclExpPCField::InsertOrigDateTimeItem( const DateTime& rDateTime, const OUString& rText )
481 {
482  size_t nPos = 0;
483  bool bFound = false;
484  for( size_t nSize = maOrigItemList.GetSize(); !bFound && (nPos < nSize); ++nPos )
485  if( (bFound = maOrigItemList.GetRecord( nPos )->EqualsDateTime( rDateTime )) )
486  InsertItemArrayIndex( nPos );
487  if( !bFound )
488  InsertOrigItem( new XclExpPCItem( rDateTime, rText ) );
489 }
490 
491 void XclExpPCField::InsertOrigBoolItem( bool bValue, const OUString& rText )
492 {
493  size_t nPos = 0;
494  bool bFound = false;
495  for( size_t nSize = maOrigItemList.GetSize(); !bFound && (nPos < nSize); ++nPos )
496  if( (bFound = maOrigItemList.GetRecord( nPos )->EqualsBool( bValue )) )
497  InsertItemArrayIndex( nPos );
498  if( !bFound )
499  InsertOrigItem( new XclExpPCItem( bValue, rText ) );
500 }
501 
503 {
504  maGroupItemList.AppendNewRecord( pNewItem );
505  return static_cast< sal_uInt16 >( maGroupItemList.GetSize() - 1 );
506 }
507 
508 void XclExpPCField::InsertNumDateGroupItems( const ScDPObject& rDPObj, const ScDPNumGroupInfo& rNumInfo, sal_Int32 nDatePart )
509 {
510  OSL_ENSURE( rDPObj.GetSheetDesc(), "XclExpPCField::InsertNumDateGroupItems - cannot generate element list" );
511  const ScSheetSourceDesc* pSrcDesc = rDPObj.GetSheetDesc();
512  if(!pSrcDesc)
513  return;
514 
515  // get the string collection with original source elements
516  const ScDPSaveData* pSaveData = rDPObj.GetSaveData();
517  const ScDPDimensionSaveData* pDimData = nullptr;
518  if (pSaveData)
519  pDimData = pSaveData->GetExistingDimensionData();
520 
521  const ScDPCache* pCache = pSrcDesc->CreateCache(pDimData);
522  if (!pCache)
523  return;
524 
525  ScSheetDPData aDPData(&GetDoc(), *pSrcDesc, *pCache);
526  long nDim = GetFieldIndex();
527  // get the string collection with generated grouping elements
528  ScDPNumGroupDimension aTmpDim( rNumInfo );
529  if( nDatePart != 0 )
530  aTmpDim.SetDateDimension();
531  const std::vector<SCROW>& aMemberIds = aTmpDim.GetNumEntries(
532  static_cast<SCCOL>(nDim), pCache);
533  for (SCROW nMemberId : aMemberIds)
534  {
535  const ScDPItemData* pData = aDPData.GetMemberById(nDim, nMemberId);
536  if ( pData )
537  {
538  OUString aStr = pCache->GetFormattedString(nDim, *pData, false);
539  InsertGroupItem(new XclExpPCItem(aStr));
540  }
541  }
542 }
543 
545 {
551 }
552 
553 void XclExpPCField::SetDateGroupLimit( const ScDPNumGroupInfo& rDateInfo, bool bUseStep )
554 {
559  sal_Int16 nStep = bUseStep ? limit_cast< sal_Int16 >( rDateInfo.mfStep, 1, SAL_MAX_INT16 ) : 1;
561 }
562 
564 {
565  // flags
567  // Excel writes long indexes even for 0x0100 items (indexes from 0x00 to 0xFF)
570  /* mnTypeFlags is updated in all Insert***Item() functions. Now the flags
571  for the current combination of item types is added to the flags. */
572  ::set_flag( maFieldInfo.mnFlags, spnPCItemFlags[ mnTypeFlags ] );
573 
574  // item count fields
575  maFieldInfo.mnVisItems = static_cast< sal_uInt16 >( GetVisItemList().GetSize() );
576  maFieldInfo.mnGroupItems = static_cast< sal_uInt16 >( maGroupItemList.GetSize() );
577  // maFieldInfo.mnBaseItems set in InitStdGroupField()
578  maFieldInfo.mnOrigItems = static_cast< sal_uInt16 >( maOrigItemList.GetSize() );
579 }
580 
582 {
583  if( IsNumGroupField() || IsDateGroupField() )
584  {
585  // SXNUMGROUP record
586  rStrm.StartRecord( EXC_ID_SXNUMGROUP, 2 );
587  rStrm << maNumGroupInfo;
588  rStrm.EndRecord();
589 
590  // limits (min/max/step) for numeric grouping
591  OSL_ENSURE( maNumGroupLimits.GetSize() == 3,
592  "XclExpPCField::WriteSxnumgroup - missing numeric grouping limits" );
593  maNumGroupLimits.Save( rStrm );
594  }
595 }
596 
598 {
599  OSL_ENSURE( IsStdGroupField() != maGroupOrder.empty(),
600  "XclExpPCField::WriteSxgroupinfo - missing grouping info" );
601  if( IsStdGroupField() && !maGroupOrder.empty() )
602  {
603  rStrm.StartRecord( EXC_ID_SXGROUPINFO, 2 * maGroupOrder.size() );
604  for( const auto& rItem : maGroupOrder )
605  rStrm << rItem;
606  rStrm.EndRecord();
607  }
608 }
609 
611 {
612  rStrm << maFieldInfo;
613 }
614 
615 XclExpPivotCache::XclExpPivotCache( const XclExpRoot& rRoot, const ScDPObject& rDPObj, sal_uInt16 nListIdx ) :
616  XclExpRoot( rRoot ),
617  mnListIdx( nListIdx ),
618  mbValid( false )
619 {
620  // source from sheet only
621  const ScSheetSourceDesc* pSrcDesc = rDPObj.GetSheetDesc();
622  if(!pSrcDesc)
623  return;
624 
625  /* maOrigSrcRange: Range received from the DataPilot object.
626  maExpSrcRange: Range written to the DCONREF record.
627  maDocSrcRange: Range used to get source data from Calc document.
628  This range may be shorter than maExpSrcRange to improve export
629  performance (#i22541#). */
631  maSrcRangeName = pSrcDesc->GetRangeName();
632 
633  // internal sheet data only
634  SCTAB nScTab = maExpSrcRange.aStart.Tab();
635  if( !((nScTab == maExpSrcRange.aEnd.Tab()) && GetTabInfo().IsExportTab( nScTab )) )
636  return;
637 
638  // ValidateRange() restricts source range to valid Excel limits
640  return;
641 
642  // #i22541# skip empty cell areas (performance)
643  SCCOL nDocCol1, nDocCol2;
644  SCROW nDocRow1, nDocRow2;
645  GetDoc().GetDataStart( nScTab, nDocCol1, nDocRow1 );
646  GetDoc().GetPrintArea( nScTab, nDocCol2, nDocRow2, false );
647  SCCOL nSrcCol1 = maExpSrcRange.aStart.Col();
648  SCROW nSrcRow1 = maExpSrcRange.aStart.Row();
649  SCCOL nSrcCol2 = maExpSrcRange.aEnd.Col();
650  SCROW nSrcRow2 = maExpSrcRange.aEnd.Row();
651 
652  // #i22541# do not store index list for too big ranges
653  if( 2 * (nDocRow2 - nDocRow1) < (nSrcRow2 - nSrcRow1) )
655 
656  // adjust row indexes, keep one row of empty area to surely have the empty cache item
657  if( nSrcRow1 < nDocRow1 )
658  nSrcRow1 = nDocRow1 - 1;
659  if( nSrcRow2 > nDocRow2 )
660  nSrcRow2 = nDocRow2 + 1;
661 
662  maDocSrcRange.aStart.SetCol( ::std::max( nDocCol1, nSrcCol1 ) );
663  maDocSrcRange.aStart.SetRow( nSrcRow1 );
664  maDocSrcRange.aEnd.SetCol( ::std::min( nDocCol2, nSrcCol2 ) );
665  maDocSrcRange.aEnd.SetRow( nSrcRow2 );
666 
667  GetDoc().GetName( nScTab, maTabName );
668  maPCInfo.mnSrcRecs = static_cast< sal_uInt32 >( maExpSrcRange.aEnd.Row() - maExpSrcRange.aStart.Row() );
669  maPCInfo.mnStrmId = nListIdx + 1;
671 
672  AddFields( rDPObj );
673 
674  mbValid = true;
675 }
676 
678 {
680 }
681 
683 {
684  return static_cast< sal_uInt16 >( maFieldList.GetSize() );
685 }
686 
687 const XclExpPCField* XclExpPivotCache::GetField( sal_uInt16 nFieldIdx ) const
688 {
689  return maFieldList.GetRecord( nFieldIdx );
690 }
691 
693 {
694  // pivot cache can be shared, if there are no additional cache fields
696 }
697 
699 {
700  /* For now, only sheet sources are supported, therefore it is enough to
701  compare the ScSheetSourceDesc. Later, there should be done more complicated
702  comparisons regarding the source type of rDPObj and this cache. */
703  if( const ScSheetSourceDesc* pSrcDesc = rDPObj.GetSheetDesc() )
704  return pSrcDesc->GetSourceRange() == maOrigSrcRange;
705  return false;
706 }
707 
709 {
710  OSL_ENSURE( mbValid, "XclExpPivotCache::Save - invalid pivot cache" );
711  // SXIDSTM
713  // SXVS
715 
716  if (!maSrcRangeName.isEmpty())
717  // DCONNAME
718  WriteDConName(rStrm);
719  else
720  // DCONREF
721  WriteDconref(rStrm);
722 
723  // create the pivot cache storage stream
725 }
726 
728 {
729 }
730 
732 {
733  AddStdFields( rDPObj );
735  AddGroupFields( rDPObj );
737 };
738 
740 {
741  // if item index list is not written, used shortened source range (maDocSrcRange) for performance
742  const ScRange& rRange = HasItemIndexList() ? maExpSrcRange : maDocSrcRange;
743  // create a standard pivot cache field for each source column
744  for( SCCOL nScCol = rRange.aStart.Col(), nEndScCol = rRange.aEnd.Col(); nScCol <= nEndScCol; ++nScCol )
745  {
746  ScRange aColRange( rRange );
747  aColRange.aStart.SetCol( nScCol );
748  aColRange.aEnd.SetCol( nScCol );
750  GetRoot(), GetFieldCount(), rDPObj, aColRange ) );
751  }
752 }
753 
755 {
756  const ScDPSaveData* pSaveData = rDPObj.GetSaveData();
757  if(!pSaveData)
758  return;
759  const ScDPDimensionSaveData* pSaveDimData = pSaveData->GetExistingDimensionData();
760  if( !pSaveDimData )
761  return;
762 
763  // loop over all existing standard fields to find their group fields
764  for( sal_uInt16 nFieldIdx = 0; nFieldIdx < maPCInfo.mnStdFields; ++nFieldIdx )
765  {
766  if( XclExpPCField* pCurrStdField = maFieldList.GetRecord( nFieldIdx ) )
767  {
768  const ScDPSaveGroupDimension* pGroupDim = pSaveDimData->GetGroupDimForBase( pCurrStdField->GetFieldName() );
769  XclExpPCField* pLastGroupField = pCurrStdField;
770  while( pGroupDim )
771  {
772  // insert the new grouping field
773  XclExpPCFieldRef xNewGroupField = new XclExpPCField(
774  GetRoot(), GetFieldCount(), rDPObj, *pGroupDim, *pCurrStdField );
775  maFieldList.AppendRecord( xNewGroupField );
776 
777  // register new grouping field at current grouping field, building a chain
778  pLastGroupField->SetGroupChildField( *xNewGroupField );
779 
780  // next grouping dimension
781  pGroupDim = pSaveDimData->GetGroupDimForBase( pGroupDim->GetGroupDimName() );
782  pLastGroupField = xNewGroupField.get();
783  }
784  }
785  }
786 }
787 
789 {
791  rStrm.StartRecord( EXC_ID_DCONREF, 7 + aRef.GetSize() );
792  rStrm << static_cast< sal_uInt16 >( maExpSrcRange.aStart.Row() )
793  << static_cast< sal_uInt16 >( maExpSrcRange.aEnd.Row() )
794  << static_cast< sal_uInt8 >( maExpSrcRange.aStart.Col() )
795  << static_cast< sal_uInt8 >( maExpSrcRange.aEnd.Col() )
796  << aRef
797  << sal_uInt8( 0 );
798  rStrm.EndRecord();
799 }
800 
802 {
804  rStrm.StartRecord(EXC_ID_DCONNAME, aName.GetSize() + 2);
805  rStrm << aName << sal_uInt16(0);
806  rStrm.EndRecord();
807 }
808 
810 {
813  if( !xSvStrm.is() )
814  return;
815 
816  XclExpStream aStrm( *xSvStrm, GetRoot() );
817  // SXDB
818  WriteSxdb( aStrm );
819  // SXDBEX
820  WriteSxdbex( aStrm );
821  // field list (SXFIELD and items)
822  maFieldList.Save( aStrm );
823  // index table (list of SXINDEXLIST)
824  WriteSxindexlistList( aStrm );
825  // EOF
826  XclExpEmptyRecord( EXC_ID_EOF ).Save( aStrm );
827 }
828 
830 {
831  rStrm.StartRecord( EXC_ID_SXDB, 21 );
832  rStrm << maPCInfo;
833  rStrm.EndRecord();
834 }
835 
837 {
838  rStrm.StartRecord( EXC_ID_SXDBEX, 12 );
839  rStrm << EXC_SXDBEX_CREATION_DATE
840  << sal_uInt32( 0 ); // number of SXFORMULA records
841  rStrm.EndRecord();
842 }
843 
845 {
846  if( !HasItemIndexList() )
847  return;
848 
849  std::size_t nRecSize = 0;
850  size_t nPos, nSize = maFieldList.GetSize();
851  for( nPos = 0; nPos < nSize; ++nPos )
852  nRecSize += maFieldList.GetRecord( nPos )->GetIndexSize();
853 
854  for( sal_uInt32 nSrcRow = 0; nSrcRow < maPCInfo.mnSrcRecs; ++nSrcRow )
855  {
856  rStrm.StartRecord( EXC_ID_SXINDEXLIST, nRecSize );
857  for( nPos = 0; nPos < nSize; ++nPos )
858  maFieldList.GetRecord( nPos )->WriteIndex( rStrm, nSrcRow );
859  rStrm.EndRecord();
860  }
861 }
862 
863 // Pivot table
864 
865 namespace {
866 
868 OUString lclGetDataFieldCaption( const OUString& rFieldName, ScGeneralFunction eFunc )
869 {
870  OUString aCaption;
871 
872  const char* pResIdx = nullptr;
873  switch( eFunc )
874  {
875  case ScGeneralFunction::SUM: pResIdx = STR_FUN_TEXT_SUM; break;
876  case ScGeneralFunction::COUNT: pResIdx = STR_FUN_TEXT_COUNT; break;
877  case ScGeneralFunction::AVERAGE: pResIdx = STR_FUN_TEXT_AVG; break;
878  case ScGeneralFunction::MAX: pResIdx = STR_FUN_TEXT_MAX; break;
879  case ScGeneralFunction::MIN: pResIdx = STR_FUN_TEXT_MIN; break;
880  case ScGeneralFunction::PRODUCT: pResIdx = STR_FUN_TEXT_PRODUCT; break;
881  case ScGeneralFunction::COUNTNUMS: pResIdx = STR_FUN_TEXT_COUNT; break;
882  case ScGeneralFunction::STDEV: pResIdx = STR_FUN_TEXT_STDDEV; break;
883  case ScGeneralFunction::STDEVP: pResIdx = STR_FUN_TEXT_STDDEV; break;
884  case ScGeneralFunction::VAR: pResIdx = STR_FUN_TEXT_VAR; break;
885  case ScGeneralFunction::VARP: pResIdx = STR_FUN_TEXT_VAR; break;
886  default:;
887  }
888  if (pResIdx)
889  aCaption = ScResId(pResIdx) + " - ";
890  aCaption += rFieldName;
891  return aCaption;
892 }
893 
894 } // namespace
895 
896 XclExpPTItem::XclExpPTItem( const XclExpPCField& rCacheField, sal_uInt16 nCacheIdx ) :
898  mpCacheItem( rCacheField.GetItem( nCacheIdx ) )
899 {
901  maItemInfo.mnCacheIdx = nCacheIdx;
903 }
904 
905 XclExpPTItem::XclExpPTItem( sal_uInt16 nItemType, sal_uInt16 nCacheIdx ) :
907  mpCacheItem( nullptr )
908 {
909  maItemInfo.mnType = nItemType;
910  maItemInfo.mnCacheIdx = nCacheIdx;
912 }
913 
915 {
916  return mpCacheItem ? mpCacheItem->ConvertToText() : OUString();
917 }
918 
920 {
921  // #i115659# GetIsVisible() is not valid if HasIsVisible() returns false, default is 'visible' then
922  ::set_flag( maItemInfo.mnFlags, EXC_SXVI_HIDDEN, rSaveMem.HasIsVisible() && !rSaveMem.GetIsVisible() );
923  // #i115659# GetShowDetails() is not valid if HasShowDetails() returns false, default is 'show detail' then
925 
926  // visible name
927  const std::optional<OUString> & pVisName = rSaveMem.GetLayoutName();
928  if (pVisName && *pVisName != GetItemName())
929  maItemInfo.SetVisName(*pVisName);
930 }
931 
933 {
934  rStrm << maItemInfo;
935 }
936 
937 XclExpPTField::XclExpPTField( const XclExpPivotTable& rPTable, sal_uInt16 nCacheIdx ) :
938  mrPTable( rPTable ),
939  mpCacheField( rPTable.GetCacheField( nCacheIdx ) )
940 {
941  maFieldInfo.mnCacheIdx = nCacheIdx;
942 
943  // create field items
944  if( mpCacheField )
945  for( sal_uInt16 nItemIdx = 0, nItemCount = mpCacheField->GetItemCount(); nItemIdx < nItemCount; ++nItemIdx )
947  maFieldInfo.mnItemCount = static_cast< sal_uInt16 >( maItemList.GetSize() );
948 }
949 
950 // data access ----------------------------------------------------------------
951 
953 {
954  return mpCacheField ? mpCacheField->GetFieldName() : OUString();
955 }
956 
958 {
959  OSL_ENSURE( !maDataInfoVec.empty(), "XclExpPTField::GetLastDataInfoIndex - no data info found" );
960  // will return 0xFFFF for empty vector -> ok
961  return static_cast< sal_uInt16 >( maDataInfoVec.size() - 1 );
962 }
963 
964 sal_uInt16 XclExpPTField::GetItemIndex( const OUString& rName, sal_uInt16 nDefaultIdx ) const
965 {
966  for( size_t nPos = 0, nSize = maItemList.GetSize(); nPos < nSize; ++nPos )
967  if( maItemList.GetRecord( nPos )->GetItemName() == rName )
968  return static_cast< sal_uInt16 >( nPos );
969  return nDefaultIdx;
970 }
971 
972 // fill data --------------------------------------------------------------
973 
978 static OUString lcl_convertCalcSubtotalName(const OUString& rName)
979 {
980  OUStringBuffer aBuf;
981  const sal_Unicode* p = rName.getStr();
982  sal_Int32 n = rName.getLength();
983  bool bEscaped = false;
984  for (sal_Int32 i = 0; i < n; ++i)
985  {
986  const sal_Unicode c = p[i];
987  if (!bEscaped && c == '\\')
988  {
989  bEscaped = true;
990  continue;
991  }
992 
993  aBuf.append(c);
994  bEscaped = false;
995  }
996  return aBuf.makeStringAndClear();
997 }
998 
1000 {
1001  // orientation
1002  DataPilotFieldOrientation eOrient = rSaveDim.GetOrientation();
1003  OSL_ENSURE( eOrient != DataPilotFieldOrientation_DATA, "XclExpPTField::SetPropertiesFromDim - called for data field" );
1004  maFieldInfo.AddApiOrient( eOrient );
1005 
1006  // show empty items (#i115659# GetShowEmpty() is not valid if HasShowEmpty() returns false, default is false then)
1008 
1009  // visible name
1010  const std::optional<OUString> & pLayoutName = rSaveDim.GetLayoutName();
1011  if (pLayoutName && *pLayoutName != GetFieldName())
1012  maFieldInfo.SetVisName(*pLayoutName);
1013 
1014  const std::optional<OUString> & pSubtotalName = rSaveDim.GetSubtotalName();
1015  if (pSubtotalName)
1016  {
1017  OUString aSubName = lcl_convertCalcSubtotalName(*pSubtotalName);
1018  maFieldExtInfo.mpFieldTotalName = aSubName;
1019  }
1020 
1021  // subtotals
1022  XclPTSubtotalVec aSubtotals;
1023  aSubtotals.reserve( static_cast< size_t >( rSaveDim.GetSubTotalsCount() ) );
1024  for( long nSubtIdx = 0, nSubtCount = rSaveDim.GetSubTotalsCount(); nSubtIdx < nSubtCount; ++nSubtIdx )
1025  aSubtotals.push_back( rSaveDim.GetSubTotalFunc( nSubtIdx ) );
1026  maFieldInfo.SetSubtotals( aSubtotals );
1027 
1028  // sorting
1029  if( const DataPilotFieldSortInfo* pSortInfo = rSaveDim.GetSortInfo() )
1030  {
1031  maFieldExtInfo.SetApiSortMode( pSortInfo->Mode );
1032  if( pSortInfo->Mode == css::sheet::DataPilotFieldSortMode::DATA )
1034  ::set_flag( maFieldExtInfo.mnFlags, EXC_SXVDEX_SORT_ASC, pSortInfo->IsAscending );
1035  }
1036 
1037  // auto show
1038  if( const DataPilotFieldAutoShowInfo* pShowInfo = rSaveDim.GetAutoShowInfo() )
1039  {
1040  ::set_flag( maFieldExtInfo.mnFlags, EXC_SXVDEX_AUTOSHOW, pShowInfo->IsEnabled );
1041  maFieldExtInfo.SetApiAutoShowMode( pShowInfo->ShowItemsMode );
1042  maFieldExtInfo.SetApiAutoShowCount( pShowInfo->ItemCount );
1044  }
1045 
1046  // layout
1047  if( const DataPilotFieldLayoutInfo* pLayoutInfo = rSaveDim.GetLayoutInfo() )
1048  {
1049  maFieldExtInfo.SetApiLayoutMode( pLayoutInfo->LayoutMode );
1050  ::set_flag( maFieldExtInfo.mnFlags, EXC_SXVDEX_LAYOUT_BLANK, pLayoutInfo->AddEmptyLines );
1051  }
1052 
1053  // special page field properties
1054  if( eOrient == DataPilotFieldOrientation_PAGE )
1055  {
1058  }
1059 
1060  // item properties
1061  const ScDPSaveDimension::MemberList &rMembers = rSaveDim.GetMembers();
1062  for (const auto& pMember : rMembers)
1063  if( XclExpPTItem* pItem = GetItemAcc( pMember->GetName() ) )
1064  pItem->SetPropertiesFromMember( *pMember );
1065 }
1066 
1068 {
1069  maDataInfoVec.emplace_back( );
1070  XclPTDataFieldInfo& rDataInfo = maDataInfoVec.back();
1071  rDataInfo.mnField = GetFieldIndex();
1072 
1073  // orientation
1074  maFieldInfo.AddApiOrient( DataPilotFieldOrientation_DATA );
1075 
1076  // aggregation function
1077  ScGeneralFunction eFunc = rSaveDim.GetFunction();
1078  rDataInfo.SetApiAggFunc( eFunc );
1079 
1080  // visible name
1081  const std::optional<OUString> & pVisName = rSaveDim.GetLayoutName();
1082  if (pVisName)
1083  rDataInfo.SetVisName(*pVisName);
1084  else
1085  rDataInfo.SetVisName( lclGetDataFieldCaption( GetFieldName(), eFunc ) );
1086 
1087  // result field reference
1088  if( const DataPilotFieldReference* pFieldRef = rSaveDim.GetReferenceValue() )
1089  {
1090  rDataInfo.SetApiRefType( pFieldRef->ReferenceType );
1091  rDataInfo.SetApiRefItemType( pFieldRef->ReferenceItemType );
1092  if( const XclExpPTField* pRefField = mrPTable.GetField( pFieldRef->ReferenceField ) )
1093  {
1094  rDataInfo.mnRefField = pRefField->GetFieldIndex();
1095  if( pFieldRef->ReferenceItemType == css::sheet::DataPilotFieldReferenceItemType::NAMED )
1096  rDataInfo.mnRefItem = pRefField->GetItemIndex( pFieldRef->ReferenceItemName, 0 );
1097  }
1098  }
1099 }
1100 
1102 {
1115 }
1116 
1117 // records --------------------------------------------------------------------
1118 
1120 {
1121  rStrm << maPageInfo;
1122 }
1123 
1124 void XclExpPTField::WriteSxdi( XclExpStream& rStrm, sal_uInt16 nDataInfoIdx ) const
1125 {
1126  OSL_ENSURE( nDataInfoIdx < maDataInfoVec.size(), "XclExpPTField::WriteSxdi - data field not found" );
1127  if( nDataInfoIdx < maDataInfoVec.size() )
1128  {
1129  rStrm.StartRecord( EXC_ID_SXDI, 12 );
1130  rStrm << maDataInfoVec[ nDataInfoIdx ];
1131  rStrm.EndRecord();
1132  }
1133 }
1134 
1136 {
1137  // SXVD
1138  WriteSxvd( rStrm );
1139  // list of SXVI records
1140  maItemList.Save( rStrm );
1141  // SXVDEX
1142  WriteSxvdex( rStrm );
1143 }
1144 
1145 // private --------------------------------------------------------------------
1146 
1147 XclExpPTItem* XclExpPTField::GetItemAcc( const OUString& rName )
1148 {
1149  XclExpPTItem* pItem = nullptr;
1150  for( size_t nPos = 0, nSize = maItemList.GetSize(); !pItem && (nPos < nSize); ++nPos )
1151  if( maItemList.GetRecord( nPos )->GetItemName() == rName )
1152  pItem = maItemList.GetRecord( nPos );
1153  return pItem;
1154 }
1155 
1156 void XclExpPTField::AppendSubtotalItem( sal_uInt16 nItemType )
1157 {
1160 }
1161 
1163 {
1164  rStrm.StartRecord( EXC_ID_SXVD, 10 );
1165  rStrm << maFieldInfo;
1166  rStrm.EndRecord();
1167 }
1168 
1170 {
1171  rStrm.StartRecord( EXC_ID_SXVDEX, 20 );
1172  rStrm << maFieldExtInfo;
1173  rStrm.EndRecord();
1174 }
1175 
1176 XclExpPivotTable::XclExpPivotTable( const XclExpRoot& rRoot, const ScDPObject& rDPObj, const XclExpPivotCache& rPCache ) :
1177  XclExpRoot( rRoot ),
1178  mrPCache( rPCache ),
1179  maDataOrientField( *this, EXC_SXIVD_DATA ),
1180  mnOutScTab( 0 ),
1181  mbValid( false ),
1182  mbFilterBtn( false )
1183 {
1184  const ScRange& rOutScRange = rDPObj.GetOutRange();
1185  if( !GetAddressConverter().ConvertRange( maPTInfo.maOutXclRange, rOutScRange, true ) )
1186  return;
1187 
1188  // DataPilot properties -----------------------------------------------
1189 
1190  // pivot table properties from DP object
1191  mnOutScTab = rOutScRange.aStart.Tab();
1192  maPTInfo.maTableName = rDPObj.GetName();
1194 
1195  maPTViewEx9Info.Init( rDPObj );
1196 
1197  const ScDPSaveData* pSaveData = rDPObj.GetSaveData();
1198  if( !pSaveData )
1199  return;
1200 
1201  // additional properties from ScDPSaveData
1202  SetPropertiesFromDP( *pSaveData );
1203 
1204  // loop over all dimensions ---------------------------------------
1205 
1206  /* 1) Default-construct all pivot table fields for all pivot cache fields. */
1207  for( sal_uInt16 nFieldIdx = 0, nFieldCount = mrPCache.GetFieldCount(); nFieldIdx < nFieldCount; ++nFieldIdx )
1208  maFieldList.AppendNewRecord( new XclExpPTField( *this, nFieldIdx ) );
1209 
1210  const ScDPSaveData::DimsType& rDimList = pSaveData->GetDimensions();
1211 
1212  /* 2) First process all data dimensions, they are needed for extended
1213  settings of row/column/page fields (sorting/auto show). */
1214  for (auto const& iter : rDimList)
1215  {
1216  if (iter->GetOrientation() == DataPilotFieldOrientation_DATA)
1218  }
1219 
1220  /* 3) Row/column/page/hidden fields. */
1221  for (auto const& iter : rDimList)
1222  {
1223  if (iter->GetOrientation() != DataPilotFieldOrientation_DATA)
1225  }
1226 
1227  // Finalize -------------------------------------------------------
1228 
1229  Finalize();
1230  mbValid = true;
1231 }
1232 
1233 const XclExpPCField* XclExpPivotTable::GetCacheField( sal_uInt16 nCacheIdx ) const
1234 {
1235  return mrPCache.GetField( nCacheIdx );
1236 }
1237 
1238 const XclExpPTField* XclExpPivotTable::GetField( sal_uInt16 nFieldIdx ) const
1239 {
1240  return (nFieldIdx == EXC_SXIVD_DATA) ? &maDataOrientField : maFieldList.GetRecord( nFieldIdx );
1241 }
1242 
1243 const XclExpPTField* XclExpPivotTable::GetField( const OUString& rName ) const
1244 {
1245  return const_cast< XclExpPivotTable* >( this )->GetFieldAcc( rName );
1246 }
1247 
1248 sal_uInt16 XclExpPivotTable::GetDataFieldIndex( const OUString& rName, sal_uInt16 nDefaultIdx ) const
1249 {
1250  auto aIt = std::find_if(maDataFields.begin(), maDataFields.end(),
1251  [this, &rName](const XclPTDataFieldPos& rDataField) {
1252  const XclExpPTField* pField = GetField( rDataField.first );
1253  return pField && pField->GetFieldName() == rName;
1254  });
1255  if (aIt != maDataFields.end())
1256  return static_cast< sal_uInt16 >( std::distance(maDataFields.begin(), aIt) );
1257  return nDefaultIdx;
1258 }
1259 
1261 {
1262  if( !mbValid )
1263  return;
1264 
1265  // SXVIEW
1266  WriteSxview( rStrm );
1267  // pivot table fields (SXVD, SXVDEX, and item records)
1268  maFieldList.Save( rStrm );
1269  // SXIVD records for row and column fields
1270  WriteSxivd( rStrm, maRowFields );
1271  WriteSxivd( rStrm, maColFields );
1272  // SXPI
1273  WriteSxpi( rStrm );
1274  // list of SXDI records containing data field info
1275  WriteSxdiList( rStrm );
1276  // SXLI records
1279  // SXEX
1280  WriteSxex( rStrm );
1281  // QSISXTAG
1282  WriteQsiSxTag( rStrm );
1283  // SXVIEWEX9
1284  WriteSxViewEx9( rStrm );
1285 }
1286 
1288 {
1289  XclExpPTField* pField = nullptr;
1290  for( size_t nPos = 0, nSize = maFieldList.GetSize(); !pField && (nPos < nSize); ++nPos )
1291  if( maFieldList.GetRecord( nPos )->GetFieldName() == rName )
1292  pField = maFieldList.GetRecord( nPos );
1293  return pField;
1294 }
1295 
1297 {
1298  // data field orientation field?
1299  if( rSaveDim.IsDataLayout() )
1300  return &maDataOrientField;
1301 
1302  // a real dimension
1303  OUString aFieldName = ScDPUtil::getSourceDimensionName(rSaveDim.GetName());
1304  return aFieldName.isEmpty() ? nullptr : GetFieldAcc(aFieldName);
1305 }
1306 
1307 // fill data --------------------------------------------------------------
1308 
1310 {
1314  mbFilterBtn = rSaveData.GetFilterButton();
1315  const ScDPSaveDimension* pDim = rSaveData.GetExistingDataLayoutDimension();
1316 
1317  if (pDim && pDim->GetLayoutName())
1318  maPTInfo.maDataName = *pDim->GetLayoutName();
1319  else
1320  maPTInfo.maDataName = ScResId(STR_PIVOT_DATA);
1321 }
1322 
1324 {
1325  XclExpPTField* pField = GetFieldAcc( rSaveDim );
1326  if(!pField)
1327  return;
1328 
1329  // field properties
1330  pField->SetPropertiesFromDim( rSaveDim );
1331 
1332  // update the corresponding field position list
1333  DataPilotFieldOrientation eOrient = rSaveDim.GetOrientation();
1334  sal_uInt16 nFieldIdx = pField->GetFieldIndex();
1335  bool bDataLayout = nFieldIdx == EXC_SXIVD_DATA;
1336  bool bMultiData = maDataFields.size() > 1;
1337 
1338  if( bDataLayout && !bMultiData )
1339  return;
1340 
1341  switch( eOrient )
1342  {
1343  case DataPilotFieldOrientation_ROW:
1344  maRowFields.push_back( nFieldIdx );
1345  if( bDataLayout )
1347  break;
1348  case DataPilotFieldOrientation_COLUMN:
1349  maColFields.push_back( nFieldIdx );
1350  if( bDataLayout )
1352  break;
1353  case DataPilotFieldOrientation_PAGE:
1354  maPageFields.push_back( nFieldIdx );
1355  OSL_ENSURE( !bDataLayout, "XclExpPivotTable::SetFieldPropertiesFromDim - wrong orientation for data fields" );
1356  break;
1357  case DataPilotFieldOrientation_DATA:
1358  OSL_FAIL( "XclExpPivotTable::SetFieldPropertiesFromDim - called for data field" );
1359  break;
1360  default:;
1361  }
1362 }
1363 
1365 {
1366  if( XclExpPTField* pField = GetFieldAcc( rSaveDim ) )
1367  {
1368  // field properties
1369  pField->SetDataPropertiesFromDim( rSaveDim );
1370  // update the data field position list
1371  maDataFields.emplace_back( pField->GetFieldIndex(), pField->GetLastDataInfoIndex() );
1372  }
1373 }
1374 
1376 {
1377  // field numbers
1378  maPTInfo.mnFields = static_cast< sal_uInt16 >( maFieldList.GetSize() );
1379  maPTInfo.mnRowFields = static_cast< sal_uInt16 >( maRowFields.size() );
1380  maPTInfo.mnColFields = static_cast< sal_uInt16 >( maColFields.size() );
1381  maPTInfo.mnPageFields = static_cast< sal_uInt16 >( maPageFields.size() );
1382  maPTInfo.mnDataFields = static_cast< sal_uInt16 >( maDataFields.size() );
1383 
1386 
1387  // subtotal items
1388  for( size_t nPos = 0, nSize = maFieldList.GetSize(); nPos < nSize; ++nPos )
1390 
1391  // find data field orientation field
1393  const ScfUInt16Vec* pFieldVec = nullptr;
1394  switch( maPTInfo.mnDataAxis )
1395  {
1396  case EXC_SXVD_AXIS_ROW: pFieldVec = &maRowFields; break;
1397  case EXC_SXVD_AXIS_COL: pFieldVec = &maColFields; break;
1398  }
1399 
1400  if( pFieldVec && !pFieldVec->empty() && (pFieldVec->back() != EXC_SXIVD_DATA) )
1401  {
1402  ScfUInt16Vec::const_iterator aIt = ::std::find( pFieldVec->begin(), pFieldVec->end(), EXC_SXIVD_DATA );
1403  if( aIt != pFieldVec->end() )
1404  maPTInfo.mnDataPos = static_cast< sal_uInt16 >( std::distance(pFieldVec->begin(), aIt) );
1405  }
1406 
1407  // single data field is always row oriented
1410 
1411  // update output range (initialized in ctor)
1412  sal_uInt16& rnXclCol1 = maPTInfo.maOutXclRange.maFirst.mnCol;
1413  sal_uInt32& rnXclRow1 = maPTInfo.maOutXclRange.maFirst.mnRow;
1414  sal_uInt16& rnXclCol2 = maPTInfo.maOutXclRange.maLast.mnCol;
1415  sal_uInt32& rnXclRow2 = maPTInfo.maOutXclRange.maLast.mnRow;
1416  // exclude page fields from output range
1417  rnXclRow1 = rnXclRow1 + maPTInfo.mnPageFields;
1418  // exclude filter button from output range
1419  if( mbFilterBtn )
1420  ++rnXclRow1;
1421  // exclude empty row between (filter button and/or page fields) and table
1423  ++rnXclRow1;
1424 
1425  // data area
1426  sal_uInt16& rnDataXclCol = maPTInfo.maDataXclPos.mnCol;
1427  sal_uInt32& rnDataXclRow = maPTInfo.maDataXclPos.mnRow;
1428  rnDataXclCol = rnXclCol1 + maPTInfo.mnRowFields;
1429  rnDataXclRow = rnXclRow1 + maPTInfo.mnColFields + 1;
1430  if( maDataFields.empty() )
1431  ++rnDataXclRow;
1432 
1433  bool bExtraHeaderRow = (0 == maPTViewEx9Info.mnGridLayout && maPTInfo.mnColFields == 0);
1434  if (bExtraHeaderRow)
1435  // Insert an extra row only when there is no column field.
1436  ++rnDataXclRow;
1437 
1438  rnXclCol2 = ::std::max( rnXclCol2, rnDataXclCol );
1439  rnXclRow2 = ::std::max( rnXclRow2, rnDataXclRow );
1440  maPTInfo.mnDataCols = rnXclCol2 - rnDataXclCol + 1;
1441  maPTInfo.mnDataRows = rnXclRow2 - rnDataXclRow + 1;
1442 
1443  // first heading
1444  maPTInfo.mnFirstHeadRow = rnXclRow1 + 1;
1445  if (bExtraHeaderRow)
1446  maPTInfo.mnFirstHeadRow += 1;
1447 }
1448 
1449 // records ----------------------------------------------------------------
1450 
1452 {
1453  rStrm.StartRecord( EXC_ID_SXVIEW, 46 + maPTInfo.maTableName.getLength() + maPTInfo.maDataName.getLength() );
1454  rStrm << maPTInfo;
1455  rStrm.EndRecord();
1456 }
1457 
1459 {
1460  if( !rFields.empty() )
1461  {
1462  rStrm.StartRecord( EXC_ID_SXIVD, rFields.size() * 2 );
1463  for( const auto& rField : rFields )
1464  rStrm << rField;
1465  rStrm.EndRecord();
1466  }
1467 }
1468 
1470 {
1471  if( !maPageFields.empty() )
1472  {
1473  rStrm.StartRecord( EXC_ID_SXPI, maPageFields.size() * 6 );
1474  rStrm.SetSliceSize( 6 );
1475  for( const auto& rPageField : maPageFields )
1476  {
1477  XclExpPTFieldRef xField = maFieldList.GetRecord( rPageField );
1478  if( xField )
1479  xField->WriteSxpiEntry( rStrm );
1480  }
1481  rStrm.EndRecord();
1482  }
1483 }
1484 
1486 {
1487  for( const auto& [rFieldIdx, rDataInfoIdx] : maDataFields )
1488  {
1489  XclExpPTFieldRef xField = maFieldList.GetRecord( rFieldIdx );
1490  if( xField )
1491  xField->WriteSxdi( rStrm, rDataInfoIdx );
1492  }
1493 }
1494 
1495 void XclExpPivotTable::WriteSxli( XclExpStream& rStrm, sal_uInt16 nLineCount, sal_uInt16 nIndexCount )
1496 {
1497  if( nLineCount <= 0 )
1498  return;
1499 
1500  std::size_t nLineSize = 8 + 2 * nIndexCount;
1501  rStrm.StartRecord( EXC_ID_SXLI, nLineSize * nLineCount );
1502 
1503  /* Excel expects the records to be filled completely, do not
1504  set a segment size... */
1505 // rStrm.SetSliceSize( nLineSize );
1506 
1507  for( sal_uInt16 nLine = 0; nLine < nLineCount; ++nLine )
1508  {
1509  // Excel XP needs a partly initialized SXLI record
1510  rStrm << sal_uInt16( 0 ) // number of equal index entries
1512  << nIndexCount
1514  rStrm.WriteZeroBytes( 2 * nIndexCount );
1515  }
1516  rStrm.EndRecord();
1517 }
1518 
1520 {
1521  rStrm.StartRecord( EXC_ID_SXEX, 24 );
1522  rStrm << maPTExtInfo;
1523  rStrm.EndRecord();
1524 }
1525 
1527 {
1528  rStrm.StartRecord( 0x0802, 32 );
1529 
1530  sal_uInt16 const nRecordType = 0x0802;
1531  sal_uInt16 const nDummyFlags = 0x0000;
1532  sal_uInt16 const nTableType = 1; // 0 = query table : 1 = pivot table
1533 
1534  rStrm << nRecordType << nDummyFlags << nTableType;
1535 
1536  // General flags
1537  sal_uInt16 const nFlags = 0x0001;
1538 #if 0
1539  // for doc purpose
1540  sal_uInt16 nFlags = 0x0000;
1541  bool bEnableRefresh = true;
1542  bool bPCacheInvalid = false;
1543  bool bOlapPTReport = false;
1544 
1545  if (bEnableRefresh) nFlags |= 0x0001;
1546  if (bPCacheInvalid) nFlags |= 0x0002;
1547  if (bOlapPTReport) nFlags |= 0x0004;
1548 #endif
1549  rStrm << nFlags;
1550 
1551  // Feature-specific options. The value differs depending on the table
1552  // type, but we assume the table type is always pivot table.
1553  sal_uInt32 const nOptions = 0x00000000;
1554 #if 0
1555  // documentation for which bit is for what
1556  bool bNoStencil = false;
1557  bool bHideTotal = false;
1558  bool bEmptyRows = false;
1559  bool bEmptyCols = false;
1560  if (bNoStencil) nOptions |= 0x00000001;
1561  if (bHideTotal) nOptions |= 0x00000002;
1562  if (bEmptyRows) nOptions |= 0x00000008;
1563  if (bEmptyCols) nOptions |= 0x00000010;
1564 #endif
1565  rStrm << nOptions;
1566 
1567  sal_uInt8 eXclVer = 0; // Excel2000
1568  sal_uInt8 const nOffsetBytes = 16;
1569  rStrm << eXclVer // version table last refreshed
1570  << eXclVer // minimum version to refresh
1571  << nOffsetBytes
1572  << eXclVer; // first version created
1573 
1574  rStrm << XclExpString(maPTInfo.maTableName);
1575  rStrm << static_cast<sal_uInt16>(0x0001); // no idea what this is for.
1576 
1577  rStrm.EndRecord();
1578 }
1579 
1581 {
1582  // Until we sync the autoformat ids only export if using grid header layout
1583  // That could only have been set via xls import so far.
1584  if ( 0 == maPTViewEx9Info.mnGridLayout )
1585  {
1586  rStrm.StartRecord( EXC_ID_SXVIEWEX9, 17 );
1587  rStrm << maPTViewEx9Info;
1588  rStrm.EndRecord();
1589  }
1590 }
1591 
1592 namespace {
1593 
1594 const SCTAB EXC_PTMGR_PIVOTCACHES = SCTAB_MAX;
1595 
1597 class XclExpPivotRecWrapper : public XclExpRecordBase
1598 {
1599 public:
1600  explicit XclExpPivotRecWrapper( XclExpPivotTableManager& rPTMgr, SCTAB nScTab );
1601  virtual void Save( XclExpStream& rStrm ) override;
1602 private:
1603  XclExpPivotTableManager& mrPTMgr;
1604  SCTAB mnScTab;
1605 };
1606 
1607 XclExpPivotRecWrapper::XclExpPivotRecWrapper( XclExpPivotTableManager& rPTMgr, SCTAB nScTab ) :
1608  mrPTMgr( rPTMgr ),
1609  mnScTab( nScTab )
1610 {
1611 }
1612 
1613 void XclExpPivotRecWrapper::Save( XclExpStream& rStrm )
1614 {
1615  if( mnScTab == EXC_PTMGR_PIVOTCACHES )
1616  mrPTMgr.WritePivotCaches( rStrm );
1617  else
1618  mrPTMgr.WritePivotTables( rStrm, mnScTab );
1619 }
1620 
1621 } // namespace
1622 
1624  XclExpRoot( rRoot )
1625 {
1626 }
1627 
1629 {
1630  if( ScDPCollection* pDPColl = GetDoc().GetDPCollection() )
1631  for( size_t nDPObj = 0, nCount = pDPColl->GetCount(); nDPObj < nCount; ++nDPObj )
1632  {
1633  ScDPObject& rDPObj = (*pDPColl)[ nDPObj ];
1634  if( const XclExpPivotCache* pPCache = CreatePivotCache( rDPObj ) )
1635  maPTableList.AppendNewRecord( new XclExpPivotTable( GetRoot(), rDPObj, *pPCache ) );
1636  }
1637 }
1638 
1640 {
1641  return new XclExpPivotRecWrapper( *this, EXC_PTMGR_PIVOTCACHES );
1642 }
1643 
1645 {
1646  return new XclExpPivotRecWrapper( *this, nScTab );
1647 }
1648 
1650 {
1651  maPCacheList.Save( rStrm );
1652 }
1653 
1655 {
1656  for( size_t nPos = 0, nSize = maPTableList.GetSize(); nPos < nSize; ++nPos )
1657  {
1659  if( xPTable->GetScTab() == nScTab )
1660  xPTable->Save( rStrm );
1661  }
1662 }
1663 
1665 {
1666  // try to find a pivot cache with the same data source
1667  /* #i25110# In Excel, the pivot cache contains additional fields
1668  (i.e. grouping info, calculated fields). If the passed DataPilot object
1669  or the found cache contains this data, do not share the cache with
1670  multiple pivot tables. */
1671  if( const ScDPSaveData* pSaveData = rDPObj.GetSaveData() )
1672  {
1673  const ScDPDimensionSaveData* pDimSaveData = pSaveData->GetExistingDimensionData();
1674  // no dimension save data at all or save data does not contain grouping info
1675  if( !pDimSaveData || !pDimSaveData->HasGroupDimensions() )
1676  {
1677  // check all existing pivot caches
1678  for( size_t nPos = 0, nSize = maPCacheList.GetSize(); nPos < nSize; ++nPos )
1679  {
1681  // pivot cache does not have grouping info and source data is equal
1682  if( !pPCache->HasAddFields() && pPCache->HasEqualDataSource( rDPObj ) )
1683  return pPCache;
1684  }
1685  }
1686  }
1687 
1688  // create a new pivot cache
1689  sal_uInt16 nNewCacheIdx = static_cast< sal_uInt16 >( maPCacheList.GetSize() );
1690  XclExpPivotCacheRef xNewPCache = new XclExpPivotCache( GetRoot(), rDPObj, nNewCacheIdx );
1691  if( xNewPCache->IsValid() )
1692  {
1693  maPCacheList.AppendRecord( xNewPCache.get() );
1694  return xNewPCache.get();
1695  }
1696 
1697  return nullptr;
1698 }
1699 
1700 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt32 mnFlags
Definition: xlpivot.hxx:623
SC_DLLPUBLIC bool GetPrintArea(SCTAB nTab, SCCOL &rEndCol, SCROW &rEndRow, bool bNotes=true) const
Definition: documen2.cxx:573
sal_uInt16 mnRefItem
Index to SXVD of referred field used for the results.
Definition: xlpivot.hxx:679
const XclExpPCField * mpCacheField
Parent pivot table containing this field.
Definition: xepivot.hxx:308
static OUString EncodeUrl(const XclExpRoot &rRoot, const OUString &rAbsUrl, const OUString *pTableName=nullptr)
Encodes and returns the URL passed in rAbsUrl to an Excel like URL.
Definition: xehelper.cxx:976
void AppendSubtotalItems()
Appends special items describing the field subtotal entries.
Definition: xepivot.cxx:1101
void SetApiLayoutMode(sal_Int32 nLayoutMode)
Sets the layout mode represented by the passed API constant.
Definition: xlpivot.cxx:625
void InsertItemArrayIndex(size_t nListPos)
Inserts the passed index into the item index array of original items.
Definition: xepivot.cxx:442
bool is() const
This class stores an unformatted or formatted string for Excel export.
Definition: xestring.hxx:43
virtual const ScDPItemData * GetMemberById(long nDim, long nId)
Definition: dptabdat.cxx:258
const ScDPDimensionSaveData * GetExistingDimensionData() const
Definition: dpsave.hxx:348
bool IsStdGroupField() const
Returns true, if this field is a grouping field.
Definition: xlpivot.cxx:303
sal_uInt16 GetItemCount() const
Returns the number of visible items of this field.
Definition: xepivot.cxx:261
void SetPropertiesFromDim(const ScDPSaveDimension &rSaveDim)
Fills this field with row/column/page properties from the passed save dimension.
Definition: xepivot.cxx:999
const OUString & GetGroupDimName() const
Definition: dpdimsave.hxx:104
const sal_uInt16 EXC_ID_SXPI
Definition: xlpivot.hxx:172
virtual void Save(XclExpStream &rStrm) override
Writes the complete record list.
Definition: xerecord.hxx:376
const sal_uInt16 EXC_SXFIELD_16BIT
Definition: xlpivot.hxx:229
sal_uInt16 mnFlags
Type of the item (e.g. data, function, grand total).
Definition: xlpivot.hxx:578
std::vector< XclPTDataFieldInfo > maDataInfoVec
Page field info (entry in SXPI record).
Definition: xepivot.hxx:313
const sal_uInt32 EXC_SXVDEX_LAYOUT_BLANK
Definition: xlpivot.hxx:339
ScRange maExpSrcRange
The original sheet source range.
Definition: xepivot.hxx:216
XclExpPTField maDataOrientField
Data field indexes.
Definition: xepivot.hxx:393
bool HasAddFields() const
Returns true, if this pivot cache contains non-standard fields (e.g.
Definition: xepivot.cxx:692
const std::optional< OUString > & GetLayoutName() const
Definition: dpsave.cxx:384
bool GetRowGrand() const
Definition: dpsave.hxx:326
bool IsGroupField() const
Returns true, if this field is a grouping field of any type.
Definition: xlpivot.cxx:318
bool HasEqualDataSource(const ScDPObject &rDPObj) const
Returns true, if the passed DP object has the same data source as this cache.
Definition: xepivot.cxx:698
void WriteSxdiList(XclExpStream &rStrm) const
Writes all SXDI records containing info about the data fields.
Definition: xepivot.cxx:1485
XclExpPCItem(const OUString &rText)
Definition: xepivot.cxx:94
const sal_uInt16 EXC_SXFIELD_DATA_DBL
Only integers, opt. with doubles.
Definition: xlpivot.hxx:236
sal_Int32 nIndex
ScAddress aStart
Definition: address.hxx:500
void SetApiAggFunc(ScGeneralFunction eAggFunc)
Sets the aggregation function represented by the passed API enum.
Definition: xlpivot.cxx:731
SC_DLLPUBLIC bool GetDataStart(SCTAB nTab, SCCOL &rStartCol, SCROW &rStartRow) const
Definition: documen2.cxx:641
void SetGroupChildField(const XclExpPCField &rChildField)
Sets the passed field as direct grouping child field of this field.
Definition: xepivot.cxx:253
const double * GetDouble() const
Returns pointer to value, if the item type is 'double', otherwise 0.
Definition: xlpivot.cxx:140
const sal_uInt16 EXC_SXFIELD_DATA_NONE
Definition: xlpivot.hxx:233
virtual void Save(XclExpStream &rStrm) override
Writes the pivot cache field and all items and other related records.
Definition: xepivot.cxx:298
This class has to do with handling exclusively grouped dimensions? TODO: Find out what this class doe...
Definition: dpdimsave.hxx:160
bool IsExportTab(SCTAB nScTab) const
Returns true, if the specified Calc sheet will be exported.
Definition: xelink.cxx:771
const sal_uInt16 EXC_ID_SXIVD
Definition: xlpivot.hxx:164
#define EMPTY_OUSTRING
Definition: global.hxx:214
void SetScDateType(sal_Int32 nScType)
Definition: xlpivot.cxx:242
XclPTExtInfo maPTExtInfo
Info about the pivot table (SXVIEW record).
Definition: xepivot.hxx:385
std::optional< OUString > mpFieldTotalName
Definition: xlpivot.hxx:627
This class is used to export Excel record streams.
Definition: xestream.hxx:71
SCROW Row() const
Definition: address.hxx:262
sal_uInt16 mnSrcType
Number of all fields (standard, grouped, calculated).
Definition: xlpivot.hxx:534
const sal_uInt32 EXC_SXVDEX_AUTOSHOW
Definition: xlpivot.hxx:336
bool HasGroupDimensions() const
Definition: dpdimsave.cxx:694
void SetFieldPropertiesFromDim(const ScDPSaveDimension &rSaveDim)
Fills a pivot table field with all properties from the passed save dimension.
Definition: xepivot.cxx:1323
std::unique_ptr< ContentProperties > pData
bool mbUseCache
The visible name, if used.
Definition: xlpivot.hxx:551
const MemberList & GetMembers() const
Definition: dpsave.hxx:128
css::sheet::DataPilotFieldOrientation GetOrientation() const
Definition: dpsave.hxx:202
ScfUInt16Vec maIndexVec
List with grouping items.
Definition: xepivot.hxx:151
const sal_uInt16 EXC_ID_SXVS
Definition: xlpivot.hxx:297
const ScDPSaveGroupDimension * GetGroupDimForBase(const OUString &rBaseDimName) const
Definition: dpdimsave.cxx:632
void AppendRecord(RecType *pRec)
Appends a record to the list.
Definition: xerecord.hxx:349
sal_uInt16 mnCacheIdx
Number of items of this field.
Definition: xlpivot.hxx:598
sal_uInt16 mnRefField
Result reference type.
Definition: xlpivot.hxx:678
const sal_uInt16 EXC_SXPI_ALLITEMS
Definition: xlpivot.hxx:173
Implementation of ScDPTableData with sheet data.
Definition: dpshttab.hxx:86
const sal_uInt16 EXC_SXVI_HIDDEN
Definition: xlpivot.hxx:156
const sal_uInt16 EXC_SXVI_TYPE_STDDEVP
Definition: xlpivot.hxx:150
const SfxPoolItem * GetItem(const SwTextAttr &rAttr, sal_uInt16 nWhich)
void SetDateTime(const DateTime &rDateTime, const OUString &rText=OUString())
Sets the item to 'date/time' type and adds the passed date.
Definition: xlpivot.cxx:74
void WriteSxpi(XclExpStream &rStrm) const
Writes the SXPI record containing page field info.
Definition: xepivot.cxx:1469
void CreatePivotTables()
Creates all pivot tables and caches from the Calc DataPilot objects.
Definition: xepivot.cxx:1628
bool GetIsVisible() const
Definition: dpsave.hxx:71
XclExpPivotTable(const XclExpRoot &rRoot, const ScDPObject &rDPObj, const XclExpPivotCache &rPCache)
Definition: xepivot.cxx:1176
const css::sheet::DataPilotFieldLayoutInfo * GetLayoutInfo() const
Definition: dpsave.hxx:194
const bool * GetBool() const
Returns pointer to Boolean value, if the item type is 'boolean', otherwise 0.
Definition: xlpivot.cxx:160
Classes to save Data Pilot settings that create new dimensions (fields).
Definition: dpdimsave.hxx:43
const OUString & GetGroupName() const
Definition: dpdimsave.hxx:62
std::size_t GetIndexSize() const
Returns the size an item index needs to write out.
Definition: xepivot.cxx:280
void WriteSxex(XclExpStream &rStrm) const
Writes the SXEX records containing additional pivot table info.
Definition: xepivot.cxx:1519
sal_uInt16 mnColFields
Number of row fields.
Definition: xlpivot.hxx:718
sal_Int64 n
const XclExpPivotTable & mrPTable
Definition: xepivot.hxx:307
void SetApiRefItemType(sal_Int32 nRefItemType)
Sets the result reference item type represented by the passed API constant.
Definition: xlpivot.cxx:798
const OUString & GetSourceDimName() const
Definition: dpdimsave.hxx:105
const sal_uInt16 EXC_SXFIELD_DATA_DATE
Only strings and doubles, nothing else.
Definition: xlpivot.hxx:239
aBuf
SvNumFormatType GetType(sal_uInt32 nFIndex) const
sal_uInt16 mnCacheIdx
Several flags.
Definition: xlpivot.hxx:579
const XclExpPCItem * mpCacheItem
Definition: xepivot.hxx:248
XclExpPCItemList maGroupItemList
List with original items.
Definition: xepivot.hxx:150
XclExpRecordList< XclExpPivotCache > maPCacheList
Definition: xepivot.hxx:433
sal_uInt16 mnGroupItems
Number of visible items for this field.
Definition: xlpivot.hxx:443
Numeric grouping field.
Definition: xlpivot.hxx:86
static void WriteSxivd(XclExpStream &rStrm, const ScfUInt16Vec &rFields)
Writes an SXIVD record for row field or column field order.
Definition: xepivot.cxx:1458
void SetPropertiesFromMember(const ScDPSaveMember &rSaveMem)
Fills this item with properties from the passed save member.
Definition: xepivot.cxx:919
void SetText(const OUString &rText)
Sets the item to 'text' type and adds the passed text.
Definition: xlpivot.cxx:61
ScAddress aEnd
Definition: address.hxx:501
void set_flag(Type &rnBitField, Type nMask, bool bSet=true)
Sets or clears (according to bSet) all set bits of nMask in rnBitField.
Definition: ftools.hxx:93
XclAddress maLast
Definition: xladdress.hxx:61
const sal_uInt16 EXC_SXVD_AXIS_COL
Definition: xlpivot.hxx:113
sal_uInt32 mnRow
Definition: xladdress.hxx:33
long GetSubTotalsCount() const
Definition: dpsave.hxx:149
XclAddress maDataXclPos
Output range.
Definition: xlpivot.hxx:711
numerical values are counted.
ScfUInt16Vec maRowFields
All fields in pivot cache order.
Definition: xepivot.hxx:388
static OUString GetHexStr(sal_uInt16 nValue)
Returns a string representing the hexadecimal value of nValue.
Definition: ftools.cxx:117
Standard field without grouping.
Definition: xlpivot.hxx:84
const sal_uInt16 EXC_SXVDEX_SHOW_NONE
Definition: xlpivot.hxx:344
void SetSubtotals(const XclPTSubtotalVec &rSubtotals)
Sets the subtotal functions contained in the passed sequence.
Definition: xlpivot.cxx:518
ReturnType limit_cast(Type nValue, ReturnType nMin, ReturnType nMax)
Returns the value, if it is not less than nMin and not greater than nMax, otherwise one of the limits...
Definition: ftools.hxx:61
const sal_uInt16 EXC_ID_SXINDEXLIST
List index for step item in groupings.
Definition: xlpivot.hxx:249
sum of all numerical values is calculated.
XclAddress maFirst
Definition: xladdress.hxx:60
bool mbFilterBtn
true = The pivot table is valid for export.
Definition: xepivot.hxx:396
bool IsDataLayout() const
Definition: dpsave.hxx:142
ScDocument & GetDoc() const
Returns reference to the destination document (import) or source document (export).
Definition: xlroot.cxx:276
sal_uInt16 mnGroupChild
Various flags.
Definition: xlpivot.hxx:440
SvNumberFormatter & GetFormatter() const
Returns the number formatter of the Calc document.
Definition: xlroot.cxx:313
This class represents the cached data part of the datapilot cache table implementation.
Definition: dpcache.hxx:47
const XclExpPCItem * GetItem(sal_uInt16 nItemIdx) const
Returns the specified pivot cache item (returns visible items in groupings).
Definition: xepivot.cxx:266
Represents a field in a pivot cache.
Definition: xlpivot.hxx:477
const sal_uInt16 EXC_ID_DCONNAME
Definition: xlpivot.hxx:95
void SetBool(bool bValue, const OUString &rText=OUString())
Sets the item to 'boolean' type and adds the passed Boolean value.
Definition: xlpivot.cxx:106
sal_uInt16 GetItemIndex(const OUString &rName, sal_uInt16 nDefaultIdx) const
Returns the list index of an item by its name.
Definition: xepivot.cxx:964
bool EqualsText(const OUString &rText) const
Definition: xepivot.cxx:133
tools::SvRef< SotStorage > OpenStorage(tools::SvRef< SotStorage > const &xStrg, const OUString &rStrgName) const
Tries to open a storage as child of the specified storage for reading or writing. ...
Definition: xlroot.cxx:252
void Init(const ScDPObject &rDPObj)
Definition: xlpivot.cxx:976
void SetApiSortMode(sal_Int32 nSortMode)
Sets the sorting mode represented by the passed API constant.
Definition: xlpivot.cxx:587
void WriteSxpiEntry(XclExpStream &rStrm) const
Writes an entry for an SXPI record containing own page field info.
Definition: xepivot.cxx:1119
sal_uInt16 mnFlags
Number of columns containing data.
Definition: xlpivot.hxx:723
virtual void WriteBody(XclExpStream &rStrm) override
Writes the body of the record (without record header).
Definition: xepivot.cxx:153
void WritePivotTables(XclExpStream &rStrm, SCTAB nScTab)
Writes all pivot tables of the specified Calc sheet.
Definition: xepivot.cxx:1654
OUString GetFieldName() const
Returns the name of this field.
Definition: xepivot.cxx:952
sal_uInt16 mnVisItems
Base field if this field contains grouping info.
Definition: xlpivot.hxx:442
XclExpRecordRef CreatePivotCachesRecord()
Creates a record wrapper for exporting all pivot caches.
Definition: xepivot.cxx:1639
const sal_uInt16 EXC_SXVI_TYPE_DATA
Definition: xlpivot.hxx:140
XclExpPTItem * GetItemAcc(const OUString &rName)
Returns an item by its name.
Definition: xepivot.cxx:1147
product of all numerical values is calculated.
const OUString & GetFieldName() const
Returns the name of this cache field.
Definition: xepivot.hxx:78
const sal_uInt16 EXC_SXVD_SUBT_COUNTNUM
Definition: xlpivot.hxx:127
const sal_uInt16 EXC_ID_SXLI
Definition: xlpivot.hxx:168
const sal_uInt16 EXC_SXVD_SUBT_STDDEV
Definition: xlpivot.hxx:128
const sal_uInt16 EXC_SXVD_SUBT_DEFAULT
Definition: xlpivot.hxx:120
XclPTPageFieldInfo maPageInfo
Extended field info (SXVDEX record).
Definition: xepivot.hxx:311
const sal_uInt16 EXC_SXVI_HIDEDETAIL
Definition: xlpivot.hxx:157
long GetGroupCount() const
Definition: dpdimsave.cxx:200
static OUString lcl_convertCalcSubtotalName(const OUString &rName)
Calc's subtotal names are escaped with backslashes ('\'), while Excel's are not escaped at all...
Definition: xepivot.cxx:978
sal_uInt16 mnFields
Position of data fields.
Definition: xlpivot.hxx:716
sal_uInt16 sal_Unicode
const sal_uInt16 EXC_ID_SXGROUPINFO
Definition: xlpivot.hxx:291
ScfUInt16Vec maGroupOrder
Own field index in pivot cache.
Definition: xlpivot.hxx:519
Access to global data from other classes.
Definition: xeroot.hxx:113
virtual void Save(XclExpStream &rStrm) override
Writes the entire pivot table field.
Definition: xepivot.cxx:1135
XclExpPTItem(const XclExpPCField &rCacheField, sal_uInt16 nCacheIdx)
Definition: xepivot.cxx:896
const ScRange & GetOutRange() const
Definition: dpobject.cxx:409
const sal_uInt16 EXC_SXVI_TYPE_VARP
Definition: xlpivot.hxx:152
const sal_uInt16 EXC_SXVS_SHEET
Definition: xlpivot.hxx:300
sal_uInt16 mnStdFields
Records in a source database block.
Definition: xlpivot.hxx:532
SCTAB mnOutScTab
Special data field orientation field.
Definition: xepivot.hxx:394
const XclExpPCField * GetField(sal_uInt16 nFieldIdx) const
Returns the specified pivot cache field.
Definition: xepivot.cxx:687
XclExpRecordList< XclExpPTItem > maItemList
List of extended data field info (SXDI records).
Definition: xepivot.hxx:315
const sal_uInt16 EXC_SXVI_TYPE_DEFAULT
Definition: xlpivot.hxx:141
XclExpPCItemList maOrigItemList
Definition: xepivot.hxx:149
sal_uInt16 InsertGroupItem(XclExpPCItem *pNewItem)
Inserts an item into the grouping item list.
Definition: xepivot.cxx:502
sal_uInt16 mnDataRows
Number of data fields.
Definition: xlpivot.hxx:721
int nCount
void AddApiOrient(css::sheet::DataPilotFieldOrientation eOrient)
Adds the axis orientation represented by the passed API enum.
Definition: xlpivot.cxx:485
sal_uInt16 mnDataFields
Number of page fields.
Definition: xlpivot.hxx:720
const sal_uInt16 EXC_PC_NOITEM
Definition: xlpivot.hxx:52
bool HasItemIndexList() const
Returns true, if the item index list will be written.
Definition: xepivot.cxx:677
void SetNumGroupLimit(const ScDPNumGroupInfo &rNumInfo)
Inserts the SXDOUBLE items that specify the limits for a numeric grouping.
Definition: xepivot.cxx:544
void WriteSxvdex(XclExpStream &rStrm) const
Writes the SXVDEX record containing additional settings.
Definition: xepivot.cxx:1169
const sal_uInt16 EXC_SXNUMGROUP_AUTOMAX
Definition: xlpivot.hxx:279
sal_uInt16 mnCacheIdx
First heading row.
Definition: xlpivot.hxx:713
SCTAB Tab() const
Definition: address.hxx:271
variance is calculated based on the entire population.
const XclExpPivotCache * CreatePivotCache(const ScDPObject &rDPObj)
Finds an existing (if enabled in mbShareCaches) or creates a new pivot cache.
Definition: xepivot.cxx:1664
void SetRow(SCROW nRowP)
Definition: address.hxx:275
Base class for all Excel records.
Definition: xerecord.hxx:39
sal_uInt16 mnShowField
Index to data field sorting bases on.
Definition: xlpivot.hxx:625
void WriteSxdi(XclExpStream &rStrm, sal_uInt16 nDataInfoIdx) const
Writes an SXDI records containing info about a data field.
Definition: xepivot.cxx:1124
SC_DLLPUBLIC const ScRange & GetSourceRange() const
Get the range that contains the source data.
Definition: dpshttab.cxx:229
ScGeneralFunction GetFunction() const
Definition: dpsave.hxx:165
sal_uInt16 mnGroupBase
Field containing grouping info for this field.
Definition: xlpivot.hxx:441
const sal_uInt32 EXC_SXEX_DRILLDOWN
Definition: xlpivot.hxx:312
bool HasShowEmpty() const
Definition: dpsave.cxx:328
Standard grouping field.
Definition: xlpivot.hxx:85
void SetInteger(sal_Int16 nValue)
Sets the item to 'integer' type and adds the passed value.
Definition: xlpivot.cxx:81
First date grouping field (opt. with child grouping field).
Definition: xlpivot.hxx:87
bool EqualsDateTime(const DateTime &rDateTime) const
Definition: xepivot.cxx:143
sal_uInt16 mnField
Definition: xlpivot.hxx:660
XclPTCachedName maVisName
Definition: xlpivot.hxx:562
sal_uInt16 GetTypeFlag() const
Definition: xepivot.hxx:46
::std::vector< ScGeneralFunction > XclPTSubtotalVec
Definition: xlpivot.hxx:589
const sal_uInt16 EXC_SXVD_SUBT_MIN
Definition: xlpivot.hxx:125
sal_Int32 GetDatePart() const
Definition: dpdimsave.hxx:107
void SetCol(SCCOL nColP)
Definition: address.hxx:279
const DateTime * GetDateTime() const
Returns pointer to date, if the item type is 'date/time', otherwise 0.
Definition: xlpivot.cxx:145
size_t GetElementCount() const
Definition: dpdimsave.cxx:73
void InsertOrigDoubleItem(double fValue, const OUString &rText)
Inserts an original value item, if it is not contained already.
Definition: xepivot.cxx:469
std::vector< ScDPSaveMember * > MemberList
Definition: dpsave.hxx:115
sal_uInt16 mnStrmId
Records in source database.
Definition: xlpivot.hxx:529
virtual void Save(XclExpStream &rStrm)
Overwrite this method to do any operation while saving the record.
Definition: xerecord.cxx:36
::std::pair< sal_uInt16, sal_uInt16 > XclPTDataFieldPos
Data field position specifying the pivot table field index (first) and data info index (second)...
Definition: xepivot.hxx:226
const OUString * GetText() const
Returns pointer to text, if the item type is 'text', otherwise 0.
Definition: xlpivot.cxx:135
void SetSliceSize(sal_uInt16 nSize)
Sets data slice length.
Definition: xestream.cxx:129
sal_uInt16 mnPagePerRow
Number of SXSELECT records.
Definition: xlpivot.hxx:739
maximum value of all numerical values is calculated.
const sal_uInt16 EXC_ID_SXSTRING
Definition: xlpivot.hxx:264
void InitDateGroupField(const ScDPObject &rDPObj, const ScDPNumGroupInfo &rDateInfo, sal_Int32 nDatePart)
Initializes a date grouping field.
Definition: xepivot.cxx:426
const sal_uInt16 EXC_ID_SXDATETIME
Definition: xlpivot.hxx:267
void SetDateGroupLimit(const ScDPNumGroupInfo &rDateInfo, bool bUseStep)
Inserts the SXDATETIME/SXINTEGER items that specify the limits for a date grouping.
Definition: xepivot.cxx:553
XclExpPivotTableList maPTableList
List of all pivot caches.
Definition: xepivot.hxx:434
void SetDataFieldPropertiesFromDim(const ScDPSaveDimension &rSaveDim)
Fills a pivot table data field with all properties from the passed save dimension.
Definition: xepivot.cxx:1364
const sal_uInt16 EXC_SXVD_SUBT_SUM
Definition: xlpivot.hxx:121
const size_t EXC_PC_MAXITEMCOUNT
Definition: xlpivot.hxx:51
sal_uInt16 mnFlags
Definition: xlpivot.hxx:458
void WriteSxindexlistList(XclExpStream &rStrm) const
Writes the SXINDEXLIST record list containing the item index table.
Definition: xepivot.cxx:844
XclPTFieldExtInfo maFieldExtInfo
General field info (SXVD record).
Definition: xepivot.hxx:310
const sal_uInt16 EXC_SXFIELD_NUMGROUP
Definition: xlpivot.hxx:228
const sal_uInt16 EXC_SXVIEW_DATALAST
Definition: xlpivot.hxx:105
const sal_uInt16 EXC_SXFDBTYPE_DEFAULT
Definition: xlpivot.hxx:356
OUString GetItemName() const
Returns the internal name of this item.
Definition: xepivot.cxx:914
bool GetDrillDown() const
Definition: dpsave.hxx:342
XclExpPCItemList maNumGroupLimits
Indexes into maItemList.
Definition: xepivot.hxx:152
sal_uInt16 mnOrigItems
Number of items in the base field.
Definition: xlpivot.hxx:445
void AddFields(const ScDPObject &rDPObj)
Adds all pivot cache fields.
Definition: xepivot.cxx:731
standard deviation is calculated based on the entire population.
const sal_uInt16 EXC_SXFIELD_HASCHILD
Definition: xlpivot.hxx:227
sal_uInt16 mnFlags
Stream identifier.
Definition: xlpivot.hxx:530
void SetApiAutoShowCount(sal_Int32 nShowCount)
Sets the number of items to be shown in AutoShow mode.
Definition: xlpivot.cxx:611
const sal_uInt16 EXC_SXVDEX_SORT_OWN
Definition: xlpivot.hxx:343
void WriteSxview(XclExpStream &rStrm) const
Writes the SXVIEW record starting the pivot table.
Definition: xepivot.cxx:1451
void AppendSubtotalItem(sal_uInt16 nItemType)
Appends a special item describing a field subtotal entry.
Definition: xepivot.cxx:1156
const sal_uInt16 EXC_SXFIELD_HASITEMS
Definition: xlpivot.hxx:224
OUString GetFormattedString(long nDim, const ScDPItemData &rItem, bool bLocaleIndependent) const
Definition: dpcache.cxx:1210
const ScDPSaveGroupItem & GetGroupByIndex(long nIndex) const
Definition: dpdimsave.cxx:205
const css::sheet::DataPilotFieldSortInfo * GetSortInfo() const
Definition: dpsave.hxx:186
When assigning a string value, you can also assign an interned string whose life-cycle is managed by ...
Definition: dpitemdata.hxx:29
sal_uInt32 mnSrcRecs
Definition: xlpivot.hxx:528
ScRange maOrigSrcRange
Range name for source data.
Definition: xepivot.hxx:215
XclExpAddressConverter & GetAddressConverter() const
Returns the address converter.
Definition: xeroot.cxx:81
const OUString * GetElementByIndex(size_t nIndex) const
Definition: dpdimsave.cxx:78
int i
DateTime GetDateTimeFromDouble(double fValue) const
Converts a floating-point value to a date/time value.
Definition: xlroot.cxx:343
Represents a group dimension that introduces a new hierarchy for an existing dimension.
Definition: dpdimsave.hxx:132
const sal_uInt16 EXC_SXDB_SAVEDATA
Definition: xlpivot.hxx:206
const sal_uInt16 EXC_ID_SXVI
Definition: xlpivot.hxx:136
void AddStdFields(const ScDPObject &rDPObj)
Adds all standard pivot cache fields based on source data.
Definition: xepivot.cxx:739
SC_DLLPUBLIC ScDPSaveDimension * GetExistingDataLayoutDimension() const
Definition: dpsave.cxx:875
average of all numerical values is calculated.
bool IsEmpty() const
Returns true, if the item type is 'empty'.
Definition: xlpivot.cxx:130
void Finalize()
Initializes flags and item count fields.
Definition: xepivot.cxx:563
bool mbValid
List index in pivot cache buffer.
Definition: xepivot.hxx:219
ScfUInt16Vec maColFields
Row field indexes.
Definition: xepivot.hxx:389
sal_Int16 SCCOL
Definition: types.hxx:22
const double EXC_SXDBEX_CREATION_DATE
Definition: xlpivot.hxx:352
const sal_uInt16 EXC_SXNUMGROUP_AUTOMIN
Definition: xlpivot.hxx:278
The main class for pivot table export.
Definition: xepivot.hxx:406
const sal_uInt16 EXC_SXVIEW_COLGRAND
Definition: xlpivot.hxx:102
static SC_DLLPUBLIC OUString getSourceDimensionName(const OUString &rName)
Definition: dputil.cxx:64
const sal_uInt16 EXC_ID_SXDOUBLE
Definition: xlpivot.hxx:252
sal_uInt16 mnSubtotals
Number of subtotal functions.
Definition: xlpivot.hxx:596
const sal_uInt16 EXC_ID_SXINTEGER
Definition: xlpivot.hxx:261
sal_uInt16 mnDataCols
Number of rows containing data.
Definition: xlpivot.hxx:722
const OUString & GetName() const
Definition: dpobject.hxx:167
const sal_uInt16 EXC_SXVD_SUBT_VAR
Definition: xlpivot.hxx:130
sal_uInt16 mnSelItem
Base field for this page info.
Definition: xlpivot.hxx:661
virtual ~XclExpPCField() override
Definition: xepivot.cxx:249
XclExpRecordRef CreatePivotTablesRecord(SCTAB nScTab)
Creates a record wrapper for exporting all pivot tables of the specified sheet.
Definition: xepivot.cxx:1644
const sal_uInt16 EXC_ID_SXEMPTY
Definition: xlpivot.hxx:270
void IncRow(SCROW nDelta=1)
Definition: address.hxx:300
const XclExpPCItemList & GetVisItemList() const
Returns the item list that contains the visible items.
Definition: xepivot.cxx:317
sal_uInt16 mnRowFields
Number of all fields.
Definition: xlpivot.hxx:717
sal_uInt16 mnPageFields
Number of column fields.
Definition: xlpivot.hxx:719
void WriteIndex(XclExpStream &rStrm, sal_uInt32 nSrcRow) const
Writes the item index at the passed source row position as part of the SXINDEXLIST record...
Definition: xepivot.cxx:285
OUString ScResId(const char *pId)
Definition: scdll.cxx:95
void EndRecord()
Checks and corrects real record length.
Definition: xestream.cxx:120
sal_uInt16 mnSortField
Several flags and number of items for AutoShow.
Definition: xlpivot.hxx:624
bool get_flag(Type nBitField, Type nMask)
Returns true, if at least one of the bits set in nMask is set in nBitField.
Definition: ftools.hxx:73
const sal_uInt16 EXC_SXFIELD_DATA_DATE_STR
Dates with integers or doubles without strings.
Definition: xlpivot.hxx:242
XclExpPCFieldList maFieldList
Pivot cache settings (SXDB record).
Definition: xepivot.hxx:212
const sal_uInt16 EXC_ID_SXDB
Definition: xlpivot.hxx:204
sal_uInt16 mnType
Definition: xlpivot.hxx:577
const sal_uInt16 EXC_ID_SXDBEX
Definition: xlpivot.hxx:351
void InsertOrigTextItem(const OUString &rText)
Inserts an original text item, if it is not contained already.
Definition: xepivot.cxx:456
SvNumFormatType
void InsertOrigItem(XclExpPCItem *pNewItem)
Inserts an original source item.
Definition: xepivot.cxx:448
void WriteSxnumgroup(XclExpStream &rStrm)
Writes an SXNUMGROUP record and the additional items for a numeric grouping field.
Definition: xepivot.cxx:581
ScDPSaveData * GetSaveData() const
Definition: dpobject.hxx:141
void SetEmpty()
Sets the item to 'empty' type.
Definition: xlpivot.cxx:55
XclExpPTField(const XclExpPivotTable &rPTable, sal_uInt16 nCacheIdx)
Definition: xepivot.cxx:937
XclExpTabInfo & GetTabInfo() const
Returns the buffer for Calc->Excel sheet index conversion.
Definition: xeroot.cxx:75
const sal_uInt16 EXC_SXVD_SUBT_AVERAGE
Definition: xlpivot.hxx:123
const ScDPNumGroupInfo & GetDateInfo() const
Definition: dpdimsave.hxx:108
const sal_Int16 * GetInteger() const
Returns pointer to integer, if the item type is 'integer', otherwise 0.
Definition: xlpivot.cxx:150
sal_uInt16 mnDataPos
Orientation of data fields.
Definition: xlpivot.hxx:715
sal_uInt16 mnCol
Definition: xladdress.hxx:32
const int nIndexCount
Definition: qproform.cxx:567
#define EXC_STORAGE_PTCACHE
Definition: xlpivot.hxx:39
const sal_uInt16 EXC_ID_SXIDSTM
Definition: xlpivot.hxx:273
Contains data for a pivot table data field (SXDI record).
Definition: xlpivot.hxx:673
sal_uInt16 GetCacheIndex() const
Returns the list index of the cache used in pivot table records.
Definition: xepivot.hxx:168
const sal_uInt16 EXC_SXFIELD_DATA_INT
Only strings, nothing else.
Definition: xlpivot.hxx:235
XclExpPTField * GetFieldAcc(const OUString &rName)
Returns a pivot table field by its name.
Definition: xepivot.cxx:1287
const sal_uInt32 EXC_SXVDEX_SORT_ASC
Definition: xlpivot.hxx:335
const sal_uInt16 EXC_SXVI_TYPE_STDDEV
Definition: xlpivot.hxx:149
XclExpPivotCache(const XclExpRoot &rRoot, const ScDPObject &rDPObj, sal_uInt16 nListIdx)
Definition: xepivot.cxx:615
OUString maSrcRangeName
Name of source data sheet.
Definition: xepivot.hxx:214
sal_uInt16 GetFieldIndex() const
Returns the index of this field in the containing pivot cache.
Definition: xlpivot.hxx:484
void AppendNewRecord(RecType *pRec)
Appends a newly created record to the list.
Definition: xerecord.hxx:362
bool EqualsDouble(double fValue) const
Definition: xepivot.cxx:138
void WriteCacheStream()
Creates the pivot cache storage stream and writes the cache.
Definition: xepivot.cxx:809
void SetPropertiesFromDP(const ScDPSaveData &rSaveData)
Fills internal members with all properties from the passed save data.
Definition: xepivot.cxx:1309
bool ValidateRange(ScRange &rScRange, bool bWarn)
Checks and eventually crops the cell range to valid dimensions.
Definition: xehelper.cxx:210
XclRange maOutXclRange
The visible name of the data field.
Definition: xlpivot.hxx:710
const sal_uInt16 EXC_ID_DCONREF
Definition: xlpivot.hxx:94
SCCOL Col() const
Definition: address.hxx:267
bool IsStandardField() const
Returns true, if this is a standard field build directly from source data.
Definition: xlpivot.cxx:298
const XclExpRoot & GetRoot() const
Returns this root instance - for code readability in derived classes.
Definition: xeroot.hxx:119
const std::optional< OUString > & GetSubtotalName() const
Definition: dpsave.cxx:358
bool GetFilterButton() const
Definition: dpsave.hxx:338
ScRange maDocSrcRange
The exported sheet source range.
Definition: xepivot.hxx:217
virtual void WriteBody(XclExpStream &rStrm) override
Writes the SXVI record body describing the pivot table item.
Definition: xepivot.cxx:932
const sal_uInt16 EXC_SXVI_TYPE_SUM
Definition: xlpivot.hxx:142
XclExpValueRecord< sal_uInt16 > XclExpUInt16Record
A record containing an unsigned 16-bit value.
Definition: xerecord.hxx:248
bool Has16BitIndexes() const
Returns true, if the item indexes in the SXINDEXLIST record are stored as 16-bit values.
Definition: xlpivot.cxx:348
sal_uInt16 mnTotalFields
Number of standard pivot cache fields.
Definition: xlpivot.hxx:533
void Save(XclExpStream &rStrm)
Writes related records into Workbook stream and creates the pivot cache storage stream.
Definition: xepivot.cxx:708
bool GetColumnGrand() const
Definition: dpsave.hxx:322
XclPCFieldInfo maFieldInfo
Definition: xlpivot.hxx:516
const sal_uInt16 EXC_ID_SXDI
Definition: xlpivot.hxx:176
void WriteSxdb(XclExpStream &rStrm) const
Writes the SXDB record.
Definition: xepivot.cxx:829
const sal_uInt16 EXC_ID_SXVD
Definition: xlpivot.hxx:109
RecType * GetRecord(size_t nPos) const
Returns reference to an existing record or empty reference on error.
Definition: xerecord.hxx:334
const XclExpPivotCache & mrPCache
Definition: xepivot.hxx:383
const sal_uInt16 EXC_SXVI_TYPE_PROD
Definition: xlpivot.hxx:147
bool EqualsBool(bool bValue) const
Definition: xepivot.cxx:148
sal_uInt16 mnPagePerCol
Number of page fields per row.
Definition: xlpivot.hxx:740
const sal_uInt16 EXC_SXFIELD_DATA_STR_INT
Only doubles, nothing else.
Definition: xlpivot.hxx:237
Represents a data item in a pivot cache containing data of any type.
Definition: xepivot.hxx:37
sal_Int32 SCROW
Definition: types.hxx:18
const sal_uInt16 EXC_ID_SXVIEW
Definition: xlpivot.hxx:99
const sal_uInt16 EXC_SXVD_SUBT_STDDEVP
Definition: xlpivot.hxx:129
OUString maDataName
The name of the pivot table.
Definition: xlpivot.hxx:709
void WriteSxvd(XclExpStream &rStrm) const
Writes the SXVD record introducing the field.
Definition: xepivot.cxx:1162
SC_DLLPUBLIC bool HasIsVisible() const
Definition: dpsave.cxx:90
XclExpPCField(const XclExpRoot &rRoot, sal_uInt16 nFieldIdx, const ScDPObject &rDPObj, const ScRange &rRange)
Creates a standard pivot cache field, filled from sheet source data.
Definition: xepivot.cxx:189
bool GetShowDetails() const
Definition: dpsave.hxx:76
static void WriteSxli(XclExpStream &rStrm, sal_uInt16 nLineCount, sal_uInt16 nIndexCount)
Writes a dummy SXLI records containing item layout info.
Definition: xepivot.cxx:1495
void InsertOrigBoolItem(bool bValue, const OUString &rText)
Inserts an original boolean item, if it is not contained already.
Definition: xepivot.cxx:491
const DimsType & GetDimensions() const
Definition: dpsave.hxx:270
XclPTViewEx9Info maPTViewEx9Info
Extended info about the pivot table (SXEX record).
Definition: xepivot.hxx:386
::std::vector< sal_uInt16 > ScfUInt16Vec
Definition: ftools.hxx:253
const sal_uInt16 EXC_ID_SXBOOLEAN
Definition: xlpivot.hxx:255
ScfUInt16Vec maPageFields
Column field indexes.
Definition: xepivot.hxx:390
XclExpPivotTableManager(const XclExpRoot &rRoot)
Definition: xepivot.cxx:1623
unsigned char sal_uInt8
const sal_uInt16 EXC_SXFIELD_DATA_STR_DBL
Only strings and integers, opt. with doubles.
Definition: xlpivot.hxx:238
void WriteSxViewEx9(XclExpStream &rStrm) const
Writes the SX_AUTOFORMAT records with the autoformat id and header layout.
Definition: xepivot.cxx:1580
void InitStdGroupField(const XclExpPCField &rBaseField, const ScDPSaveGroupDimension &rGroupDim)
Initializes a standard grouping field.
Definition: xepivot.cxx:361
std::size_t GetSize() const
Returns the byte count the whole string will take on export.
Definition: xestring.cxx:248
bool GetShowEmpty() const
Definition: dpsave.hxx:157
void AddGroupFields(const ScDPObject &rDPObj)
Adds all grouping pivot cache fields.
Definition: xepivot.cxx:754
const sal_uInt16 EXC_SXIVD_DATA
Definition: xlpivot.hxx:165
ScGeneralFunction
the css::sheet::GeneralFunction enum is extended by constants in GeneralFunction2, which causes some type-safety issues.
A record without body.
Definition: xerecord.hxx:184
OUString aName
const OUString & GetName() const
Definition: dpsave.hxx:139
XclPCInfo maPCInfo
Definition: xepivot.hxx:211
const sal_uInt16 EXC_SXVD_SUBT_MAX
Definition: xlpivot.hxx:124
std::vector< std::unique_ptr< ScDPSaveDimension > > DimsType
Definition: dpsave.hxx:238
const sal_uInt16 EXC_SXVI_TYPE_COUNT
Definition: xlpivot.hxx:143
variance is calculated based on a sample.
#define SAL_MAX_INT16
all values, including non-numerical values, are counted.
const ScSheetSourceDesc * GetSheetDesc() const
Definition: dpobject.hxx:156
Represents a new group dimension whose dimension ID is higher than the highest source dimension ID...
Definition: dpdimsave.hxx:87
const OUString & GetRangeName() const
Definition: dpshttab.hxx:60
const OUString & ConvertToText() const
Returns the text representation of the item.
Definition: xlpivot.hxx:394
sal_uInt16 mnFlags
Name of the pivot cache field.
Definition: xlpivot.hxx:439
void WriteDConName(XclExpStream &rStrm) const
DCONNAME record contains range name source.
Definition: xepivot.cxx:801
XclExpPTFieldList maFieldList
The selected autoformat (SXVIEWEX9)
Definition: xepivot.hxx:387
const std::vector< SCROW > & GetNumEntries(SCCOL nSourceDim, const ScDPCache *pCache) const
Definition: dpgroup.cxx:453
XclPTInfo maPTInfo
The pivot cache this pivot table bases on.
Definition: xepivot.hxx:384
void * p
void Finalize()
Initializes any data after processing the entire source DataPilot.
Definition: xepivot.cxx:1375
void InsertNumDateGroupItems(const ScDPObject &rDPObj, const ScDPNumGroupInfo &rNumInfo, sal_Int32 nDatePart=0)
Generates and inserts all visible items for numeric or date grouping.
Definition: xepivot.cxx:508
const css::sheet::DataPilotFieldAutoShowInfo * GetAutoShowInfo() const
Definition: dpsave.hxx:190
XclPTFieldInfo maFieldInfo
The referred pivot cache field.
Definition: xepivot.hxx:309
const sal_uInt16 EXC_SXVI_TYPE_VAR
Definition: xlpivot.hxx:151
const sal_uInt16 EXC_ID_SXEX
Definition: xlpivot.hxx:310
const sal_uInt16 EXC_SXVI_DEFAULT_CACHE
Definition: xlpivot.hxx:161
XclPTItemInfo maItemInfo
The referred pivot cache item.
Definition: xepivot.hxx:249
const sal_uInt16 EXC_ID_SXNUMGROUP
Definition: xlpivot.hxx:276
void InitStandardField(const ScRange &rRange)
Initializes a standard field.
Definition: xepivot.cxx:324
OUString maTabName
List of all pivot cache fields.
Definition: xepivot.hxx:213
size_t GetSize() const
Definition: xerecord.hxx:328
const sal_uInt32 EXC_SXVDEX_SHOWALL
Definition: xlpivot.hxx:333
const sal_uInt16 EXC_SXVI_TYPE_MIN
Definition: xlpivot.hxx:146
void SetApiRefType(sal_Int32 nRefType)
Sets the result reference type represented by the passed API constant.
Definition: xlpivot.cxx:769
minimum value of all numerical values is calculated.
static void WriteSxdbex(XclExpStream &rStrm)
Writes the SXDBEX record.
Definition: xepivot.cxx:836
standard deviation is calculated based on a sample.
void StartRecord(sal_uInt16 nRecId, std::size_t nRecSize)
Starts a new record: writes header data, stores calculated record size.
Definition: xestream.cxx:108
const sal_uInt16 EXC_ID_SXFDBTYPE
Definition: xlpivot.hxx:355
void SetVisName(const OUString &rName)
Sets the visible name and enables usage of cache if name is empty.
Definition: xlpivot.cxx:425
bool IsDateGroupField() const
Returns true, if this field is a date/time grouping field.
Definition: xlpivot.cxx:313
const XclExpPCField * GetCacheField(sal_uInt16 nCacheIdx) const
Returns a pivot cache field.
Definition: xepivot.cxx:1233
void WritePivotCaches(XclExpStream &rStrm)
Writes all pivot caches (all Workbook records and cache streams).
Definition: xepivot.cxx:1649
void SetDataPropertiesFromDim(const ScDPSaveDimension &rSaveDim)
Fills this field with data field properties from the passed save dimension.
Definition: xepivot.cxx:1067
const sal_uInt16 EXC_SXVD_AXIS_NONE
Definition: xlpivot.hxx:111
void SetApiAutoShowMode(sal_Int32 nShowMode)
Sets the AutoShow mode represented by the passed API constant.
Definition: xlpivot.cxx:601
const sal_uInt16 EXC_ID_SXFIELD
Definition: xlpivot.hxx:222
virtual void Save(XclExpStream &rStrm) override
Writes the entire pivot table.
Definition: xepivot.cxx:1260
std::vector< XclPTDataFieldPos > maDataFields
Page field indexes.
Definition: xepivot.hxx:392
const sal_uInt16 EXC_SXVI_TYPE_MAX
Definition: xlpivot.hxx:145
XclPCNumGroupInfo maNumGroupInfo
Order of items in a grouping field (SXGROUPINFO record).
Definition: xlpivot.hxx:520
void InsertOrigDateTimeItem(const DateTime &rDateTime, const OUString &rText)
Inserts an original date/time item, if it is not contained already.
Definition: xepivot.cxx:480
const sal_uInt16 EXC_SXVD_AXIS_ROW
Definition: xlpivot.hxx:112
const sal_uInt16 EXC_SXDB_SRC_SHEET
Definition: xlpivot.hxx:216
bool IsNumGroupField() const
Returns true, if this field is a numeric grouping field.
Definition: xlpivot.cxx:308
sal_uInt16 mnField
Definition: xlpivot.hxx:675
OUString maTableName
Definition: xlpivot.hxx:708
static void SaveXml(XclExpXmlStream &rStrm)
Definition: xepivot.cxx:727
sal_uInt16 GetItemIndex(const OUString &rItemName) const
Returns the index of a pivot cache item, or EXC_PC_NOITEM on error.
Definition: xepivot.cxx:271
const sal_uInt16 EXC_SXVD_SUBT_VARP
Definition: xlpivot.hxx:131
sal_uInt16 GetFieldCount() const
Returns the number of pivot cache fields.
Definition: xepivot.cxx:682
sal_uInt16 GetFieldIndex() const
Returns the pivot table field list index of this field.
Definition: xepivot.hxx:264
SC_DLLPUBLIC const std::optional< OUString > & GetLayoutName() const
Definition: dpsave.cxx:123
const sal_uInt16 EXC_ID_SXVDEX
Definition: xlpivot.hxx:331
const XclExpPTField * GetField(sal_uInt16 nFieldIdx) const
Returns a pivot table field by its name.
Definition: xepivot.cxx:1238
const sal_uInt16 EXC_SXVIEW_ROWGRAND
Definition: xlpivot.hxx:101
void WriteDconref(XclExpStream &rStrm) const
Writes the DCONREF record containing the source range.
Definition: xepivot.cxx:788
void SetDouble(double fValue, const OUString &rText=OUString())
Sets the item to 'double' type and adds the passed value.
Definition: xlpivot.cxx:67
sal_uInt16 mnBaseItems
Number of special items in a grouping field.
Definition: xlpivot.hxx:444
void WriteSxgroupinfo(XclExpStream &rStrm)
Writes an SXGROUPINFO record describing the item order in grouping fields.
Definition: xepivot.cxx:597
tools::SvRef< SotStorageStream > OpenStream(tools::SvRef< SotStorage > const &xStrg, const OUString &rStrmName) const
Tries to open a new stream in the specified storage for reading or writing.
Definition: xlroot.cxx:264
const sal_uInt16 EXC_SXFIELD_DATA_STR
Special state for groupings.
Definition: xlpivot.hxx:234
XclPCFieldType meFieldType
Pivot cache field info (SXFIELD record).
Definition: xlpivot.hxx:517
bool IsSupportedField() const
Returns true, if the type of the field is supported by Calc.
Definition: xlpivot.cxx:293
bool IsEmpty() const
Definition: xerecord.hxx:327
virtual void WriteBody(XclExpStream &rStrm) override
Writes the contents of the SXFIELD record for this field.
Definition: xepivot.cxx:610
virtual void Save(XclExpStream &rStrm) override
Writes the record header and calls WriteBody().
Definition: xerecord.cxx:150
sal_uInt16 mnTypeFlag
Definition: xepivot.hxx:57
const SCTAB SCTAB_MAX
Definition: address.hxx:58
bool mbValid
Sheet index of the output range.
Definition: xepivot.hxx:395
const sal_uInt16 EXC_SXFIELD_DATA_DATE_NUM
Dates and empty strings, nothing else (?).
Definition: xlpivot.hxx:241
OUString maName
Definition: xlpivot.hxx:438
const sal_uInt16 EXC_SXVI_TYPE_AVERAGE
Definition: xlpivot.hxx:144
const sal_uInt16 EXC_SXVD_SUBT_PROD
Definition: xlpivot.hxx:126
sal_uInt16 GetLastDataInfoIndex() const
Returns the index of the last inserted data info struct.
Definition: xepivot.cxx:957
const sal_uInt16 EXC_ID_SXVIEWEX9
Definition: xlpivot.hxx:359
This class contains authoritative information on the internal reference used as the data source for d...
Definition: dpshttab.hxx:39
sal_uInt32 mnFlags
Number of page fields per column.
Definition: xlpivot.hxx:741
aStr
SC_DLLPUBLIC bool GetName(SCTAB nTab, OUString &rName) const
Definition: document.cxx:213
const sal_uInt16 EXC_SXVI_TYPE_COUNTNUM
Definition: xlpivot.hxx:148
void WriteQsiSxTag(XclExpStream &rStrm) const
Definition: xepivot.cxx:1526
const css::sheet::DataPilotFieldReference * GetReferenceValue() const
Definition: dpsave.hxx:181
bool mbValid
void InitNumGroupField(const ScDPObject &rDPObj, const ScDPNumGroupInfo &rNumInfo)
Initializes a numeric grouping field.
Definition: xepivot.cxx:402
Base class for single records with any content.
Definition: xerecord.hxx:143
sal_uInt16 nPos
sal_Int16 SCTAB
Definition: types.hxx:23
sal_uInt16 mnTypeFlags
List with limit values for numeric grouping.
Definition: xepivot.hxx:153
const sal_Int32 EXC_PC_MAXSTRLEN
Definition: xlpivot.hxx:48
ScGeneralFunction GetSubTotalFunc(long nIndex) const
Definition: dpsave.hxx:152
sal_uInt16 mnItemCount
Bitfield for subtotal functions.
Definition: xlpivot.hxx:597
sal_uInt16 mnFirstHeadRow
First cell containing data.
Definition: xlpivot.hxx:712
const sal_uInt16 EXC_SXVD_SUBT_COUNT
Definition: xlpivot.hxx:122
const sal_uInt16 EXC_SXLI_DEFAULTFLAGS
Definition: xlpivot.hxx:169
void WriteZeroBytes(std::size_t nBytes)
Writes a sequence of nBytes zero bytes (respects slice setting).
Definition: xestream.cxx:256
sal_uInt16 GetDataFieldIndex(const OUString &rName, sal_uInt16 nDefaultIdx) const
Returns the data-field-only index of the first data field with the passed name.
Definition: xepivot.cxx:1248
sal_uInt8 mnGridLayout
AutoFormat ID.
Definition: xlpivot.hxx:756
const sal_uInt16 EXC_ID_EOF
Internal use only.
Definition: xlconst.hxx:173
sal_uInt16 mnDataAxis
0-based index of the pivot cache.
Definition: xlpivot.hxx:714
SC_DLLPUBLIC bool HasShowDetails() const
Definition: dpsave.cxx:100