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