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  if( const ScSheetSourceDesc* pSrcDesc = rDPObj.GetSheetDesc() )
512  {
513  // get the string collection with original source elements
514  const ScDPSaveData* pSaveData = rDPObj.GetSaveData();
515  const ScDPDimensionSaveData* pDimData = nullptr;
516  if (pSaveData)
517  pDimData = pSaveData->GetExistingDimensionData();
518 
519  const ScDPCache* pCache = pSrcDesc->CreateCache(pDimData);
520  if (!pCache)
521  return;
522 
523  ScSheetDPData aDPData(&GetDoc(), *pSrcDesc, *pCache);
524  long nDim = GetFieldIndex();
525  // get the string collection with generated grouping elements
526  ScDPNumGroupDimension aTmpDim( rNumInfo );
527  if( nDatePart != 0 )
528  aTmpDim.SetDateDimension();
529  const std::vector<SCROW>& aMemberIds = aTmpDim.GetNumEntries(
530  static_cast<SCCOL>(nDim), pCache);
531  for (SCROW nMemberId : aMemberIds)
532  {
533  const ScDPItemData* pData = aDPData.GetMemberById(nDim, nMemberId);
534  if ( pData )
535  {
536  OUString aStr = pCache->GetFormattedString(nDim, *pData, false);
537  InsertGroupItem(new XclExpPCItem(aStr));
538  }
539  }
540  }
541 }
542 
544 {
550 }
551 
552 void XclExpPCField::SetDateGroupLimit( const ScDPNumGroupInfo& rDateInfo, bool bUseStep )
553 {
558  sal_Int16 nStep = bUseStep ? limit_cast< sal_Int16 >( rDateInfo.mfStep, 1, SAL_MAX_INT16 ) : 1;
560 }
561 
563 {
564  // flags
566  // Excel writes long indexes even for 0x0100 items (indexes from 0x00 to 0xFF)
569  /* mnTypeFlags is updated in all Insert***Item() functions. Now the flags
570  for the current combination of item types is added to the flags. */
571  ::set_flag( maFieldInfo.mnFlags, spnPCItemFlags[ mnTypeFlags ] );
572 
573  // item count fields
574  maFieldInfo.mnVisItems = static_cast< sal_uInt16 >( GetVisItemList().GetSize() );
575  maFieldInfo.mnGroupItems = static_cast< sal_uInt16 >( maGroupItemList.GetSize() );
576  // maFieldInfo.mnBaseItems set in InitStdGroupField()
577  maFieldInfo.mnOrigItems = static_cast< sal_uInt16 >( maOrigItemList.GetSize() );
578 }
579 
581 {
582  if( IsNumGroupField() || IsDateGroupField() )
583  {
584  // SXNUMGROUP record
585  rStrm.StartRecord( EXC_ID_SXNUMGROUP, 2 );
586  rStrm << maNumGroupInfo;
587  rStrm.EndRecord();
588 
589  // limits (min/max/step) for numeric grouping
590  OSL_ENSURE( maNumGroupLimits.GetSize() == 3,
591  "XclExpPCField::WriteSxnumgroup - missing numeric grouping limits" );
592  maNumGroupLimits.Save( rStrm );
593  }
594 }
595 
597 {
598  OSL_ENSURE( IsStdGroupField() != maGroupOrder.empty(),
599  "XclExpPCField::WriteSxgroupinfo - missing grouping info" );
600  if( IsStdGroupField() && !maGroupOrder.empty() )
601  {
602  rStrm.StartRecord( EXC_ID_SXGROUPINFO, 2 * maGroupOrder.size() );
603  for( const auto& rItem : maGroupOrder )
604  rStrm << rItem;
605  rStrm.EndRecord();
606  }
607 }
608 
610 {
611  rStrm << maFieldInfo;
612 }
613 
614 XclExpPivotCache::XclExpPivotCache( const XclExpRoot& rRoot, const ScDPObject& rDPObj, sal_uInt16 nListIdx ) :
615  XclExpRoot( rRoot ),
616  mnListIdx( nListIdx ),
617  mbValid( false )
618 {
619  // source from sheet only
620  if( const ScSheetSourceDesc* pSrcDesc = rDPObj.GetSheetDesc() )
621  {
622  /* maOrigSrcRange: Range received from the DataPilot object.
623  maExpSrcRange: Range written to the DCONREF record.
624  maDocSrcRange: Range used to get source data from Calc document.
625  This range may be shorter than maExpSrcRange to improve export
626  performance (#i22541#). */
627  maOrigSrcRange = maExpSrcRange = maDocSrcRange = pSrcDesc->GetSourceRange();
628  maSrcRangeName = pSrcDesc->GetRangeName();
629 
630  // internal sheet data only
631  SCTAB nScTab = maExpSrcRange.aStart.Tab();
632  if( (nScTab == maExpSrcRange.aEnd.Tab()) && GetTabInfo().IsExportTab( nScTab ) )
633  {
634  // ValidateRange() restricts source range to valid Excel limits
636  {
637  // #i22541# skip empty cell areas (performance)
638  SCCOL nDocCol1, nDocCol2;
639  SCROW nDocRow1, nDocRow2;
640  GetDoc().GetDataStart( nScTab, nDocCol1, nDocRow1 );
641  GetDoc().GetPrintArea( nScTab, nDocCol2, nDocRow2, false );
642  SCCOL nSrcCol1 = maExpSrcRange.aStart.Col();
643  SCROW nSrcRow1 = maExpSrcRange.aStart.Row();
644  SCCOL nSrcCol2 = maExpSrcRange.aEnd.Col();
645  SCROW nSrcRow2 = maExpSrcRange.aEnd.Row();
646 
647  // #i22541# do not store index list for too big ranges
648  if( 2 * (nDocRow2 - nDocRow1) < (nSrcRow2 - nSrcRow1) )
650 
651  // adjust row indexes, keep one row of empty area to surely have the empty cache item
652  if( nSrcRow1 < nDocRow1 )
653  nSrcRow1 = nDocRow1 - 1;
654  if( nSrcRow2 > nDocRow2 )
655  nSrcRow2 = nDocRow2 + 1;
656 
657  maDocSrcRange.aStart.SetCol( ::std::max( nDocCol1, nSrcCol1 ) );
658  maDocSrcRange.aStart.SetRow( nSrcRow1 );
659  maDocSrcRange.aEnd.SetCol( ::std::min( nDocCol2, nSrcCol2 ) );
660  maDocSrcRange.aEnd.SetRow( nSrcRow2 );
661 
662  GetDoc().GetName( nScTab, maTabName );
663  maPCInfo.mnSrcRecs = static_cast< sal_uInt32 >( maExpSrcRange.aEnd.Row() - maExpSrcRange.aStart.Row() );
664  maPCInfo.mnStrmId = nListIdx + 1;
666 
667  AddFields( rDPObj );
668 
669  mbValid = true;
670  }
671  }
672  }
673 }
674 
676 {
678 }
679 
681 {
682  return static_cast< sal_uInt16 >( maFieldList.GetSize() );
683 }
684 
685 const XclExpPCField* XclExpPivotCache::GetField( sal_uInt16 nFieldIdx ) const
686 {
687  return maFieldList.GetRecord( nFieldIdx );
688 }
689 
691 {
692  // pivot cache can be shared, if there are no additional cache fields
694 }
695 
697 {
698  /* For now, only sheet sources are supported, therefore it is enough to
699  compare the ScSheetSourceDesc. Later, there should be done more complicated
700  comparisons regarding the source type of rDPObj and this cache. */
701  if( const ScSheetSourceDesc* pSrcDesc = rDPObj.GetSheetDesc() )
702  return pSrcDesc->GetSourceRange() == maOrigSrcRange;
703  return false;
704 }
705 
707 {
708  OSL_ENSURE( mbValid, "XclExpPivotCache::Save - invalid pivot cache" );
709  // SXIDSTM
711  // SXVS
713 
714  if (!maSrcRangeName.isEmpty())
715  // DCONNAME
716  WriteDConName(rStrm);
717  else
718  // DCONREF
719  WriteDconref(rStrm);
720 
721  // create the pivot cache storage stream
723 }
724 
726 {
727 }
728 
730 {
731  AddStdFields( rDPObj );
733  AddGroupFields( rDPObj );
735 };
736 
738 {
739  // if item index list is not written, used shortened source range (maDocSrcRange) for performance
740  const ScRange& rRange = HasItemIndexList() ? maExpSrcRange : maDocSrcRange;
741  // create a standard pivot cache field for each source column
742  for( SCCOL nScCol = rRange.aStart.Col(), nEndScCol = rRange.aEnd.Col(); nScCol <= nEndScCol; ++nScCol )
743  {
744  ScRange aColRange( rRange );
745  aColRange.aStart.SetCol( nScCol );
746  aColRange.aEnd.SetCol( nScCol );
748  GetRoot(), GetFieldCount(), rDPObj, aColRange ) );
749  }
750 }
751 
753 {
754  if( const ScDPSaveData* pSaveData = rDPObj.GetSaveData() )
755  {
756  if( const ScDPDimensionSaveData* pSaveDimData = pSaveData->GetExistingDimensionData() )
757  {
758  // loop over all existing standard fields to find their group fields
759  for( sal_uInt16 nFieldIdx = 0; nFieldIdx < maPCInfo.mnStdFields; ++nFieldIdx )
760  {
761  if( XclExpPCField* pCurrStdField = maFieldList.GetRecord( nFieldIdx ) )
762  {
763  const ScDPSaveGroupDimension* pGroupDim = pSaveDimData->GetGroupDimForBase( pCurrStdField->GetFieldName() );
764  XclExpPCField* pLastGroupField = pCurrStdField;
765  while( pGroupDim )
766  {
767  // insert the new grouping field
768  XclExpPCFieldRef xNewGroupField = new XclExpPCField(
769  GetRoot(), GetFieldCount(), rDPObj, *pGroupDim, *pCurrStdField );
770  maFieldList.AppendRecord( xNewGroupField );
771 
772  // register new grouping field at current grouping field, building a chain
773  pLastGroupField->SetGroupChildField( *xNewGroupField );
774 
775  // next grouping dimension
776  pGroupDim = pSaveDimData->GetGroupDimForBase( pGroupDim->GetGroupDimName() );
777  pLastGroupField = xNewGroupField.get();
778  }
779  }
780  }
781  }
782  }
783 }
784 
786 {
788  rStrm.StartRecord( EXC_ID_DCONREF, 7 + aRef.GetSize() );
789  rStrm << static_cast< sal_uInt16 >( maExpSrcRange.aStart.Row() )
790  << static_cast< sal_uInt16 >( maExpSrcRange.aEnd.Row() )
791  << static_cast< sal_uInt8 >( maExpSrcRange.aStart.Col() )
792  << static_cast< sal_uInt8 >( maExpSrcRange.aEnd.Col() )
793  << aRef
794  << sal_uInt8( 0 );
795  rStrm.EndRecord();
796 }
797 
799 {
801  rStrm.StartRecord(EXC_ID_DCONNAME, aName.GetSize() + 2);
802  rStrm << aName << sal_uInt16(0);
803  rStrm.EndRecord();
804 }
805 
807 {
810  if( xSvStrm.is() )
811  {
812  XclExpStream aStrm( *xSvStrm, GetRoot() );
813  // SXDB
814  WriteSxdb( aStrm );
815  // SXDBEX
816  WriteSxdbex( aStrm );
817  // field list (SXFIELD and items)
818  maFieldList.Save( aStrm );
819  // index table (list of SXINDEXLIST)
820  WriteSxindexlistList( aStrm );
821  // EOF
822  XclExpEmptyRecord( EXC_ID_EOF ).Save( aStrm );
823  }
824 }
825 
827 {
828  rStrm.StartRecord( EXC_ID_SXDB, 21 );
829  rStrm << maPCInfo;
830  rStrm.EndRecord();
831 }
832 
834 {
835  rStrm.StartRecord( EXC_ID_SXDBEX, 12 );
836  rStrm << EXC_SXDBEX_CREATION_DATE
837  << sal_uInt32( 0 ); // number of SXFORMULA records
838  rStrm.EndRecord();
839 }
840 
842 {
843  if( HasItemIndexList() )
844  {
845  std::size_t nRecSize = 0;
846  size_t nPos, nSize = maFieldList.GetSize();
847  for( nPos = 0; nPos < nSize; ++nPos )
848  nRecSize += maFieldList.GetRecord( nPos )->GetIndexSize();
849 
850  for( sal_uInt32 nSrcRow = 0; nSrcRow < maPCInfo.mnSrcRecs; ++nSrcRow )
851  {
852  rStrm.StartRecord( EXC_ID_SXINDEXLIST, nRecSize );
853  for( nPos = 0; nPos < nSize; ++nPos )
854  maFieldList.GetRecord( nPos )->WriteIndex( rStrm, nSrcRow );
855  rStrm.EndRecord();
856  }
857  }
858 }
859 
860 // Pivot table
861 
862 namespace {
863 
865 OUString lclGetDataFieldCaption( const OUString& rFieldName, ScGeneralFunction eFunc )
866 {
867  OUString aCaption;
868 
869  const char* pResIdx = nullptr;
870  switch( eFunc )
871  {
872  case ScGeneralFunction::SUM: pResIdx = STR_FUN_TEXT_SUM; break;
873  case ScGeneralFunction::COUNT: pResIdx = STR_FUN_TEXT_COUNT; break;
874  case ScGeneralFunction::AVERAGE: pResIdx = STR_FUN_TEXT_AVG; break;
875  case ScGeneralFunction::MAX: pResIdx = STR_FUN_TEXT_MAX; break;
876  case ScGeneralFunction::MIN: pResIdx = STR_FUN_TEXT_MIN; break;
877  case ScGeneralFunction::PRODUCT: pResIdx = STR_FUN_TEXT_PRODUCT; break;
878  case ScGeneralFunction::COUNTNUMS: pResIdx = STR_FUN_TEXT_COUNT; break;
879  case ScGeneralFunction::STDEV: pResIdx = STR_FUN_TEXT_STDDEV; break;
880  case ScGeneralFunction::STDEVP: pResIdx = STR_FUN_TEXT_STDDEV; break;
881  case ScGeneralFunction::VAR: pResIdx = STR_FUN_TEXT_VAR; break;
882  case ScGeneralFunction::VARP: pResIdx = STR_FUN_TEXT_VAR; break;
883  default:;
884  }
885  if (pResIdx)
886  aCaption = ScResId(pResIdx) + " - ";
887  aCaption += rFieldName;
888  return aCaption;
889 }
890 
891 } // namespace
892 
893 XclExpPTItem::XclExpPTItem( const XclExpPCField& rCacheField, sal_uInt16 nCacheIdx ) :
895  mpCacheItem( rCacheField.GetItem( nCacheIdx ) )
896 {
898  maItemInfo.mnCacheIdx = nCacheIdx;
900 }
901 
902 XclExpPTItem::XclExpPTItem( sal_uInt16 nItemType, sal_uInt16 nCacheIdx ) :
904  mpCacheItem( nullptr )
905 {
906  maItemInfo.mnType = nItemType;
907  maItemInfo.mnCacheIdx = nCacheIdx;
909 }
910 
912 {
913  return mpCacheItem ? mpCacheItem->ConvertToText() : OUString();
914 }
915 
917 {
918  // #i115659# GetIsVisible() is not valid if HasIsVisible() returns false, default is 'visible' then
919  ::set_flag( maItemInfo.mnFlags, EXC_SXVI_HIDDEN, rSaveMem.HasIsVisible() && !rSaveMem.GetIsVisible() );
920  // #i115659# GetShowDetails() is not valid if HasShowDetails() returns false, default is 'show detail' then
922 
923  // visible name
924  const std::optional<OUString> & pVisName = rSaveMem.GetLayoutName();
925  if (pVisName && *pVisName != GetItemName())
926  maItemInfo.SetVisName(*pVisName);
927 }
928 
930 {
931  rStrm << maItemInfo;
932 }
933 
934 XclExpPTField::XclExpPTField( const XclExpPivotTable& rPTable, sal_uInt16 nCacheIdx ) :
935  mrPTable( rPTable ),
936  mpCacheField( rPTable.GetCacheField( nCacheIdx ) )
937 {
938  maFieldInfo.mnCacheIdx = nCacheIdx;
939 
940  // create field items
941  if( mpCacheField )
942  for( sal_uInt16 nItemIdx = 0, nItemCount = mpCacheField->GetItemCount(); nItemIdx < nItemCount; ++nItemIdx )
944  maFieldInfo.mnItemCount = static_cast< sal_uInt16 >( maItemList.GetSize() );
945 }
946 
947 // data access ----------------------------------------------------------------
948 
950 {
951  return mpCacheField ? mpCacheField->GetFieldName() : OUString();
952 }
953 
955 {
956  OSL_ENSURE( !maDataInfoVec.empty(), "XclExpPTField::GetLastDataInfoIndex - no data info found" );
957  // will return 0xFFFF for empty vector -> ok
958  return static_cast< sal_uInt16 >( maDataInfoVec.size() - 1 );
959 }
960 
961 sal_uInt16 XclExpPTField::GetItemIndex( const OUString& rName, sal_uInt16 nDefaultIdx ) const
962 {
963  for( size_t nPos = 0, nSize = maItemList.GetSize(); nPos < nSize; ++nPos )
964  if( maItemList.GetRecord( nPos )->GetItemName() == rName )
965  return static_cast< sal_uInt16 >( nPos );
966  return nDefaultIdx;
967 }
968 
969 // fill data --------------------------------------------------------------
970 
975 static OUString lcl_convertCalcSubtotalName(const OUString& rName)
976 {
977  OUStringBuffer aBuf;
978  const sal_Unicode* p = rName.getStr();
979  sal_Int32 n = rName.getLength();
980  bool bEscaped = false;
981  for (sal_Int32 i = 0; i < n; ++i)
982  {
983  const sal_Unicode c = p[i];
984  if (!bEscaped && c == '\\')
985  {
986  bEscaped = true;
987  continue;
988  }
989 
990  aBuf.append(c);
991  bEscaped = false;
992  }
993  return aBuf.makeStringAndClear();
994 }
995 
997 {
998  // orientation
999  DataPilotFieldOrientation eOrient = rSaveDim.GetOrientation();
1000  OSL_ENSURE( eOrient != DataPilotFieldOrientation_DATA, "XclExpPTField::SetPropertiesFromDim - called for data field" );
1001  maFieldInfo.AddApiOrient( eOrient );
1002 
1003  // show empty items (#i115659# GetShowEmpty() is not valid if HasShowEmpty() returns false, default is false then)
1005 
1006  // visible name
1007  const std::optional<OUString> & pLayoutName = rSaveDim.GetLayoutName();
1008  if (pLayoutName && *pLayoutName != GetFieldName())
1009  maFieldInfo.SetVisName(*pLayoutName);
1010 
1011  const std::optional<OUString> & pSubtotalName = rSaveDim.GetSubtotalName();
1012  if (pSubtotalName)
1013  {
1014  OUString aSubName = lcl_convertCalcSubtotalName(*pSubtotalName);
1015  maFieldExtInfo.mpFieldTotalName = aSubName;
1016  }
1017 
1018  // subtotals
1019  XclPTSubtotalVec aSubtotals;
1020  aSubtotals.reserve( static_cast< size_t >( rSaveDim.GetSubTotalsCount() ) );
1021  for( long nSubtIdx = 0, nSubtCount = rSaveDim.GetSubTotalsCount(); nSubtIdx < nSubtCount; ++nSubtIdx )
1022  aSubtotals.push_back( rSaveDim.GetSubTotalFunc( nSubtIdx ) );
1023  maFieldInfo.SetSubtotals( aSubtotals );
1024 
1025  // sorting
1026  if( const DataPilotFieldSortInfo* pSortInfo = rSaveDim.GetSortInfo() )
1027  {
1028  maFieldExtInfo.SetApiSortMode( pSortInfo->Mode );
1029  if( pSortInfo->Mode == css::sheet::DataPilotFieldSortMode::DATA )
1031  ::set_flag( maFieldExtInfo.mnFlags, EXC_SXVDEX_SORT_ASC, pSortInfo->IsAscending );
1032  }
1033 
1034  // auto show
1035  if( const DataPilotFieldAutoShowInfo* pShowInfo = rSaveDim.GetAutoShowInfo() )
1036  {
1037  ::set_flag( maFieldExtInfo.mnFlags, EXC_SXVDEX_AUTOSHOW, pShowInfo->IsEnabled );
1038  maFieldExtInfo.SetApiAutoShowMode( pShowInfo->ShowItemsMode );
1039  maFieldExtInfo.SetApiAutoShowCount( pShowInfo->ItemCount );
1041  }
1042 
1043  // layout
1044  if( const DataPilotFieldLayoutInfo* pLayoutInfo = rSaveDim.GetLayoutInfo() )
1045  {
1046  maFieldExtInfo.SetApiLayoutMode( pLayoutInfo->LayoutMode );
1047  ::set_flag( maFieldExtInfo.mnFlags, EXC_SXVDEX_LAYOUT_BLANK, pLayoutInfo->AddEmptyLines );
1048  }
1049 
1050  // special page field properties
1051  if( eOrient == DataPilotFieldOrientation_PAGE )
1052  {
1055  }
1056 
1057  // item properties
1058  const ScDPSaveDimension::MemberList &rMembers = rSaveDim.GetMembers();
1059  for (const auto& pMember : rMembers)
1060  if( XclExpPTItem* pItem = GetItemAcc( pMember->GetName() ) )
1061  pItem->SetPropertiesFromMember( *pMember );
1062 }
1063 
1065 {
1066  maDataInfoVec.emplace_back( );
1067  XclPTDataFieldInfo& rDataInfo = maDataInfoVec.back();
1068  rDataInfo.mnField = GetFieldIndex();
1069 
1070  // orientation
1071  maFieldInfo.AddApiOrient( DataPilotFieldOrientation_DATA );
1072 
1073  // aggregation function
1074  ScGeneralFunction eFunc = rSaveDim.GetFunction();
1075  rDataInfo.SetApiAggFunc( eFunc );
1076 
1077  // visible name
1078  const std::optional<OUString> & pVisName = rSaveDim.GetLayoutName();
1079  if (pVisName)
1080  rDataInfo.SetVisName(*pVisName);
1081  else
1082  rDataInfo.SetVisName( lclGetDataFieldCaption( GetFieldName(), eFunc ) );
1083 
1084  // result field reference
1085  if( const DataPilotFieldReference* pFieldRef = rSaveDim.GetReferenceValue() )
1086  {
1087  rDataInfo.SetApiRefType( pFieldRef->ReferenceType );
1088  rDataInfo.SetApiRefItemType( pFieldRef->ReferenceItemType );
1089  if( const XclExpPTField* pRefField = mrPTable.GetField( pFieldRef->ReferenceField ) )
1090  {
1091  rDataInfo.mnRefField = pRefField->GetFieldIndex();
1092  if( pFieldRef->ReferenceItemType == css::sheet::DataPilotFieldReferenceItemType::NAMED )
1093  rDataInfo.mnRefItem = pRefField->GetItemIndex( pFieldRef->ReferenceItemName, 0 );
1094  }
1095  }
1096 }
1097 
1099 {
1112 }
1113 
1114 // records --------------------------------------------------------------------
1115 
1117 {
1118  rStrm << maPageInfo;
1119 }
1120 
1121 void XclExpPTField::WriteSxdi( XclExpStream& rStrm, sal_uInt16 nDataInfoIdx ) const
1122 {
1123  OSL_ENSURE( nDataInfoIdx < maDataInfoVec.size(), "XclExpPTField::WriteSxdi - data field not found" );
1124  if( nDataInfoIdx < maDataInfoVec.size() )
1125  {
1126  rStrm.StartRecord( EXC_ID_SXDI, 12 );
1127  rStrm << maDataInfoVec[ nDataInfoIdx ];
1128  rStrm.EndRecord();
1129  }
1130 }
1131 
1133 {
1134  // SXVD
1135  WriteSxvd( rStrm );
1136  // list of SXVI records
1137  maItemList.Save( rStrm );
1138  // SXVDEX
1139  WriteSxvdex( rStrm );
1140 }
1141 
1142 // private --------------------------------------------------------------------
1143 
1144 XclExpPTItem* XclExpPTField::GetItemAcc( const OUString& rName )
1145 {
1146  XclExpPTItem* pItem = nullptr;
1147  for( size_t nPos = 0, nSize = maItemList.GetSize(); !pItem && (nPos < nSize); ++nPos )
1148  if( maItemList.GetRecord( nPos )->GetItemName() == rName )
1149  pItem = maItemList.GetRecord( nPos );
1150  return pItem;
1151 }
1152 
1153 void XclExpPTField::AppendSubtotalItem( sal_uInt16 nItemType )
1154 {
1157 }
1158 
1160 {
1161  rStrm.StartRecord( EXC_ID_SXVD, 10 );
1162  rStrm << maFieldInfo;
1163  rStrm.EndRecord();
1164 }
1165 
1167 {
1168  rStrm.StartRecord( EXC_ID_SXVDEX, 20 );
1169  rStrm << maFieldExtInfo;
1170  rStrm.EndRecord();
1171 }
1172 
1173 XclExpPivotTable::XclExpPivotTable( const XclExpRoot& rRoot, const ScDPObject& rDPObj, const XclExpPivotCache& rPCache ) :
1174  XclExpRoot( rRoot ),
1175  mrPCache( rPCache ),
1176  maDataOrientField( *this, EXC_SXIVD_DATA ),
1177  mnOutScTab( 0 ),
1178  mbValid( false ),
1179  mbFilterBtn( false )
1180 {
1181  const ScRange& rOutScRange = rDPObj.GetOutRange();
1182  if( GetAddressConverter().ConvertRange( maPTInfo.maOutXclRange, rOutScRange, true ) )
1183  {
1184  // DataPilot properties -----------------------------------------------
1185 
1186  // pivot table properties from DP object
1187  mnOutScTab = rOutScRange.aStart.Tab();
1188  maPTInfo.maTableName = rDPObj.GetName();
1190 
1191  maPTViewEx9Info.Init( rDPObj );
1192 
1193  if( const ScDPSaveData* pSaveData = rDPObj.GetSaveData() )
1194  {
1195  // additional properties from ScDPSaveData
1196  SetPropertiesFromDP( *pSaveData );
1197 
1198  // loop over all dimensions ---------------------------------------
1199 
1200  /* 1) Default-construct all pivot table fields for all pivot cache fields. */
1201  for( sal_uInt16 nFieldIdx = 0, nFieldCount = mrPCache.GetFieldCount(); nFieldIdx < nFieldCount; ++nFieldIdx )
1202  maFieldList.AppendNewRecord( new XclExpPTField( *this, nFieldIdx ) );
1203 
1204  const ScDPSaveData::DimsType& rDimList = pSaveData->GetDimensions();
1205 
1206  /* 2) First process all data dimensions, they are needed for extended
1207  settings of row/column/page fields (sorting/auto show). */
1208  for (auto const& iter : rDimList)
1209  {
1210  if (iter->GetOrientation() == DataPilotFieldOrientation_DATA)
1212  }
1213 
1214  /* 3) Row/column/page/hidden fields. */
1215  for (auto const& iter : rDimList)
1216  {
1217  if (iter->GetOrientation() != DataPilotFieldOrientation_DATA)
1219  }
1220 
1221  // Finalize -------------------------------------------------------
1222 
1223  Finalize();
1224  mbValid = true;
1225  }
1226  }
1227 }
1228 
1229 const XclExpPCField* XclExpPivotTable::GetCacheField( sal_uInt16 nCacheIdx ) const
1230 {
1231  return mrPCache.GetField( nCacheIdx );
1232 }
1233 
1234 const XclExpPTField* XclExpPivotTable::GetField( sal_uInt16 nFieldIdx ) const
1235 {
1236  return (nFieldIdx == EXC_SXIVD_DATA) ? &maDataOrientField : maFieldList.GetRecord( nFieldIdx );
1237 }
1238 
1239 const XclExpPTField* XclExpPivotTable::GetField( const OUString& rName ) const
1240 {
1241  return const_cast< XclExpPivotTable* >( this )->GetFieldAcc( rName );
1242 }
1243 
1244 sal_uInt16 XclExpPivotTable::GetDataFieldIndex( const OUString& rName, sal_uInt16 nDefaultIdx ) const
1245 {
1246  auto aIt = std::find_if(maDataFields.begin(), maDataFields.end(),
1247  [this, &rName](const XclPTDataFieldPos& rDataField) {
1248  const XclExpPTField* pField = GetField( rDataField.first );
1249  return pField && pField->GetFieldName() == rName;
1250  });
1251  if (aIt != maDataFields.end())
1252  return static_cast< sal_uInt16 >( std::distance(maDataFields.begin(), aIt) );
1253  return nDefaultIdx;
1254 }
1255 
1257 {
1258  if( mbValid )
1259  {
1260  // SXVIEW
1261  WriteSxview( rStrm );
1262  // pivot table fields (SXVD, SXVDEX, and item records)
1263  maFieldList.Save( rStrm );
1264  // SXIVD records for row and column fields
1265  WriteSxivd( rStrm, maRowFields );
1266  WriteSxivd( rStrm, maColFields );
1267  // SXPI
1268  WriteSxpi( rStrm );
1269  // list of SXDI records containing data field info
1270  WriteSxdiList( rStrm );
1271  // SXLI records
1274  // SXEX
1275  WriteSxex( rStrm );
1276  // QSISXTAG
1277  WriteQsiSxTag( rStrm );
1278  // SXVIEWEX9
1279  WriteSxViewEx9( rStrm );
1280  }
1281 }
1282 
1284 {
1285  XclExpPTField* pField = nullptr;
1286  for( size_t nPos = 0, nSize = maFieldList.GetSize(); !pField && (nPos < nSize); ++nPos )
1287  if( maFieldList.GetRecord( nPos )->GetFieldName() == rName )
1288  pField = maFieldList.GetRecord( nPos );
1289  return pField;
1290 }
1291 
1293 {
1294  // data field orientation field?
1295  if( rSaveDim.IsDataLayout() )
1296  return &maDataOrientField;
1297 
1298  // a real dimension
1299  OUString aFieldName = ScDPUtil::getSourceDimensionName(rSaveDim.GetName());
1300  return aFieldName.isEmpty() ? nullptr : GetFieldAcc(aFieldName);
1301 }
1302 
1303 // fill data --------------------------------------------------------------
1304 
1306 {
1310  mbFilterBtn = rSaveData.GetFilterButton();
1311  const ScDPSaveDimension* pDim = rSaveData.GetExistingDataLayoutDimension();
1312 
1313  if (pDim && pDim->GetLayoutName())
1314  maPTInfo.maDataName = *pDim->GetLayoutName();
1315  else
1316  maPTInfo.maDataName = ScResId(STR_PIVOT_DATA);
1317 }
1318 
1320 {
1321  if( XclExpPTField* pField = GetFieldAcc( rSaveDim ) )
1322  {
1323  // field properties
1324  pField->SetPropertiesFromDim( rSaveDim );
1325 
1326  // update the corresponding field position list
1327  DataPilotFieldOrientation eOrient = rSaveDim.GetOrientation();
1328  sal_uInt16 nFieldIdx = pField->GetFieldIndex();
1329  bool bDataLayout = nFieldIdx == EXC_SXIVD_DATA;
1330  bool bMultiData = maDataFields.size() > 1;
1331 
1332  if( !bDataLayout || bMultiData ) switch( eOrient )
1333  {
1334  case DataPilotFieldOrientation_ROW:
1335  maRowFields.push_back( nFieldIdx );
1336  if( bDataLayout )
1338  break;
1339  case DataPilotFieldOrientation_COLUMN:
1340  maColFields.push_back( nFieldIdx );
1341  if( bDataLayout )
1343  break;
1344  case DataPilotFieldOrientation_PAGE:
1345  maPageFields.push_back( nFieldIdx );
1346  OSL_ENSURE( !bDataLayout, "XclExpPivotTable::SetFieldPropertiesFromDim - wrong orientation for data fields" );
1347  break;
1348  case DataPilotFieldOrientation_DATA:
1349  OSL_FAIL( "XclExpPivotTable::SetFieldPropertiesFromDim - called for data field" );
1350  break;
1351  default:;
1352  }
1353  }
1354 }
1355 
1357 {
1358  if( XclExpPTField* pField = GetFieldAcc( rSaveDim ) )
1359  {
1360  // field properties
1361  pField->SetDataPropertiesFromDim( rSaveDim );
1362  // update the data field position list
1363  maDataFields.emplace_back( pField->GetFieldIndex(), pField->GetLastDataInfoIndex() );
1364  }
1365 }
1366 
1368 {
1369  // field numbers
1370  maPTInfo.mnFields = static_cast< sal_uInt16 >( maFieldList.GetSize() );
1371  maPTInfo.mnRowFields = static_cast< sal_uInt16 >( maRowFields.size() );
1372  maPTInfo.mnColFields = static_cast< sal_uInt16 >( maColFields.size() );
1373  maPTInfo.mnPageFields = static_cast< sal_uInt16 >( maPageFields.size() );
1374  maPTInfo.mnDataFields = static_cast< sal_uInt16 >( maDataFields.size() );
1375 
1378 
1379  // subtotal items
1380  for( size_t nPos = 0, nSize = maFieldList.GetSize(); nPos < nSize; ++nPos )
1382 
1383  // find data field orientation field
1385  const ScfUInt16Vec* pFieldVec = nullptr;
1386  switch( maPTInfo.mnDataAxis )
1387  {
1388  case EXC_SXVD_AXIS_ROW: pFieldVec = &maRowFields; break;
1389  case EXC_SXVD_AXIS_COL: pFieldVec = &maColFields; break;
1390  }
1391 
1392  if( pFieldVec && !pFieldVec->empty() && (pFieldVec->back() != EXC_SXIVD_DATA) )
1393  {
1394  ScfUInt16Vec::const_iterator aIt = ::std::find( pFieldVec->begin(), pFieldVec->end(), EXC_SXIVD_DATA );
1395  if( aIt != pFieldVec->end() )
1396  maPTInfo.mnDataPos = static_cast< sal_uInt16 >( std::distance(pFieldVec->begin(), aIt) );
1397  }
1398 
1399  // single data field is always row oriented
1402 
1403  // update output range (initialized in ctor)
1404  sal_uInt16& rnXclCol1 = maPTInfo.maOutXclRange.maFirst.mnCol;
1405  sal_uInt32& rnXclRow1 = maPTInfo.maOutXclRange.maFirst.mnRow;
1406  sal_uInt16& rnXclCol2 = maPTInfo.maOutXclRange.maLast.mnCol;
1407  sal_uInt32& rnXclRow2 = maPTInfo.maOutXclRange.maLast.mnRow;
1408  // exclude page fields from output range
1409  rnXclRow1 = rnXclRow1 + maPTInfo.mnPageFields;
1410  // exclude filter button from output range
1411  if( mbFilterBtn )
1412  ++rnXclRow1;
1413  // exclude empty row between (filter button and/or page fields) and table
1415  ++rnXclRow1;
1416 
1417  // data area
1418  sal_uInt16& rnDataXclCol = maPTInfo.maDataXclPos.mnCol;
1419  sal_uInt32& rnDataXclRow = maPTInfo.maDataXclPos.mnRow;
1420  rnDataXclCol = rnXclCol1 + maPTInfo.mnRowFields;
1421  rnDataXclRow = rnXclRow1 + maPTInfo.mnColFields + 1;
1422  if( maDataFields.empty() )
1423  ++rnDataXclRow;
1424 
1425  bool bExtraHeaderRow = (0 == maPTViewEx9Info.mnGridLayout && maPTInfo.mnColFields == 0);
1426  if (bExtraHeaderRow)
1427  // Insert an extra row only when there is no column field.
1428  ++rnDataXclRow;
1429 
1430  rnXclCol2 = ::std::max( rnXclCol2, rnDataXclCol );
1431  rnXclRow2 = ::std::max( rnXclRow2, rnDataXclRow );
1432  maPTInfo.mnDataCols = rnXclCol2 - rnDataXclCol + 1;
1433  maPTInfo.mnDataRows = rnXclRow2 - rnDataXclRow + 1;
1434 
1435  // first heading
1436  maPTInfo.mnFirstHeadRow = rnXclRow1 + 1;
1437  if (bExtraHeaderRow)
1438  maPTInfo.mnFirstHeadRow += 1;
1439 }
1440 
1441 // records ----------------------------------------------------------------
1442 
1444 {
1445  rStrm.StartRecord( EXC_ID_SXVIEW, 46 + maPTInfo.maTableName.getLength() + maPTInfo.maDataName.getLength() );
1446  rStrm << maPTInfo;
1447  rStrm.EndRecord();
1448 }
1449 
1451 {
1452  if( !rFields.empty() )
1453  {
1454  rStrm.StartRecord( EXC_ID_SXIVD, rFields.size() * 2 );
1455  for( const auto& rField : rFields )
1456  rStrm << rField;
1457  rStrm.EndRecord();
1458  }
1459 }
1460 
1462 {
1463  if( !maPageFields.empty() )
1464  {
1465  rStrm.StartRecord( EXC_ID_SXPI, maPageFields.size() * 6 );
1466  rStrm.SetSliceSize( 6 );
1467  for( const auto& rPageField : maPageFields )
1468  {
1469  XclExpPTFieldRef xField = maFieldList.GetRecord( rPageField );
1470  if( xField )
1471  xField->WriteSxpiEntry( rStrm );
1472  }
1473  rStrm.EndRecord();
1474  }
1475 }
1476 
1478 {
1479  for( const auto& [rFieldIdx, rDataInfoIdx] : maDataFields )
1480  {
1481  XclExpPTFieldRef xField = maFieldList.GetRecord( rFieldIdx );
1482  if( xField )
1483  xField->WriteSxdi( rStrm, rDataInfoIdx );
1484  }
1485 }
1486 
1487 void XclExpPivotTable::WriteSxli( XclExpStream& rStrm, sal_uInt16 nLineCount, sal_uInt16 nIndexCount )
1488 {
1489  if( nLineCount > 0 )
1490  {
1491  std::size_t nLineSize = 8 + 2 * nIndexCount;
1492  rStrm.StartRecord( EXC_ID_SXLI, nLineSize * nLineCount );
1493 
1494  /* Excel expects the records to be filled completely, do not
1495  set a segment size... */
1496 // rStrm.SetSliceSize( nLineSize );
1497 
1498  for( sal_uInt16 nLine = 0; nLine < nLineCount; ++nLine )
1499  {
1500  // Excel XP needs a partly initialized SXLI record
1501  rStrm << sal_uInt16( 0 ) // number of equal index entries
1503  << nIndexCount
1505  rStrm.WriteZeroBytes( 2 * nIndexCount );
1506  }
1507  rStrm.EndRecord();
1508  }
1509 }
1510 
1512 {
1513  rStrm.StartRecord( EXC_ID_SXEX, 24 );
1514  rStrm << maPTExtInfo;
1515  rStrm.EndRecord();
1516 }
1517 
1519 {
1520  rStrm.StartRecord( 0x0802, 32 );
1521 
1522  sal_uInt16 const nRecordType = 0x0802;
1523  sal_uInt16 const nDummyFlags = 0x0000;
1524  sal_uInt16 const nTableType = 1; // 0 = query table : 1 = pivot table
1525 
1526  rStrm << nRecordType << nDummyFlags << nTableType;
1527 
1528  // General flags
1529  sal_uInt16 const nFlags = 0x0001;
1530 #if 0
1531  // for doc purpose
1532  sal_uInt16 nFlags = 0x0000;
1533  bool bEnableRefresh = true;
1534  bool bPCacheInvalid = false;
1535  bool bOlapPTReport = false;
1536 
1537  if (bEnableRefresh) nFlags |= 0x0001;
1538  if (bPCacheInvalid) nFlags |= 0x0002;
1539  if (bOlapPTReport) nFlags |= 0x0004;
1540 #endif
1541  rStrm << nFlags;
1542 
1543  // Feature-specific options. The value differs depending on the table
1544  // type, but we assume the table type is always pivot table.
1545  sal_uInt32 const nOptions = 0x00000000;
1546 #if 0
1547  // documentation for which bit is for what
1548  bool bNoStencil = false;
1549  bool bHideTotal = false;
1550  bool bEmptyRows = false;
1551  bool bEmptyCols = false;
1552  if (bNoStencil) nOptions |= 0x00000001;
1553  if (bHideTotal) nOptions |= 0x00000002;
1554  if (bEmptyRows) nOptions |= 0x00000008;
1555  if (bEmptyCols) nOptions |= 0x00000010;
1556 #endif
1557  rStrm << nOptions;
1558 
1559  sal_uInt8 eXclVer = 0; // Excel2000
1560  sal_uInt8 const nOffsetBytes = 16;
1561  rStrm << eXclVer // version table last refreshed
1562  << eXclVer // minimum version to refresh
1563  << nOffsetBytes
1564  << eXclVer; // first version created
1565 
1566  rStrm << XclExpString(maPTInfo.maTableName);
1567  rStrm << static_cast<sal_uInt16>(0x0001); // no idea what this is for.
1568 
1569  rStrm.EndRecord();
1570 }
1571 
1573 {
1574  // Until we sync the autoformat ids only export if using grid header layout
1575  // That could only have been set via xls import so far.
1576  if ( 0 == maPTViewEx9Info.mnGridLayout )
1577  {
1578  rStrm.StartRecord( EXC_ID_SXVIEWEX9, 17 );
1579  rStrm << maPTViewEx9Info;
1580  rStrm.EndRecord();
1581  }
1582 }
1583 
1584 namespace {
1585 
1586 const SCTAB EXC_PTMGR_PIVOTCACHES = SCTAB_MAX;
1587 
1589 class XclExpPivotRecWrapper : public XclExpRecordBase
1590 {
1591 public:
1592  explicit XclExpPivotRecWrapper( XclExpPivotTableManager& rPTMgr, SCTAB nScTab );
1593  virtual void Save( XclExpStream& rStrm ) override;
1594 private:
1595  XclExpPivotTableManager& mrPTMgr;
1596  SCTAB mnScTab;
1597 };
1598 
1599 XclExpPivotRecWrapper::XclExpPivotRecWrapper( XclExpPivotTableManager& rPTMgr, SCTAB nScTab ) :
1600  mrPTMgr( rPTMgr ),
1601  mnScTab( nScTab )
1602 {
1603 }
1604 
1605 void XclExpPivotRecWrapper::Save( XclExpStream& rStrm )
1606 {
1607  if( mnScTab == EXC_PTMGR_PIVOTCACHES )
1608  mrPTMgr.WritePivotCaches( rStrm );
1609  else
1610  mrPTMgr.WritePivotTables( rStrm, mnScTab );
1611 }
1612 
1613 } // namespace
1614 
1616  XclExpRoot( rRoot )
1617 {
1618 }
1619 
1621 {
1622  if( ScDPCollection* pDPColl = GetDoc().GetDPCollection() )
1623  for( size_t nDPObj = 0, nCount = pDPColl->GetCount(); nDPObj < nCount; ++nDPObj )
1624  {
1625  ScDPObject& rDPObj = (*pDPColl)[ nDPObj ];
1626  if( const XclExpPivotCache* pPCache = CreatePivotCache( rDPObj ) )
1627  maPTableList.AppendNewRecord( new XclExpPivotTable( GetRoot(), rDPObj, *pPCache ) );
1628  }
1629 }
1630 
1632 {
1633  return new XclExpPivotRecWrapper( *this, EXC_PTMGR_PIVOTCACHES );
1634 }
1635 
1637 {
1638  return new XclExpPivotRecWrapper( *this, nScTab );
1639 }
1640 
1642 {
1643  maPCacheList.Save( rStrm );
1644 }
1645 
1647 {
1648  for( size_t nPos = 0, nSize = maPTableList.GetSize(); nPos < nSize; ++nPos )
1649  {
1651  if( xPTable->GetScTab() == nScTab )
1652  xPTable->Save( rStrm );
1653  }
1654 }
1655 
1657 {
1658  // try to find a pivot cache with the same data source
1659  /* #i25110# In Excel, the pivot cache contains additional fields
1660  (i.e. grouping info, calculated fields). If the passed DataPilot object
1661  or the found cache contains this data, do not share the cache with
1662  multiple pivot tables. */
1663  if( const ScDPSaveData* pSaveData = rDPObj.GetSaveData() )
1664  {
1665  const ScDPDimensionSaveData* pDimSaveData = pSaveData->GetExistingDimensionData();
1666  // no dimension save data at all or save data does not contain grouping info
1667  if( !pDimSaveData || !pDimSaveData->HasGroupDimensions() )
1668  {
1669  // check all existing pivot caches
1670  for( size_t nPos = 0, nSize = maPCacheList.GetSize(); nPos < nSize; ++nPos )
1671  {
1673  // pivot cache does not have grouping info and source data is equal
1674  if( !pPCache->HasAddFields() && pPCache->HasEqualDataSource( rDPObj ) )
1675  return pPCache;
1676  }
1677  }
1678  }
1679 
1680  // create a new pivot cache
1681  sal_uInt16 nNewCacheIdx = static_cast< sal_uInt16 >( maPCacheList.GetSize() );
1682  XclExpPivotCacheRef xNewPCache = new XclExpPivotCache( GetRoot(), rDPObj, nNewCacheIdx );
1683  if( xNewPCache->IsValid() )
1684  {
1685  maPCacheList.AppendRecord( xNewPCache.get() );
1686  return xNewPCache.get();
1687  }
1688 
1689  return nullptr;
1690 }
1691 
1692 /* 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:1098
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:996
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:690
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:696
void WriteSxdiList(XclExpStream &rStrm) const
Writes all SXDI records containing info about the data fields.
Definition: xepivot.cxx:1477
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:1319
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
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:1461
void CreatePivotTables()
Creates all pivot tables and caches from the Calc DataPilot objects.
Definition: xepivot.cxx:1620
bool GetIsVisible() const
Definition: dpsave.hxx:71
XclExpPivotTable(const XclExpRoot &rRoot, const ScDPObject &rDPObj, const XclExpPivotCache &rPCache)
Definition: xepivot.cxx:1173
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:1511
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:1450
void SetPropertiesFromMember(const ScDPSaveMember &rSaveMem)
Fills this item with properties from the passed save member.
Definition: xepivot.cxx:916
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:278
sal_uInt16 mnGroupChild
Various flags.
Definition: xlpivot.hxx:440
SvNumberFormatter & GetFormatter() const
Returns the number formatter of the Calc document.
Definition: xlroot.cxx:315
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:961
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:254
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:1116
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:1646
OUString GetFieldName() const
Returns the name of this field.
Definition: xepivot.cxx:949
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:1631
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:1144
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:975
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:1132
XclExpPTItem(const XclExpPCField &rCacheField, sal_uInt16 nCacheIdx)
Definition: xepivot.cxx:893
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:685
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:675
void SetNumGroupLimit(const ScDPNumGroupInfo &rNumInfo)
Inserts the SXDOUBLE items that specify the limits for a numeric grouping.
Definition: xepivot.cxx:543
void WriteSxvdex(XclExpStream &rStrm) const
Writes the SXVDEX record containing additional settings.
Definition: xepivot.cxx:1166
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:1656
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:1121
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:552
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:1356
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:841
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:911
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:729
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:1443
void AppendSubtotalItem(sal_uInt16 nItemType)
Appends a special item describing a field subtotal entry.
Definition: xepivot.cxx:1153
const sal_uInt16 EXC_SXFIELD_HASITEMS
Definition: xlpivot.hxx:224
OUString GetFormattedString(long nDim, const ScDPItemData &rItem, bool bLocaleIndependent) const
Definition: dpcache.cxx:1211
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:345
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:737
SC_DLLPUBLIC ScDPSaveDimension * GetExistingDataLayoutDimension() const
Definition: dpsave.cxx:876
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:562
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:1636
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:580
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:934
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:1283
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:614
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:806
void SetPropertiesFromDP(const ScDPSaveData &rSaveData)
Fills internal members with all properties from the passed save data.
Definition: xepivot.cxx:1305
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:929
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:706
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:826
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:1159
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:1487
void InsertOrigBoolItem(bool bValue, const OUString &rText)
Inserts an original boolean item, if it is not contained already.
Definition: xepivot.cxx:491
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:1615
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:1572
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:752
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 & 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:798
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:1367
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:833
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:1229
void WritePivotCaches(XclExpStream &rStrm)
Writes all pivot caches (all Workbook records and cache streams).
Definition: xepivot.cxx:1641
void SetDataPropertiesFromDim(const ScDPSaveDimension &rSaveDim)
Fills this field with data field properties from the passed save dimension.
Definition: xepivot.cxx:1064
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:1256
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:725
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:680
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:1234
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:785
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:596
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:266
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:609
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:954
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:212
const sal_uInt16 EXC_SXVI_TYPE_COUNTNUM
Definition: xlpivot.hxx:148
void WriteQsiSxTag(XclExpStream &rStrm) const
Definition: xepivot.cxx:1518
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:1244
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