sc/inc/dpobject.hxx                         |   44 +++++++++++++++++++-------
 sc/source/core/data/dpobject.cxx            |    6 +--
 sc/source/filter/excel/xepivotxml.cxx       |   46 +++++++---------------------
 sc/source/filter/inc/pivottablebuffer.hxx   |    8 +---
 sc/source/filter/oox/pivottablebuffer.cxx   |   16 +--------
 sc/source/filter/oox/pivottablefragment.cxx |   14 +++++++-
 6 files changed, 65 insertions(+), 69 deletions(-)

New commits:
commit 34dab6c599fea8b72eb73f8523469c1ab8282f67
Author:     Tomaž Vajngerl <[email protected]>
AuthorDate: Fri Nov 14 19:23:57 2025 +0900
Commit:     Tomaž Vajngerl <[email protected]>
CommitDate: Fri Dec 5 12:55:31 2025 +0100

    sc: remove grab bag from pivot table, add PivotTableStyleInfo
    
    This removes the grab bag from the pivot table, which was used to
    store the pivotTableStyleInfo element. Instead of this add a struct
    to store the style info data and add that to the DPObject. With
    this we can actually take the information and use when we output
    the pivot table to the sheet.
    
    Change-Id: I1226b80ac0083797c08a20342603c652c43a9568
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194017
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194999
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>

diff --git a/sc/inc/dpobject.hxx b/sc/inc/dpobject.hxx
index ce05a46f7c6b..ac563a513a71 100644
--- a/sc/inc/dpobject.hxx
+++ b/sc/inc/dpobject.hxx
@@ -80,6 +80,26 @@ struct ScDPServiceDesc
     bool operator== ( const ScDPServiceDesc& rOther ) const;
 };
 
+namespace sc
+{
+
+struct PivotTableStyleInfo
+{
+    OUString maName;
+    bool mbShowRowHeaders = false;
+    bool mbShowColHeaders = false;
+    bool mbShowRowStripes = false;
+    bool mbShowColStripes = false;
+    bool mbShowLastColumn = false;
+
+    bool isSet() const
+    {
+        return !maName.isEmpty();
+    }
+};
+
+}
+
 class ScDPObject
 {
 private:
@@ -109,6 +129,8 @@ private:
     bool mbEnableGetPivotData : 1;
     bool mbHideHeader : 1 = false;
 
+    sc::PivotTableStyleInfo maStyleInfo;
+
     void              CreateObjects();
     void              CreateOutput();
     void ClearSource();
@@ -246,6 +268,16 @@ public:
     // (button attribute must be present)
     void                RefreshAfterLoad();
 
+    sc::PivotTableStyleInfo const& getStyleInfo() const
+    {
+        return maStyleInfo;
+    }
+
+    void setStyleInfo(sc::PivotTableStyleInfo const& rStyleInfo)
+    {
+        maStyleInfo = rStyleInfo;
+    }
+
     SC_DLLPUBLIC void BuildAllDimensionMembers();
 
     /**
@@ -270,18 +302,6 @@ public:
 
     SC_DLLPUBLIC static bool IsOrientationAllowed( 
css::sheet::DataPilotFieldOrientation nOrient, sal_Int32 nDimFlags );
 
-    void PutInteropGrabBag(std::map<OUString, css::uno::Any>&& val)
-    {
-        maInteropGrabBag = std::move(val);
-    }
-    std::pair<bool, css::uno::Any> GetInteropGrabBagValue(const OUString& 
sName) const
-    {
-        if (const auto it = maInteropGrabBag.find(sName); it != 
maInteropGrabBag.end())
-            return { true, it->second };
-
-        return { false, css::uno::Any() };
-    }
-
 #if DUMP_PIVOT_TABLE
     void Dump() const;
     void DumpCache() const;
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index c96ccaa7de74..e13100230578 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -323,13 +323,13 @@ ScDPObject::ScDPObject(const ScDPObject& rOther)
     , maTableName(rOther.maTableName)
     , maTableTag(rOther.maTableTag)
     , maOutputRange(rOther.maOutputRange)
-    , maInteropGrabBag(rOther.maInteropGrabBag)
     , mnHeaderRows(rOther.mnHeaderRows)
     , mbHeaderLayout(rOther.mbHeaderLayout)
     , mbAllowMove(false)
     , mbSettingsChanged(false)
     , mbEnableGetPivotData(rOther.mbEnableGetPivotData)
     , mbHideHeader(rOther.mbHideHeader)
+    , maStyleInfo(rOther.maStyleInfo)
 {
     if (rOther.mpSaveData)
         mpSaveData.reset(new ScDPSaveData(*rOther.mpSaveData));
@@ -357,13 +357,13 @@ ScDPObject& ScDPObject::operator= (const ScDPObject& 
rOther)
         maTableName = rOther.maTableName;
         maTableTag = rOther.maTableTag;
         maOutputRange = rOther.maOutputRange;
-        maInteropGrabBag = rOther.maInteropGrabBag;
         mnHeaderRows = rOther.mnHeaderRows;
         mbHeaderLayout =rOther.mbHeaderLayout;
         mbAllowMove = false;
         mbSettingsChanged = false;
         mbEnableGetPivotData = rOther.mbEnableGetPivotData;
         mbHideHeader = rOther.mbHideHeader;
+        maStyleInfo = rOther.maStyleInfo;
 
         if (rOther.mpSaveData)
             mpSaveData.reset(new ScDPSaveData(*rOther.mpSaveData));
@@ -798,13 +798,13 @@ void ScDPObject::InvalidateData()
 
 void ScDPObject::Clear()
 {
+    maStyleInfo = {};
     mpOutput.reset();
     mpSaveData.reset();
     mpSheetDescription.reset();
     mpImportDescription.reset();
     mpServiceDescription.reset();
     ClearTableData();
-    maInteropGrabBag.clear();
 }
 
 void ScDPObject::ClearTableData()
diff --git a/sc/source/filter/excel/xepivotxml.cxx 
b/sc/source/filter/excel/xepivotxml.cxx
index f48569f32faa..bbd70dd86557 100644
--- a/sc/source/filter/excel/xepivotxml.cxx
+++ b/sc/source/filter/excel/xepivotxml.cxx
@@ -711,38 +711,6 @@ sal_Int32 GetSubtotalAttrToken(ScGeneralFunction eFunc)
     return XML_defaultSubtotal;
 }
 
-// An item is expected to contain sequences of css::xml::FastAttribute and 
css::xml::Attribute
-void WriteGrabBagItemToStream(XclExpXmlStream& rStrm, sal_Int32 tokenId, const 
css::uno::Any& rItem)
-{
-    css::uno::Sequence<css::uno::Any> aSeqs;
-    if(!(rItem >>= aSeqs))
-        return;
-
-    auto& pStrm = rStrm.GetCurrentStream();
-    pStrm->write("<")->writeId(tokenId);
-
-    css::uno::Sequence<css::xml::FastAttribute> aFastSeq;
-    css::uno::Sequence<css::xml::Attribute> aUnkSeq;
-    for (const auto& a : aSeqs)
-    {
-        if (a >>= aFastSeq)
-        {
-            for (const auto& rAttr : aFastSeq)
-                rStrm.WriteAttributes(rAttr.Token, rAttr.Value);
-        }
-        else if (a >>= aUnkSeq)
-        {
-            for (const auto& rAttr : aUnkSeq)
-                pStrm->write(" ")
-                    ->write(rAttr.Name)
-                    ->write("=\"")
-                    ->writeEscaped(rAttr.Value)
-                    ->write("\"");
-        }
-    }
-
-    pStrm->write("/>");
-}
 }
 
 void XclExpXmlPivotTables::SavePivotTableXml( XclExpXmlStream& rStrm, const 
ScDPObject& rDPObj, sal_Int32 nCacheId )
@@ -1253,13 +1221,23 @@ void XclExpXmlPivotTables::SavePivotTableXml( 
XclExpXmlStream& rStrm, const ScDP
     savePivotTableFormats(rStrm, rDPObj);
 
     // Now add style info (use grab bag, or just a set which is default on 
Excel 2007 through 2016)
-    if (const auto [bHas, aVal] = 
rDPObj.GetInteropGrabBagValue(u"pivotTableStyleInfo"_ustr); bHas)
-        WriteGrabBagItemToStream(rStrm, XML_pivotTableStyleInfo, aVal);
+    auto const& rStyleInfo = rDPObj.getStyleInfo();
+    if (rStyleInfo.isSet())
+    {
+        pPivotStrm->singleElement(XML_pivotTableStyleInfo, XML_name, 
rStyleInfo.maName,
+                                  XML_showRowHeaders, 
rStyleInfo.mbShowRowHeaders ? "1" : "0",
+                                  XML_showColHeaders, 
rStyleInfo.mbShowColHeaders ? "1" : "0",
+                                  XML_showRowStripes, 
rStyleInfo.mbShowRowStripes ? "1" : "0",
+                                  XML_showColStripes, 
rStyleInfo.mbShowColStripes ? "1" : "0",
+                                  XML_showLastColumn, 
rStyleInfo.mbShowLastColumn ? "1" : "0");
+    }
     else
+    {
         pPivotStrm->singleElement(XML_pivotTableStyleInfo, XML_name, 
"PivotStyleLight16",
                                   XML_showRowHeaders, "1", XML_showColHeaders, 
"1",
                                   XML_showRowStripes, "0", XML_showColStripes, 
"0",
                                   XML_showLastColumn, "1");
+    }
 
     OUString aBuf = "../pivotCache/pivotCacheDefinition" +
         OUString::number(nCacheId) +
diff --git a/sc/source/filter/inc/pivottablebuffer.hxx 
b/sc/source/filter/inc/pivottablebuffer.hxx
index 2c032277e90e..a760d54e423c 100644
--- a/sc/source/filter/inc/pivottablebuffer.hxx
+++ b/sc/source/filter/inc/pivottablebuffer.hxx
@@ -23,6 +23,7 @@
 #include "PivotTableFormat.hxx"
 #include "stylesbuffer.hxx"
 #include <rtl/ref.hxx>
+#include <dpobject.hxx>
 
 namespace com::sun::star {
     namespace sheet { class XDataPilotDescriptor; }
@@ -299,9 +300,6 @@ public:
     void                importPageField( const AttributeList& rAttribs );
     /** Reads the settings of a field located in the data dimension from the 
dataField element. */
     void                importDataField( const AttributeList& rAttribs );
-    /** Puts the attributes to the named grab bag value. */
-    void putToInteropGrabBag(const OUString& sName, const AttributeList& 
rAttribs);
-
     /** Reads global pivot table settings from the PTDEFINITION record. */
     void                importPTDefinition( SequenceInputStream& rStrm );
     /** Reads the location of the pivot table from the PTLOCATION record. */
@@ -354,7 +352,7 @@ public:
     sal_Int32           getCacheDatabaseIndex( sal_Int32 nFieldIdx ) const;
 
     ScDPObject* getDPObject() { return mpDPObject; }
-
+    sc::PivotTableStyleInfo& getStyleInfo() { return maStyleInfo; }
 private:
     typedef RefVector< PivotTableField >        PivotTableFieldVector;
     typedef RefVector< PivotTableFilter >       PivotTableFilterVector;
@@ -386,7 +384,7 @@ private:
     PivotCache*           mpPivotCache;       /// The pivot cache this table 
is based on.
     rtl::Reference< ScDataPilotDescriptorBase > // 
css::sheet::XDataPilotDescriptor
                           mxDPDescriptor;     /// Descriptor of the DataPilot 
object.
-    std::map<OUString, css::uno::Any> maInteropGrabBag;
+    sc::PivotTableStyleInfo maStyleInfo;
 
 };
 
diff --git a/sc/source/filter/oox/pivottablebuffer.cxx 
b/sc/source/filter/oox/pivottablebuffer.cxx
index 15041c45343e..e86739466bad 100644
--- a/sc/source/filter/oox/pivottablebuffer.cxx
+++ b/sc/source/filter/oox/pivottablebuffer.cxx
@@ -1081,18 +1081,6 @@ void PivotTable::importDataField( const AttributeList& 
rAttribs )
     maDataFields.push_back( aModel );
 }
 
-void PivotTable::putToInteropGrabBag(const OUString& sName, const 
AttributeList& rAttribs)
-{
-    if (auto xFastAttributeList = rAttribs.getFastAttributeList())
-    {
-        // Store both known and unknown attribute sequences to the grab bag as 
is
-        css::uno::Sequence<css::xml::FastAttribute> aFast = 
xFastAttributeList->getFastAttributes();
-        css::uno::Sequence<css::xml::Attribute> aUnk = 
xFastAttributeList->getUnknownAttributes();
-        css::uno::Sequence<css::uno::Any> aVal{ css::uno::Any(aFast), 
css::uno::Any(aUnk) };
-        maInteropGrabBag[sName] <<= aVal;
-    }
-}
-
 void PivotTable::importPTDefinition( SequenceInputStream& rStrm )
 {
     sal_uInt32 nFlags1, nFlags2, nFlags3;
@@ -1351,8 +1339,8 @@ void PivotTable::finalizeImport()
         if( !maPageFields.empty() )
             aPos.Row = ::std::max< sal_Int32 >( static_cast< sal_Int32 >( 
aPos.Row - maPageFields.size() - 1 ), 0 );
 
-        // save interop grab bag
-        mpDPObject->PutInteropGrabBag(std::move(maInteropGrabBag));
+        // set the pivot table style info
+        mpDPObject->setStyleInfo(std::move(maStyleInfo));
 
         // insert the DataPilot table into the sheet
         ScDocument& rDoc = getDocImport().getDoc();
diff --git a/sc/source/filter/oox/pivottablefragment.cxx 
b/sc/source/filter/oox/pivottablefragment.cxx
index 5158f3f87347..ae44daa0f7f5 100644
--- a/sc/source/filter/oox/pivottablefragment.cxx
+++ b/sc/source/filter/oox/pivottablefragment.cxx
@@ -184,8 +184,20 @@ ContextHandlerRef PivotTableFragment::onCreateContext( 
sal_Int32 nElement, const
                 case XLS_TOKEN(formats):
                     return this;
                 case XLS_TOKEN(pivotTableStyleInfo):
-                    
mrPivotTable.putToInteropGrabBag(u"pivotTableStyleInfo"_ustr, rAttribs);
+                {
+                    OUString aName = rAttribs.getXString(XML_name, OUString());
+                    if (!aName.isEmpty())
+                    {
+                        auto& rStyleInfo = mrPivotTable.getStyleInfo();
+                        rStyleInfo.maName = aName;
+                        rStyleInfo.mbShowRowHeaders = 
rAttribs.getBool(XML_showRowHeaders, false);
+                        rStyleInfo.mbShowColHeaders = 
rAttribs.getBool(XML_showColHeaders, false);
+                        rStyleInfo.mbShowRowStripes = 
rAttribs.getBool(XML_showRowStripes, false);
+                        rStyleInfo.mbShowColStripes = 
rAttribs.getBool(XML_showColStripes, false);
+                        rStyleInfo.mbShowLastColumn = 
rAttribs.getBool(XML_showLastColumn, false);
+                    }
                     break;
+                }
             }
         break;
 

Reply via email to