/* * Copyright (C) Ascensio System SIA, 2009-2026 * * This program is a free software product. You can redistribute it and/or * modify it under the terms of the GNU Affero General Public License (AGPL) * version 3 as published by the Free Software Foundation, together with the * additional terms provided in the LICENSE file. * * This program is distributed WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For * details, see the GNU AGPL at: https://www.gnu.org/licenses/agpl-3.0.html * * You can contact Ascensio System SIA by email at info@onlyoffice.com * or by postal mail at 20A-6 Ernesta Birznieka-Upisha Street, Riga, * LV-1050, Latvia, European Union. * * The interactive user interfaces in modified versions of the Program * are required to display Appropriate Legal Notices in accordance with * Section 5 of the GNU AGPL version 3. * * No trademark rights are granted under this License. * * All non-code elements of the Product, including illustrations, * icon sets, and technical writing content, are licensed under the * Creative Commons Attribution-ShareAlike 4.0 International License: * https://creativecommons.org/licenses/by-sa/4.0/legalcode * * This license applies only to such non-code elements and does not * modify or replace the licensing terms applicable to the Program's * source code, which remains licensed under the GNU Affero General * Public License v3. * * SPDX-License-Identifier: AGPL-3.0-only */ #include "Sheets.h" #include "../../XlsbFormat/Biff12_records/BundleSh.h" #include "../../../MsBinaryFile/XlsFile/Format/Logic/GlobalsSubstream.h" #include "../../../MsBinaryFile/XlsFile/Format/Logic/Biff_unions/BUNDLESHEET.h" #include "../../../MsBinaryFile/XlsFile/Format/Logic/Biff_records/BoundSheet8.h" #include "../../../MsBinaryFile/XlsFile/Format/Logic/Biff_records/RRTabId.h" #include "../../../MsBinaryFile/XlsFile/Format/Logic/Biff_structures/SheetId.h" #include "../../Common/SimpleTypes_Shared.h" #include "../../Common/SimpleTypes_Spreadsheet.h" namespace OOX { namespace Spreadsheet { CSheet::CSheet(OOX::Document *pMain) : WritingElement(pMain) { } CSheet::~CSheet() { } void CSheet::fromXML(XmlUtils::CXmlNode& node) { } std::wstring CSheet::toXML() const { return (L""); } void CSheet::toXML(NSStringUtils::CStringBuilder& writer) const { writer.WriteString((L"GetValue()); WritingStringNullableAttrString(L"state", m_oState, m_oState->ToString()); WritingStringNullableAttrString(L"r:id", m_oRid, m_oRid->ToString()); writer.WriteString((L"/>")); } void CSheet::fromXML(XmlUtils::CXmlLiteReader& oReader) { ReadAttributes( oReader ); if ( !oReader.IsEmptyNode() ) oReader.ReadTillEnd(); } XLS::BaseObjectPtr CSheet::toBin() { auto ptr(new XLSB::BundleSh); XLS::BaseObjectPtr objectPtr(ptr); if(m_oRid.IsInit()) ptr->strRelID.value = m_oRid->GetValue(); else ptr->strRelID.value.setSize(0xFFFFFFFF); if(m_oName.IsInit()) ptr->strName = m_oName.get(); else ptr->strName = L""; if(m_oSheetId.IsInit()) ptr->iTabID = m_oSheetId->GetValue(); else ptr->iTabID = 0; if(m_oState == SimpleTypes::Spreadsheet::EVisibleType::visibleVisible) ptr->hsState = XLSB::BundleSh::ST_SheetState::VISIBLE; else if(m_oState == SimpleTypes::Spreadsheet::EVisibleType::visibleHidden) ptr->hsState = XLSB::BundleSh::ST_SheetState::HIDDEN; else if(m_oState == SimpleTypes::Spreadsheet::EVisibleType::visibleVeryHidden) ptr->hsState = XLSB::BundleSh::ST_SheetState::VERYHIDDEN; else ptr->hsState = XLSB::BundleSh::ST_SheetState::VISIBLE; return objectPtr; } void CSheet::fromBin(XLS::BaseObjectPtr& obj) { ReadAttributes(obj); } EElementType CSheet::getType () const { return et_x_Sheet; } void CSheet::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) { WritingElement_ReadAttributes_Start_No_NS( oReader ) WritingElement_ReadAttributes_Read_if ( oReader, L"id", m_oRid ) WritingElement_ReadAttributes_Read_else_if( oReader, L"name", m_oName ) WritingElement_ReadAttributes_Read_else_if( oReader, L"sheetId", m_oSheetId ) WritingElement_ReadAttributes_Read_else_if( oReader, L"state", m_oState ) WritingElement_ReadAttributes_End_No_NS( oReader ) } void CSheet::ReadAttributes(XLS::BaseObjectPtr& obj) { auto ptr = static_cast(obj.get()); m_oRid = ptr->strRelID.value.value(); m_oName = ptr->strName.value(); m_oSheetId = ptr->iTabID; switch(ptr->hsState) { case XLSB::BundleSh::ST_SheetState::VISIBLE: m_oState = SimpleTypes::Spreadsheet::EVisibleType::visibleVisible; break; case XLSB::BundleSh::ST_SheetState::HIDDEN: m_oState = SimpleTypes::Spreadsheet::EVisibleType::visibleHidden; break; case XLSB::BundleSh::ST_SheetState::VERYHIDDEN: m_oState = SimpleTypes::Spreadsheet::EVisibleType::visibleVeryHidden; break; } } CSheets::CSheets(OOX::Document *pMain) : WritingElementWithChilds(pMain) { } CSheets::~CSheets() { } void CSheets::fromXML(XmlUtils::CXmlNode& node) { } std::wstring CSheets::toXML() const { return (L""); } void CSheets::toXML(NSStringUtils::CStringBuilder& writer) const { writer.WriteString((L"")); for ( size_t i = 0; i < m_arrItems.size(); ++i) { if ( m_arrItems[i] ) { m_arrItems[i]->toXML(writer); } } writer.WriteString((L"")); } void CSheets::fromXML(XmlUtils::CXmlLiteReader& oReader) { ReadAttributes( oReader ); if ( oReader.IsEmptyNode() ) return; int nCurDepth = oReader.GetDepth(); while( oReader.ReadNextSiblingNode( nCurDepth ) ) { std::wstring sName = XmlUtils::GetNameNoNS(oReader.GetName()); if ( (L"sheet") == sName ) { CSheet* pSheet = new CSheet(); *pSheet = oReader; m_arrItems.push_back( pSheet ); } } auto sheetIndex = 0; for(auto i:m_arrItems) { if(i->m_oName.IsInit()) AddSheetRef(i->m_oName.get(), sheetIndex); sheetIndex++; } } void CSheets::fromBin(std::vector& obj) { //ReadAttributes(obj); if (obj.empty()) return; for(auto &sheet : obj) { m_arrItems.push_back(new CSheet(sheet)); } } std::vector CSheets::toBin() { std::vector objectVector; for(auto i: m_arrItems) objectVector.push_back(i->toBin()); return objectVector; } void CSheets::toXLS(XLS::BaseObjectPtr stream, const std::vector<_UINT16> &SheetTypes) { auto streamPtr = static_cast(stream.get()); auto tabIdArray = new XLS::RRTabId; streamPtr->m_RRTabId = XLS::BaseObjectPtr(tabIdArray); auto SheetNum = 1; for(auto i: m_arrItems) { auto tempSheet = new XLS::BoundSheet8; auto tempSheetUnion = new XLS::BUNDLESHEET; tempSheetUnion->bundleSheetRecord = XLS::BaseObjectPtr(tempSheet); { XLS::SheetIdPtr element(new XLS::SheetId); if(i->m_oSheetId.IsInit()) element->id = i->m_oSheetId->GetValue(); else element->id = SheetNum; tabIdArray->sheet_ids.push_back(element); } if(i->m_oName.IsInit()) tempSheet->name_ = i->m_oName.get(); else tempSheet->name_ = std::wstring(L"sheet" + std::to_wstring(SheetNum)); streamPtr->m_arBUNDLESHEET.push_back(XLS::BaseObjectPtr(tempSheetUnion)); if(SheetTypes.size() > SheetNum-1) tempSheet->dt = SheetTypes.at(SheetNum-1); SheetNum++; } } EElementType CSheets::getType () const { return et_x_Sheets; } void CSheets::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) { } void CSheets::AddSheetRef(const std::wstring& link, const _INT32& sheetIndex) { XLS::GlobalWorkbookInfo::_xti val_1; val_1.iSup = sheetIndex; val_1.itabFirst = sheetIndex; val_1.itabLast = sheetIndex; val_1.link = link; XLS::GlobalWorkbookInfo::arXti_External_static.push_back(val_1); } } //Spreadsheet } // namespace OOX