2025-01-11 preparation of XLTables and XLComments and hyperlink support - integration in XLRelationships

This commit is contained in:
Lars Uffmann
2025-01-11 13:36:34 +01:00
parent 4ed9c97ad6
commit 0d101fba89
8 changed files with 296 additions and 44 deletions

View File

@@ -81,8 +81,7 @@ YM M9 MM MM MM MM MM d' `MM. MM MM d' `MM.
namespace OpenXLSX
{
/**
* @brief The XLComments class is the base class for the
* @tparam T Type that will inherit functionality. Restricted to types XLWorksheet and XLChartsheet.
* @brief The XLComments class is the base class for worksheet comments
*/
class OPENXLSX_EXPORT XLComments : public XLXmlFile
{
@@ -141,12 +140,13 @@ namespace OpenXLSX
/**
* @brief set the comment for the referenced cell
* @param cellRef the cell address to set
* @param comment set this text as comment for the cell
* @return true upon success, false on failure
*/
bool set(std::string cellRef);
bool set(std::string cellRef, std::string comment);
/**
* @brief Print the XML contents of the XLSheet using the underlying XMLNode print function
* @brief Print the XML contents of this XLComments instance using the underlying XMLNode print function
*/
void print(std::basic_ostream<char>& ostr) const;
};

View File

@@ -125,6 +125,7 @@ namespace OpenXLSX
VBAProject,
ControlProperties,
Comments,
Table,
Unknown
};
} // namespace OpenXLSX

View File

@@ -137,6 +137,47 @@ namespace OpenXLSX
Invalid = 255
};
const std::vector< std::string_view > XLWorksheetNodeOrder = { // worksheet XML root node required child sequence
"sheetPr",
"dimension",
"sheetViews",
"sheetFormatPr",
"cols",
"sheetData",
"sheetCalcPr",
"sheetProtection",
"protectedRanges",
"scenarios",
"autoFilter",
"sortState",
"dataConsolidate",
"customSheetViews",
"mergeCells",
"phoneticPr",
"conditionalFormatting",
"dataValidations",
"hyperlinks",
"printOptions",
"pageMargins",
"pageSetup",
"headerFooter",
"rowBreaks",
"colBreaks",
"customProperties",
"cellWatches",
"ignoredErrors",
"smartTags",
"drawing",
"legacyDrawing",
"legacyDrawingHF",
"picture",
"oleObjects",
"controls",
"webPublishItems",
"tableParts",
"extLst"
}; // END: const std::vector< std::string_view > XLWorksheetNodeOrder
// ================================================================================
// Converter functions between OpenXLSX class specific enum class types and OOXML values
// ================================================================================
@@ -813,22 +854,7 @@ namespace OpenXLSX
private: // ---------- Private Member Variables ---------- //
std::unique_ptr<XMLNode> m_sheetNode; /**< An XMLNode object with the sheet item */
// TODO: pass in m_nodeOrder from XLWorksheet
inline static const std::vector< std::string_view > m_nodeOrder = { // worksheet XML root node required child sequence
"sheetPr",
"dimension",
"sheetViews",
"sheetFormatPr",
"cols",
"sheetData",
"sheetProtection",
"mergeCells",
"conditionalFormatting",
"printOptions",
"pageMargins",
"pageSetup",
"headerFooter"
};
const std::vector< std::string_view >& m_nodeOrder = XLWorksheetNodeOrder; // worksheet XML root node required child sequence
};
/**
@@ -1214,22 +1240,7 @@ namespace OpenXLSX
private: // ---------- Private Member Variables ---------- //
XLMergeCells m_merges; /**< class handling the <mergeCells> */
inline static const std::vector< std::string_view > m_nodeOrder = { // worksheet XML root node required child sequence
"sheetPr",
"dimension",
"sheetViews",
"sheetFormatPr",
"cols",
"sheetData",
"sheetProtection",
"mergeCells",
"conditionalFormatting",
"printOptions",
"pageMargins",
"pageSetup",
"headerFooter"
};
const std::vector< std::string_view >& m_nodeOrder = XLWorksheetNodeOrder; // worksheet XML root node required child sequence
};
/**

View File

@@ -0,0 +1,136 @@
/*
____ ____ ___ ____ ____ ____ ___
6MMMMb `MM( )M' `MM' 6MMMMb\`MM( )M'
8P Y8 `MM. d' MM 6M' ` `MM. d'
6M Mb __ ____ ____ ___ __ `MM. d' MM MM `MM. d'
MM MM `M6MMMMb 6MMMMb `MM 6MMb `MM. d' MM YM. `MM. d'
MM MM MM' `Mb 6M' `Mb MMM9 `Mb `MMd MM YMMMMb `MMd
MM MM MM MM MM MM MM' MM dMM. MM `Mb dMM.
MM MM MM MM MMMMMMMM MM MM d'`MM. MM MM d'`MM.
YM M9 MM MM MM MM MM d' `MM. MM MM d' `MM.
8b d8 MM. ,M9 YM d9 MM MM d' `MM. MM / L ,M9 d' `MM.
YMMMM9 MMYMMM9 YMMMM9 _MM_ _MM_M(_ _)MM_ _MMMMMMM MYMMMM9 _M(_ _)MM_
MM
MM
_MM_
Copyright (c) 2018, Kenneth Troldal Balslev
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of the author nor the
names of any contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef OPENXLSX_XLCOMMENTS_HPP
#define OPENXLSX_XLCOMMENTS_HPP
// ===== External Includes ===== //
#include <cstdint> // uint8_t, uint16_t, uint32_t
#include <ostream> // std::basic_ostream
// #include <type_traits>
// #include <variant>
// ===== OpenXLSX Includes ===== //
#include "OpenXLSX-Exports.hpp"
// #include "XLCell.hpp"
// #include "XLCellReference.hpp"
// #include "XLColor.hpp"
// #include "XLColumn.hpp"
// #include "XLCommandQuery.hpp"
#include "XLDocument.hpp"
#include "XLException.hpp"
// #include "XLRow.hpp"
#include "XLXmlFile.hpp"
namespace OpenXLSX
{
/**
* @brief The XLTables class is the base class for worksheet tables
*/
class OPENXLSX_EXPORT XLTables : public XLXmlFile
{
public:
/**
* @brief Constructor
*/
XLTables() : XLXmlFile(nullptr) {};
/**
* @brief The constructor.
* @param xmlData the source XML of the table file
*/
XLTables(XLXmlData* xmlData);
/**
* @brief The copy constructor.
* @param other The object to be copied.
* @note The default copy constructor is used, i.e. only shallow copying of pointer data members.
*/
XLTables(const XLTables& other) = default;
/**
* @brief
* @param other
*/
XLTables(XLTables&& other) noexcept = default;
/**
* @brief The destructor
* @note The default destructor is used, since cleanup of pointer data members is not required.
*/
~XLTables() = default;
/**
* @brief Assignment operator
* @return A reference to the new object.
* @note The default assignment operator is used, i.e. only shallow copying of pointer data members.
*/
XLTables& operator=(const XLTables&) = default;
/**
* @brief
* @param other
* @return
*/
XLTables& operator=(XLTables&& other) noexcept = default;
// /**
// * @brief getters
// */
// std::string get(std::string cellRef) const;
//
// /**
// * @brief setters
// */
// bool set(std::string cellRef);
/**
* @brief Print the XML contents of this XLTables instance using the underlying XMLNode print function
*/
void print(std::basic_ostream<char>& ostr) const;
};
} // namespace OpenXLSX
#endif // OPENXLSX_XLCOMMENTS_HPP

View File

@@ -61,11 +61,10 @@ namespace OpenXLSX
} // namespace OpenXLSX
// ========== XLSheet Member Functions
// ========== XLComments Member Functions
/**
* @details The constructor begins by constructing an instance of its superclass, XLXmlFile. The default
* sheet type is WorkSheet and the default sheet state is Visible.
* @details The constructor creates an instance of the superclass, XLXmlFile
*/
XLComments::XLComments(XLXmlData* xmlData) : XLXmlFile(xmlData)
{
@@ -85,9 +84,10 @@ std::string XLComments::get(std::string cellRef) const
/**
* @details create (if it doesn't exist) & set the comment for the referenced cell
*/
bool XLComments::set(std::string cellRef)
bool XLComments::set(std::string cellRef, std::string comment)
{
OpenXLSX::ignore(cellRef);
OpenXLSX::ignore(comment);
return false;
}

View File

@@ -155,8 +155,6 @@ namespace
return XLRelationshipType::VMLDrawing;
if (typeString.substr(comparePos) == (comparePos ? "" : relationshipDomainOpenXml2006) + "/relationships/ctrlProp")
return XLRelationshipType::ControlProperties;
if (typeString.substr(comparePos) == (comparePos ? "" : relationshipDomainOpenXml2006) + "/relationships/comments")
return XLRelationshipType::Comments;
if (typeString.substr(comparePos) == (comparePos ? "" : relationshipDomainOpenXml2006CoreProps) + "/relationships/metadata/core-properties")
return XLRelationshipType::CoreProperties;
if (typeString.substr(comparePos) == (comparePos ? "" : relationshipDomainMicrosoft2006) + "/relationships/vbaProject")
@@ -165,6 +163,10 @@ namespace
return XLRelationshipType::ChartStyle;
if (typeString.substr(comparePos) == (comparePos ? "" : relationshipDomainMicrosoft2011) + "/relationships/chartColorStyle")
return XLRelationshipType::ChartColorStyle;
if (typeString.substr(comparePos) == (comparePos ? "" : relationshipDomainOpenXml2006) + "/relationships/comments")
return XLRelationshipType::Comments;
if (typeString.substr(comparePos) == (comparePos ? "" : relationshipDomainOpenXml2006) + "/relationships/table")
return XLRelationshipType::Table;
// ===== relationship could not be identified
if (comparePos == 0 ) // If fallback solution has not yet been tried
@@ -202,11 +204,12 @@ namespace OpenXLSX_XLRelationships { // make GetStringFromType accessible thr
case XLRelationshipType::PrinterSettings: return relationshipDomainOpenXml2006 + "/relationships/printerSettings";
case XLRelationshipType::VMLDrawing: return relationshipDomainOpenXml2006 + "/relationships/vmlDrawing";
case XLRelationshipType::ControlProperties: return relationshipDomainOpenXml2006 + "/relationships/ctrlProp";
case XLRelationshipType::Comments: return relationshipDomainOpenXml2006 + "/relationships/comments";
case XLRelationshipType::CoreProperties: return relationshipDomainOpenXml2006CoreProps + "/relationships/metadata/core-properties";
case XLRelationshipType::VBAProject: return relationshipDomainMicrosoft2006 + "/relationships/vbaProject";
case XLRelationshipType::ChartStyle: return relationshipDomainMicrosoft2011 + "/relationships/chartStyle";
case XLRelationshipType::ChartColorStyle: return relationshipDomainMicrosoft2011 + "/relationships/chartColorStyle";
case XLRelationshipType::Comments: return relationshipDomainOpenXml2006 + "/relationships/comments";
case XLRelationshipType::Table: return relationshipDomainOpenXml2006 + "/relationships/table";
default:
throw XLInternalError("RelationshipType not recognized!");
}

View File

@@ -0,0 +1,100 @@
/*
____ ____ ___ ____ ____ ____ ___
6MMMMb `MM( )M' `MM' 6MMMMb\`MM( )M'
8P Y8 `MM. d' MM 6M' ` `MM. d'
6M Mb __ ____ ____ ___ __ `MM. d' MM MM `MM. d'
MM MM `M6MMMMb 6MMMMb `MM 6MMb `MM. d' MM YM. `MM. d'
MM MM MM' `Mb 6M' `Mb MMM9 `Mb `MMd MM YMMMMb `MMd
MM MM MM MM MM MM MM' MM dMM. MM `Mb dMM.
MM MM MM MM MMMMMMMM MM MM d'`MM. MM MM d'`MM.
YM M9 MM MM MM MM MM d' `MM. MM MM d' `MM.
8b d8 MM. ,M9 YM d9 MM MM d' `MM. MM / L ,M9 d' `MM.
YMMMM9 MMYMMM9 YMMMM9 _MM_ _MM_M(_ _)MM_ _MMMMMMM MYMMMM9 _M(_ _)MM_
MM
MM
_MM_
Copyright (c) 2018, Kenneth Troldal Balslev
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of the author nor the
names of any contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// ===== External Includes ===== //
// #include <algorithm>
#include <pugixml.hpp>
// ===== OpenXLSX Includes ===== //
// #include "XLCellRange.hpp"
// #include "XLDocument.hpp"
#include "XLTables.hpp"
#include "utilities/XLUtilities.hpp" // OpenXLSX::ignore
using namespace OpenXLSX;
namespace OpenXLSX
{
// placeholder for utility functions
} // namespace OpenXLSX
// ========== XLTables Member Functions
/**
* @details The constructor creates an instance of the superclass, XLXmlFile
*/
XLTables::XLTables(XLXmlData* xmlData) : XLXmlFile(xmlData)
{
if (xmlData->getXmlType() != XLContentType::Table)
throw XLInternalError("XLTables constructor: Invalid XML data.");
}
/**
* @details getters
*/
/*
std::string XLTables::get(std::string cellRef) const
{
OpenXLSX::ignore(cellRef);
return "";
}
*/
/**
* @details setters
*/
/*
bool XLTables::set(std::string cellRef)
{
OpenXLSX::ignore(cellRef);
return false;
}
*/
/**
* @details Print the underlying XML using pugixml::xml_node::print
*/
void XLTables::print(std::basic_ostream<char>& ostr) const { xmlDocument().document_element().print( ostr ); }

View File

@@ -97,9 +97,9 @@ namespace OpenXLSX
case XLContentType::CoreProperties: return "CoreProperties";
case XLContentType::ExtendedProperties: return "ExtendedProperties";
case XLContentType::CustomProperties: return "CustomProperties";
case XLContentType::VMLDrawing: return "VMLDrawing";
case XLContentType::Comments: return "Comments";
case XLContentType::Table: return "Table";
case XLContentType::VMLDrawing: return "VMLDrawing";
case XLContentType::Unknown: return "Unknown";
}
return "invalid";
@@ -138,6 +138,7 @@ namespace OpenXLSX
case XLRelationshipType::VBAProject: return "VBAProject";
case XLRelationshipType::ControlProperties: return "ControlProperties";
case XLRelationshipType::Comments: return "Comments";
case XLRelationshipType::Table: return "Table";
case XLRelationshipType::Unknown: return "Unknown";
}
return "invalid";