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