diff --git a/MsBinaryFile/Projects/XlsFormatLib/Linux/XlsFormatLib.pro b/MsBinaryFile/Projects/XlsFormatLib/Linux/XlsFormatLib.pro index 2b4d461d9b..699fa3e16c 100644 --- a/MsBinaryFile/Projects/XlsFormatLib/Linux/XlsFormatLib.pro +++ b/MsBinaryFile/Projects/XlsFormatLib/Linux/XlsFormatLib.pro @@ -78,7 +78,8 @@ SOURCES += \ ../../../XlsFile/Converter/xlsx_external_context.cpp \ ../../../XlsFile/Converter/xlsx_activeX_context.cpp \ ../../../XlsFile/Converter/xlsx_comments.cpp \ - ../../../XlsFile/Converter/xlsx_comments_context.cpp + ../../../XlsFile/Converter/xlsx_comments_context.cpp \ + ../../../XlsFile/Converter/xls_writer.cpp HEADERS += \ ../../../XlsFile/Format/Binary/BinSmartPointers.h \ @@ -129,5 +130,6 @@ HEADERS += \ \ ../../../XlsFile/Converter/ShapeType.h \ ../../../XlsFile/Converter/xlsx_chart_context.h \ - ../../../XlsFile/Format/Auxiliary/HelpFunc.h + ../../../XlsFile/Format/Auxiliary/HelpFunc.h \ + ../../../XlsFile/Converter/xls_writer.h diff --git a/MsBinaryFile/XlsFile/Converter/xls_writer.cpp b/MsBinaryFile/XlsFile/Converter/xls_writer.cpp new file mode 100644 index 0000000000..30657e10c7 --- /dev/null +++ b/MsBinaryFile/XlsFile/Converter/xls_writer.cpp @@ -0,0 +1,55 @@ +#/* + * (c) Copyright Ascensio System SIA 2010-2025 + * + * 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. In accordance with + * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect + * that Ascensio System SIA expressly excludes the warranty of non-infringement + * of any third-party rights. + * + * 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: http://www.gnu.org/licenses/agpl-3.0.html + * + * You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish + * street, Riga, Latvia, EU, LV-1050. + * + * The interactive user interfaces in modified source and object code versions + * of the Program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU AGPL version 3. + * + * Pursuant to Section 7(b) of the License you must retain the original Product + * logo when distributing the program. Pursuant to Section 7(e) we decline to + * grant you any rights under trademark law for use of our trademarks. + * + * All the Product's GUI elements, including illustrations and icon sets, as + * well as technical writing content are licensed under the terms of the + * Creative Commons Attribution-ShareAlike 4.0 International. See the License + * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + * + */ + +#include "xls_writer.h" +#include "../Format/Binary/CompoundFile.h" +#include "../Format/Binary/CFStreamCacheWriter.h" +#include "../Format/Logic/WorkbookStreamObject.h" + + bool XlsWriter::Open(const std::wstring &fileName) + { + xls_file = boost::shared_ptr(new XLS::CompoundFile(fileName, XLS::CompoundFile::cf_WriteMode)); + if(xls_file->isError()) + return false; + return true; + } + + bool XlsWriter::WriteStreamObject(std::wstring &streamName, XLS::BaseObjectPtr streamObject) + { + auto xls_global_info = boost::shared_ptr(new XLS::GlobalWorkbookInfo(XLS::WorkbookStreamObject::DefaultCodePage, nullptr)); + XLS::StreamCacheWriterPtr cacheWriter(new XLS::CFStreamCacheWriter(xls_file->createNamedStream(streamName), xls_global_info)); + + XLS::BinWriterProcessor stream_proc(cacheWriter, nullptr); + stream_proc.mandatory(*streamObject); + xls_file->storage_->close(); + return true; + } diff --git a/MsBinaryFile/XlsFile/Converter/xls_writer.h b/MsBinaryFile/XlsFile/Converter/xls_writer.h new file mode 100644 index 0000000000..e0101a43ff --- /dev/null +++ b/MsBinaryFile/XlsFile/Converter/xls_writer.h @@ -0,0 +1,51 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2025 + * + * 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. In accordance with + * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect + * that Ascensio System SIA expressly excludes the warranty of non-infringement + * of any third-party rights. + * + * 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: http://www.gnu.org/licenses/agpl-3.0.html + * + * You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish + * street, Riga, Latvia, EU, LV-1050. + * + * The interactive user interfaces in modified source and object code versions + * of the Program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU AGPL version 3. + * + * Pursuant to Section 7(b) of the License you must retain the original Product + * logo when distributing the program. Pursuant to Section 7(e) we decline to + * grant you any rights under trademark law for use of our trademarks. + * + * All the Product's GUI elements, including illustrations and icon sets, as + * well as technical writing content are licensed under the terms of the + * Creative Commons Attribution-ShareAlike 4.0 International. See the License + * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + * + */ + +#pragma once +#include +#include +#include "../Format/Logic/CompositeObject.h" +namespace XLS +{ + class CompoundFile; + typedef boost::shared_ptr CompoundFilePtr; +} +class XlsWriter +{ +public: + bool Open(const std::wstring &fileName); + bool WriteStreamObject(std::wstring &streamName, XLS::BaseObjectPtr streamObject); +private: + std::wstring fileName_ = L""; + + XLS::CompoundFilePtr xls_file; +}; diff --git a/MsBinaryFile/XlsFile/Format/Binary/CFRecord.cpp b/MsBinaryFile/XlsFile/Format/Binary/CFRecord.cpp index 2015a5dd94..a2b710532c 100644 --- a/MsBinaryFile/XlsFile/Format/Binary/CFRecord.cpp +++ b/MsBinaryFile/XlsFile/Format/Binary/CFRecord.cpp @@ -478,6 +478,13 @@ void CFRecord::save(NSBinPptxRW::CXlsbBinaryWriter& writer) writer.WriteBYTEArray((BYTE*)&intData[0], rdPtr); } +void CFRecord::save(CFStreamPtr& writer) +{ + writer->write(&type_id_, 2); + writer->write(&rdPtr, 2); + writer->write(&intData[0], rdPtr); +} + CFRecord& CFRecord::operator >> (bool& val) { throw;// EXCEPT::LE::WrongAPIUsage("This function may only be called by mistake.", __FUNCTION__); diff --git a/MsBinaryFile/XlsFile/Format/Binary/CFRecord.h b/MsBinaryFile/XlsFile/Format/Binary/CFRecord.h index 8ad0ee56f3..f899a8a379 100644 --- a/MsBinaryFile/XlsFile/Format/Binary/CFRecord.h +++ b/MsBinaryFile/XlsFile/Format/Binary/CFRecord.h @@ -33,6 +33,7 @@ #include "CFRecordType.h" #include "CFStream.h" +#include "CFStreamCacheWriter.h" #include "BinSmartPointers.h" #include "../Logic/GlobalWorkbookInfo.h" @@ -90,6 +91,7 @@ public: //save record to stream void save(NSBinPptxRW::CXlsbBinaryWriter& writer); + void save(CFStreamPtr& writer); template const T* getCurData() const diff --git a/MsBinaryFile/XlsFile/Format/Binary/CFStreamCacheWriter.cpp b/MsBinaryFile/XlsFile/Format/Binary/CFStreamCacheWriter.cpp index 8e6fe5e4c2..93c8c073bc 100644 --- a/MsBinaryFile/XlsFile/Format/Binary/CFStreamCacheWriter.cpp +++ b/MsBinaryFile/XlsFile/Format/Binary/CFStreamCacheWriter.cpp @@ -77,7 +77,7 @@ CFStreamCacheWriter::~CFStreamCacheWriter() // Returns whether the record was saved to file or stored for later saving bool CFStreamCacheWriter::storeNextRecord(CFRecordPtr record) { - //record->save(stream_); + record->save(stream_); return true; } diff --git a/MsBinaryFile/XlsFile/Format/Binary/CompoundFile.h b/MsBinaryFile/XlsFile/Format/Binary/CompoundFile.h index 85076de889..af424a8cfb 100644 --- a/MsBinaryFile/XlsFile/Format/Binary/CompoundFile.h +++ b/MsBinaryFile/XlsFile/Format/Binary/CompoundFile.h @@ -64,14 +64,15 @@ public: CFStreamPtr getNamedStream (const std::wstring& name); POLE::Storage *storage_; + + CFStreamPtr createNamedStream (const std::wstring& name); + void closeNamedStream (const std::wstring& name); private: void copy_stream(std::wstring streamNameOpen, std::wstring streamNameCreate, POLE::Storage * storageOut, bool bWithRoot = true); POLE::Stream* openStream (const std::wstring & stream_name); // Opens a stream in the storage (shall be called not more than once per stream) POLE::Stream* createStream (const std::wstring & stream_name); // Creates a new stream in the storage - CFStreamPtr createNamedStream (const std::wstring& name); - void closeNamedStream (const std::wstring& name); std::map streams; ReadWriteMode rwMode; diff --git a/OOXML/test/test.pro b/OOXML/test/test.pro index d9ab1094cd..1f7e92961a 100644 --- a/OOXML/test/test.pro +++ b/OOXML/test/test.pro @@ -23,3 +23,9 @@ DESTDIR = $$CORE_BUILDS_BINARY_PATH SOURCES -= $$CORE_GTEST_PATH/src/gtest_main.cc +SOURCES -= ../../../Common/OfficeFileFormatChecker2.cpp +SOURCES -= ../../src/cextracttools.cpp +SOURCES -= ../../src/ASCConverters.cpp +SOURCES += ../../Common/OfficeFileFormatChecker2.cpp +SOURCES += $$X2T_DIR/src/cextracttools.cpp +SOURCES += $$X2T_DIR/src/ASCConverters.cpp