From 9f24bda011ad1fd69568ba4a9671d848ec31ab57 Mon Sep 17 00:00:00 2001 From: Viktor Andreev Date: Thu, 2 Oct 2025 18:13:24 +0600 Subject: [PATCH] add pivotCache files conversion --- .../Format/Logic/Biff_unions/PIVOTCACHE.cpp | 7 +++++-- OOXML/XlsxFormat/Pivot/PivotCacheDefinition.h | 2 ++ OOXML/XlsxFormat/Pivot/Pivots.cpp | 14 ++++++++++++++ OOXML/XlsxFormat/Xlsx.cpp | 13 +++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/PIVOTCACHE.cpp b/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/PIVOTCACHE.cpp index 3255cb06d3..31d673d5e7 100644 --- a/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/PIVOTCACHE.cpp +++ b/MsBinaryFile/XlsFile/Format/Logic/Biff_unions/PIVOTCACHE.cpp @@ -158,10 +158,13 @@ const bool PIVOTCACHE::loadContent(BinProcessor& proc) } const bool PIVOTCACHE::saveContent(BinProcessor& proc) { - if(m_SXDB == nullptr || m_SXDBEx == nullptr) + if(m_SXDB == nullptr) return false; proc.mandatory(*m_SXDB); - proc.mandatory(*m_SXDBEx); + if(m_SXDBEx != nullptr) + proc.mandatory(*m_SXDBEx); + else + proc.mandatory(); for(auto i : m_arSXFORMULA) if(i != nullptr) proc.mandatory(*i); diff --git a/OOXML/XlsxFormat/Pivot/PivotCacheDefinition.h b/OOXML/XlsxFormat/Pivot/PivotCacheDefinition.h index 1049985eb3..9da44709f5 100644 --- a/OOXML/XlsxFormat/Pivot/PivotCacheDefinition.h +++ b/OOXML/XlsxFormat/Pivot/PivotCacheDefinition.h @@ -567,11 +567,13 @@ namespace OOX virtual void fromXML(XmlUtils::CXmlLiteReader& oReader); void fromBin(XLS::BaseObjectPtr& obj); XLS::BaseObjectPtr toBin(); + XLS::BaseObjectPtr toXLS(); virtual EElementType getType () const { return et_x_PivotCacheDefinition; } XLS::BaseObjectPtr writeAttributes(); + XLS::BaseObjectPtr writeAttributesXLS(); void ReadAttributes(XLS::BaseObjectPtr& obj); void ReadAttributes(XmlUtils::CXmlLiteReader& oReader); //---------- diff --git a/OOXML/XlsxFormat/Pivot/Pivots.cpp b/OOXML/XlsxFormat/Pivot/Pivots.cpp index bb832303da..38a6e1bc2a 100644 --- a/OOXML/XlsxFormat/Pivot/Pivots.cpp +++ b/OOXML/XlsxFormat/Pivot/Pivots.cpp @@ -153,11 +153,13 @@ #include "../../../MsBinaryFile/XlsFile/Format/Logic/Biff_unions/PIVOTVD.h" #include "../../../MsBinaryFile/XlsFile/Format/Logic/Biff_unions/PIVOTIVD.h" #include "../../../MsBinaryFile/XlsFile/Format/Logic/Biff_unions/PIVOTLI.h" +#include "../../../MsBinaryFile/XlsFile/Format/Logic/Biff_unions/PIVOTCACHE.h" #include "../../../MsBinaryFile/XlsFile/Format/Logic/Biff_records/SxView.h" #include "../../../MsBinaryFile/XlsFile/Format/Logic/Biff_records/Sxvd.h" #include "../../../MsBinaryFile/XlsFile/Format/Logic/Biff_records/SxIvd.h" #include "../../../MsBinaryFile/XlsFile/Format/Logic/Biff_records/SXVI.h" #include "../../../MsBinaryFile/XlsFile/Format/Logic/Biff_records/SXDI.h" +#include "../../../MsBinaryFile/XlsFile/Format/Logic/Biff_records/SXDB.h" #include "../../../MsBinaryFile/XlsFile/Format/Logic/Biff_records/SXLI.h" namespace OOX @@ -4361,6 +4363,18 @@ xmlns:xr16=\"http://schemas.microsoft.com/office/spreadsheetml/2017/revision16\" return objectPtr; } + XLS::BaseObjectPtr CPivotCacheDefinition::toXLS() + { + auto ptr = new XLS::PIVOTCACHE; + ptr->m_SXDB = writeAttributesXLS(); + return XLS::BaseObjectPtr(ptr); + } + XLS::BaseObjectPtr CPivotCacheDefinition::writeAttributesXLS() + { + auto ptr = new XLS::SXDB; + + return XLS::BaseObjectPtr(ptr); + } void CPivotCacheDefinition::fromBin(XLS::BaseObjectPtr& obj) { auto ptr = static_cast(obj.get()); diff --git a/OOXML/XlsxFormat/Xlsx.cpp b/OOXML/XlsxFormat/Xlsx.cpp index 0ef89a4727..85edc74c2e 100644 --- a/OOXML/XlsxFormat/Xlsx.cpp +++ b/OOXML/XlsxFormat/Xlsx.cpp @@ -213,6 +213,19 @@ bool OOX::Spreadsheet::CXlsx::WriteXLS(const CPath& oFilePath) writer.Open(oFilePath.GetPath()); writer.WriteWorkbook(workbookPtr); + + if(m_pWorkbook->m_oPivotCaches.IsInit() && !m_pWorkbook->m_oPivotCaches->m_arrItems.empty()) + { + for(auto cacheHeader : m_pWorkbook->m_oPivotCaches->m_arrItems) + { + if(!cacheHeader->m_oCacheId.IsInit() || !cacheHeader->m_oRid.IsInit() || !m_pWorkbook->IsExist(cacheHeader->m_oRid->GetValue())) + continue; + auto cacheFilePtr = m_pWorkbook->Find(cacheHeader->m_oRid->GetValue()); + auto CachePtr = static_cast(cacheFilePtr.GetPointer()); + if(CachePtr->m_oPivotCashDefinition.IsInit()) + writer.WritePivotCache(CachePtr->m_oPivotCashDefinition->toXLS(), cacheHeader->m_oCacheId->GetValue()); + } + } return true; } bool OOX::Spreadsheet::CXlsx::WriteWorkbook(const CPath& oDirPath)