1#ifndef OPENXLSX_XLDOCUMENT_HPP
2#define OPENXLSX_XLDOCUMENT_HPP
6# pragma warning(disable : 4251)
7# pragma warning(disable : 4275)
16#include <shared_mutex>
19#include <unordered_map>
23#include "OpenXLSX-Exports.hpp"
97 return getXmlData(path, doNotThrow);
101 return getXmlData(path, doNotThrow);
105 return &m_data.emplace_back(
this, path,
id, type);
109 return m_sharedFormulas;
138 void suppressWarnings();
144 void open(std::string_view fileName);
151 void open(std::string_view fileName,
const std::string& password);
158 void create(std::string_view fileName,
bool forceOverwrite = XLForceOverwrite);
164 [[deprecated]]
void create(
const std::string& fileName);
175 void addStreamedFile(std::string_view pathInZip, std::string_view tempFilePath);
182 void saveAs(std::string_view fileName,
bool forceOverwrite = XLForceOverwrite);
190 void saveAs(std::string_view fileName,
const std::string& password,
bool forceOverwrite = XLForceOverwrite);
196 [[deprecated]]
void saveAs(
const std::string& fileName);
202 [[nodiscard]] std::string name()
const;
208 [[nodiscard]]
const std::string& path()
const;
223 bool hasMacro()
const;
237 [[nodiscard]] uint32_t nextTableId()
const;
248 [[nodiscard]] std::string property(
XLProperty prop)
const;
255 void setProperty(
XLProperty prop, std::string_view value);
265 [[nodiscard]]
explicit operator bool()
const;
270 [[nodiscard]]
bool isOpen()
const;
276 void setCompressionLevel(
int level);
281 int compressionLevel()
const;
286 void setDefaultAuthor(
const std::string& author);
291 std::string defaultAuthor()
const;
301 [[nodiscard]]
bool hasSheetRelationships(uint16_t sheetXmlNo,
bool isChartsheet =
false)
const;
302 [[nodiscard]]
bool hasSheetVmlDrawing(uint16_t sheetXmlNo)
const;
303 [[nodiscard]]
bool hasSheetComments(uint16_t sheetXmlNo)
const;
304 [[nodiscard]]
bool hasSheetThreadedComments(uint16_t sheetXmlNo)
const;
305 [[nodiscard]]
bool hasSheetDrawing(uint16_t sheetXmlNo)
const;
306 [[nodiscard]]
bool hasSheetTables(uint16_t sheetXmlNo)
const;
308 XLRelationships sheetRelationships(uint16_t sheetXmlNo,
bool isChartsheet =
false);
309 XLDrawing sheetDrawing(uint16_t sheetXmlNo);
311 XLDrawing drawing(std::string_view path);
313 XLComments sheetComments(uint16_t sheetXmlNo);
315 XLTables sheetTables(uint16_t sheetXmlNo);
323 std::string createTableSlicerCache(uint32_t tableId, uint32_t tableColumnId, std::string_view name, std::string_view sourceName);
325 std::string createPivotSlicerCache(uint32_t pivotCacheId,
327 std::string_view pivotTableName,
328 std::string_view name,
329 std::string_view sourceName);
331 std::string createSlicer(std::string_view name, std::string_view cacheName, std::string_view caption);
339 std::string addImage(std::string_view name, std::string_view data);
344 [[nodiscard]] std::string getImage(std::string_view path) const;
380 bool validateSheetName(std::string_view sheetName,
bool throwOnInvalid =
false);
382 bool execCommand(
const XLCommand& command);
402 bool hasPersons()
const;
413 void cleanupSharedStrings();
425 [[nodiscard]] std::string extractXmlFromArchive(std::string_view path);
432 [[nodiscard]]
XLXmlData* getXmlData(std::string_view path,
bool doNotThrow =
false);
433 [[nodiscard]]
const XLXmlData* getXmlData(std::string_view path,
bool doNotThrow =
false)
const;
434 [[nodiscard]]
bool hasXmlData(std::string_view path)
const;
440 std::shared_mutex&
mutex()
const {
return *m_docMutex; }
443 bool m_suppressWarnings{
true};
444 std::string m_filePath{};
445 std::string m_defaultAuthor{
"System Admin"};
447 XLXmlSavingDeclaration m_xmlSavingDeclaration;
449 mutable std::list<XLXmlData> m_data{};
450 mutable XLSharedStringsState m_sharedStringsState{};
451 mutable std::unique_ptr<std::shared_mutex> m_docMutex{std::make_unique<std::shared_mutex>()};
452 mutable XLSharedStrings m_sharedStrings{};
453 mutable std::map<void*, std::unordered_map<uint32_t, SharedFormula>> m_sharedFormulas{};
454 std::map<std::string, std::string> m_unhandledEntries{};
456 bool m_formulaNeedsRecalculation{
false};
457 bool m_isEncryptedSession{
false};
458 std::string m_encryptionPassword{
""};
459 std::string m_tempDecryptedPath{
""};
463 XLContentTypes m_contentTypes{};
464 XLAppProperties m_appProperties{};
465 XLProperties m_coreProperties{};
466 XLCustomProperties m_customProperties{};
468 XLWorkbook m_workbook{};
469 XLPersons m_persons{};
470 IZipArchive m_archive{};
473 [[nodiscard]] OPENXLSX_EXPORT std::string
BinaryAsHexString(gsl::span<const std::byte> data);
474 [[nodiscard]] OPENXLSX_EXPORT uint16_t
ExcelPasswordHash(std::string_view password);
return XLRelationships(xmlData, relsFilename)
This class functions as a wrapper around any class that provides the necessary functionality for a zi...
Definition IZipArchive.hpp:26
The XLAppProperties class represents the extended/application properties (docProps/app....
Definition XLProperties.hpp:146
Definition XLChart.hpp:223
Definition XLCommandQuery.hpp:43
The purpose of this class is to load, store add and save item in the [Content_Types]....
Definition XLContentTypes.hpp:102
The XLCustomProperties class represents custom user-defined properties (docProps/custom....
Definition XLProperties.hpp:293
This class encapsulates the concept of an excel file. It is different from the XLWorkbook,...
Definition XLDocument.hpp:82
std::map< void *, std::unordered_map< uint32_t, SharedFormula > > & sharedFormulas(XLInternalAccess) const
Definition XLDocument.hpp:108
const XLSharedStrings & sharedStrings() const
Access the workbook's central Shared String Table (SST). The SST reduces file size by deduplicating t...
Definition XLDocument.hpp:397
const XLXmlData * getXmlData(XLInternalAccess, std::string_view path, bool doNotThrow=false) const
Definition XLDocument.hpp:100
const XLProperties & coreProperties() const
Definition XLDocument.hpp:375
XLXmlData * getXmlData(XLInternalAccess, std::string_view path, bool doNotThrow=false)
Definition XLDocument.hpp:96
const XLAppProperties & appProperties() const
Definition XLDocument.hpp:368
std::shared_mutex & mutex() const
Get the document-level mutex for thread-safe operations.
Definition XLDocument.hpp:440
XLDocument & operator=(XLDocument &&other) noexcept=default
const IZipArchive & archive() const
Definition XLDocument.hpp:361
XLProperties & coreProperties()
Access core document metadata properties. [[nodiscard]] is used to prevent state-querying errors.
Definition XLDocument.hpp:374
XLAppProperties & appProperties()
Access application-specific properties (metadata). [[nodiscard]] is used to prevent state-querying er...
Definition XLDocument.hpp:367
XLXmlData * addXmlData(XLInternalAccess, const std::string &path, const std::string &id, XLContentType type)
Definition XLDocument.hpp:104
XLDocument(const XLDocument &other)=delete
XLDocument & operator=(const XLDocument &other)=delete
void setFormulaNeedsRecalculation(bool status=true)
Marks the document to require formula recalculation on load.
Definition XLDocument.hpp:418
IZipArchive & archive()
Access the low-level ZIP archive for advanced package manipulation. [[nodiscard]] is used to prevent ...
Definition XLDocument.hpp:360
XLDocument(XLDocument &&other) noexcept=default
The XLDrawing class is the base class for worksheet drawings (images, charts, etc....
Definition XLDrawing.hpp:383
Passkey Idiom for internal access control. Only the specified friend classes can instantiate this pas...
Definition XLInternalAccess.hpp:24
A class encapsulating modern Excel persons metadata (persons.xml)
Definition XLThreadedComments.hpp:119
Definition XLPivotTable.hpp:173
Definition XLPivotTable.hpp:198
Definition XLPivotTable.hpp:126
The XLProperties class represents the core properties of the document (docProps/core....
Definition XLProperties.hpp:26
Definition XLCommandQuery.hpp:106
Definition XLRelationships.hpp:140
This class encapsulate the Excel concept of Shared Strings. In Excel, instead of havig individual str...
Definition XLSharedStrings.hpp:67
An encapsulation of the styles file (xl/styles.xml) in an Excel document package.
Definition XLStyles.hpp:2261
The XLTableCollection class manages multiple tables within a worksheet.
Definition XLTables.hpp:40
The XLVmlDrawing class is the base class for worksheet comments.
Definition XLDrawing.hpp:508
This class encapsulates the concept of a Workbook. It provides access to the individual sheets (works...
Definition XLWorkbook.hpp:87
The XLXmlData class encapsulates the properties and behaviour of the .xml files in an ....
Definition XLXmlData.hpp:29
The XLXmlSavingDeclaration class encapsulates the properties of an XML saving declaration,...
Definition XLXmlSavingDeclaration.hpp:19
Definition XLZipArchive.hpp:22
Definition IZipArchive.hpp:18
std::string getPathARelativeToPathB(std::string_view pathA, std::string_view pathB)
Definition XLUtilities.cpp:105
OPENXLSX_EXPORT uint16_t ExcelPasswordHash(std::string_view password)
Definition XLUtilities.cpp:39
XLContentType
Definition XLContentTypes.hpp:28
constexpr const bool XLForceOverwrite
Definition XLDocument.hpp:45
std::string eliminateDotAndDotDotFromPath(std::string_view path)
Definition XLUtilities.cpp:126
XLChartType
Definition XLChart.hpp:14
XLProperty
The XLDocumentProperties class is an enumeration of the possible properties (metadata) that can be se...
Definition XLDocument.hpp:52
constexpr const bool XLDoNotOverwrite
Definition XLDocument.hpp:46
constexpr const unsigned int pugi_parse_settings
Definition XLDocument.hpp:43
OPENXLSX_EXPORT std::string ExcelPasswordHashAsString(std::string_view password)
Definition XLUtilities.cpp:56
OPENXLSX_EXPORT std::string BinaryAsHexString(gsl::span< const std::byte > data)
Definition XLUtilities.cpp:24
Definition XLCellIterator.hpp:121