OpenXLSX 1.12.1
Modern C++ Excel Library (Fork of OpenXLSX by Kenneth Troldal Balslev)
Loading...
Searching...
No Matches
XLUtilities.hpp
Go to the documentation of this file.
1/*
2 * OpenXLSX-NX - Modern High-Performance C++ Excel Library
3 *
4 * Original work Copyright (c) 2018-2025, Kenneth Troldal Balslev and OpenXLSX contributors
5 * Modified work Copyright (c) 2026, Curry Tang and OpenXLSX-NX contributors
6 *
7 * Distributed under the BSD 3-Clause License.
8 * See LICENSE.md in the project root or https://opensource.org/licenses/BSD-3-Clause
9 */
10
11#ifndef OPENXLSX_XLUTILITIES_HPP
12#define OPENXLSX_XLUTILITIES_HPP
13
14#include <fstream>
15#include <string> // 2024-04-25 needed for xml_node_type_string
16#include <string_view> // std::string_view
17#include <vector> // std::vector< std::string_view >
18
19#include "XLCellReference.hpp"
20#include "XLCellValue.hpp" // OpenXLSX::XLValueType
21#include "XLConstants.hpp" // 2024-05-28 OpenXLSX::MAX_ROWS
22#include "XLContentTypes.hpp" // OpenXLSX::XLContentType
23#include "XLRelationships.hpp" // OpenXLSX::XLRelationshipType
24#include "XLStyles_Common.hpp" // XLStyleIndex, XLDefaultCellFormat
25#include "XLXmlHelpers.hpp" // ensure*/set* DOM helpers + appendAnd* aliases
26#include "XLXmlParser.hpp"
27
28namespace OpenXLSX
29{
35 inline bool isCleanXmlString(std::string_view sv) noexcept
36 {
37 for (char c : sv) {
38 unsigned char uc = static_cast<unsigned char>(c);
39 if (uc < 0x20 && uc != 0x09 && uc != 0x0A && uc != 0x0D) {
40 return false;
41 }
42 }
43 return true;
44 }
45
51 inline std::string sanitizeXmlString(std::string_view sv)
52 {
53 std::string result;
54 result.reserve(sv.size());
55 for (char c : sv) {
56 unsigned char uc = static_cast<unsigned char>(c);
57 if (uc >= 0x20 || uc == 0x09 || uc == 0x0A || uc == 0x0D) {
58 result += c;
59 }
60 }
61 return result;
62 }
63
69 inline void appendEscaped(std::string& out, std::string_view sv)
70 {
71 for (char c : sv) {
72 switch (c) {
73 case '<':
74 out += "&lt;";
75 break;
76 case '>':
77 out += "&gt;";
78 break;
79 case '&':
80 out += "&amp;";
81 break;
82 case '"':
83 out += "&quot;";
84 break;
85 case '\'':
86 out += "&apos;";
87 break;
88 default:
89 out += c;
90 break;
91 }
92 }
93 }
94
103 inline uint16_t extractColumnFromCellRef(const char* cellRef) noexcept
104 {
105 if (cellRef == nullptr or *cellRef == '\0') return 0;
106
107 uint32_t colNo = 0;
108 const char* p = cellRef;
109
110 // Parse uppercase letters only (A-Z)
111 while (*p >= 'A' and *p <= 'Z') {
112 colNo = colNo * 26 + static_cast<uint32_t>(*p - 'A' + 1);
113 ++p;
114 }
115
116 // Return 0 if no letters were found, or if column exceeds MAX_COLS
117 return (colNo > 0 and colNo <= MAX_COLS) ? static_cast<uint16_t>(colNo) : 0;
118 }
119
127 inline char* columnToLetters(uint16_t colNo, char* buffer) noexcept
128 {
129 char temp[4];
130 int idx = 0;
131
132 while (colNo > 0) {
133 --colNo; // Convert to 0-indexed for modulo
134 temp[idx++] = static_cast<char>('A' + (colNo % 26));
135 colNo /= 26;
136 }
137
138 // Reverse the result into buffer
139 int j = 0;
140 while (idx > 0) { buffer[j++] = temp[--idx]; }
141 buffer[j] = '\0';
142
143 return buffer;
144 }
145
154 #if defined(__GNUC__) || defined(__clang__)
155__attribute__((always_inline)) inline char* makeCellAddress(uint32_t row, uint16_t col, char* buffer) noexcept
156#elif defined(_MSC_VER)
157__forceinline char* makeCellAddress(uint32_t row, uint16_t col, char* buffer) noexcept
158#else
159inline char* makeCellAddress(uint32_t row, uint16_t col, char* buffer) noexcept
160#endif
161 {
162 // Generate column letters
163 char* p = buffer;
164 char colLetters[4];
165 columnToLetters(col, colLetters);
166
167 // Copy column letters
168 for (const char* c = colLetters; *c; ++c) { *p++ = *c; }
169
170 // Convert row number to string
171 char rowStr[12];
172 int idx = 0;
173 uint32_t r = row;
174 do {
175 rowStr[idx++] = static_cast<char>('0' + (r % 10));
176 r /= 10;
177 }
178 while (r > 0);
179
180 // Append row digits in reverse order
181 while (idx > 0) { *p++ = rowStr[--idx]; }
182 *p = '\0';
183
184 return buffer;
185 }
186
191 template<class T>
192 void ignore(const T&)
193 {}
194
200 inline std::string XLValueTypeString(XLValueType t)
201 {
202 using namespace std::literals::string_literals;
203 switch (t) {
205 return "Empty"s;
207 return "Boolean"s;
209 return "Integer"s;
211 return "Float"s;
213 return "Error"s;
215 return "String"s;
217 return "RichText"s;
218 }
219 throw XLInternalError(__func__ + "Invalid XLValueType."s);
220 }
221
227 inline std::string xml_node_type_string(XMLNodeType t)
228 {
229 using namespace std::literals::string_literals;
230 switch (t) {
231 case node_null:
232 return "node_null"s;
233 case node_document:
234 return "node_document"s;
235 case node_element:
236 return "node_element"s;
237 case node_pcdata:
238 return "node_pcdata"s;
239 case node_cdata:
240 return "node_cdata"s;
241 case node_comment:
242 return "node_comment"s;
243 case node_pi:
244 return "node_pi"s;
245 case node_declaration:
246 return "node_declaration"s;
247 case node_doctype:
248 return "node_doctype"s;
249 }
250 throw XLInternalError("Invalid XML node type.");
251 }
252
258 inline std::string XLContentTypeString(OpenXLSX::XLContentType const& t)
259 {
260 using namespace OpenXLSX;
261 switch (t) {
263 return "Workbook";
265 return "Relationships";
267 return "WorkbookMacroEnabled";
269 return "Worksheet";
271 return "Chartsheet";
273 return "ExternalLink";
275 return "Theme";
277 return "Styles";
279 return "SharedStrings";
281 return "Drawing";
283 return "Chart";
285 return "ChartStyle";
287 return "ChartColorStyle";
289 return "ControlProperties";
291 return "CalculationChain";
293 return "VBAProject";
295 return "Slicer";
297 return "SlicerCache";
299 return "PivotTable";
301 return "PivotCacheDefinition";
303 return "PivotCacheRecords";
304
306 return "CoreProperties";
308 return "ExtendedProperties";
310 return "CustomProperties";
312 return "VMLDrawing";
314 return "Comments";
316 return "Table";
318 return "ThreadedComments";
320 return "Persons";
322 return "Hyperlink";
324 return "Unknown";
325 }
326 return "invalid";
327 }
328
335 {
336 using namespace OpenXLSX;
337 switch (t) {
339 return "CoreProperties";
341 return "ExtendedProperties";
343 return "CustomProperties";
345 return "Workbook";
347 return "Worksheet";
349 return "Chartsheet";
351 return "Dialogsheet";
353 return "Macrosheet";
355 return "CalculationChain";
357 return "ExternalLink";
359 return "ExternalLinkPath";
361 return "Theme";
363 return "Styles";
365 return "Chart";
367 return "ChartStyle";
369 return "ChartColorStyle";
371 return "Image";
373 return "Drawing";
375 return "VMLDrawing";
377 return "SharedStrings";
379 return "PrinterSettings";
381 return "VBAProject";
383 return "Slicer";
385 return "SlicerCache";
387 return "PivotTable";
389 return "PivotCacheDefinition";
391 return "PivotCacheRecords";
392
394 return "ControlProperties";
396 return "Comments";
398 return "Table";
400 return "ThreadedComments";
402 return "Person";
404 return "Hyperlink";
406 return "Unknown";
407 }
408 return "invalid";
409 }
410
414 inline XMLNode getRowNode(XMLNode sheetDataNode, uint32_t rowNumber, uint32_t* hintRowNumber = nullptr, XMLNode* hintRowNode = nullptr)
415 {
416 if (rowNumber < 1 or rowNumber > OpenXLSX::MAX_ROWS) { // 2024-05-28: added range check
417 using namespace std::literals::string_literals;
418 throw XLCellAddressError("rowNumber "s + std::to_string(rowNumber) + " is outside valid range [1;"s +
419 std::to_string(OpenXLSX::MAX_ROWS) + "]"s);
420 }
421
422 // ===== O(1) Hint Fast-Path
423 if (hintRowNumber && hintRowNode && *hintRowNumber == rowNumber && !hintRowNode->empty()) {
424 return *hintRowNode;
425 }
426
427 XMLNode result;
428
429 // ===== Optimized Hint Crawl (if the target row is exactly the next row or very close after the hint)
430 if (hintRowNumber && hintRowNode && !hintRowNode->empty() && rowNumber > *hintRowNumber) {
431 result = *hintRowNode;
432 while (!result.empty() && result.attribute("r").as_ullong() < rowNumber) {
433 result = result.next_sibling_of_type(node_element);
434 }
435 if (result.empty() || result.attribute("r").as_ullong() > rowNumber) {
436 if (result.empty()) result = sheetDataNode.append_child("row");
437 else result = sheetDataNode.insert_child_before("row", result);
438 result.append_attribute("r") = rowNumber;
439 }
440 }
441 else if (hintRowNumber && hintRowNode && !hintRowNode->empty() && rowNumber < *hintRowNumber) {
442 result = *hintRowNode;
443 while (!result.empty() && result.attribute("r").as_ullong() > rowNumber) {
444 result = result.previous_sibling_of_type(node_element);
445 }
446 if (result.empty() || result.attribute("r").as_ullong() < rowNumber) {
447 if (result.empty()) result = sheetDataNode.prepend_child("row");
448 else result = sheetDataNode.insert_child_after("row", result);
449 result.append_attribute("r") = rowNumber;
450 }
451 }
452 else {
453 // ===== Original Binary/Edge crawling fallback
454 result = sheetDataNode.last_child_of_type(node_element);
455
456 if (result.empty() or (rowNumber > result.attribute("r").as_ullong())) {
457 result = sheetDataNode.append_child("row");
458 result.append_attribute("r") = rowNumber;
459 }
460 else if (result.attribute("r").as_ullong() - rowNumber < rowNumber) {
461 while (not result.empty() and (result.attribute("r").as_ullong() > rowNumber))
462 result = result.previous_sibling_of_type(node_element);
463 if (result.empty() or (result.attribute("r").as_ullong() != rowNumber)) {
464 if (result.empty())
465 result = sheetDataNode.prepend_child("row");
466 else
467 result = sheetDataNode.insert_child_after("row", result);
468 result.append_attribute("r") = rowNumber;
469 }
470 }
471 else {
472 result = sheetDataNode.first_child_of_type(node_element);
473 while (result.attribute("r").as_ullong() < rowNumber) result = result.next_sibling_of_type(node_element);
474 if (result.attribute("r").as_ullong() > rowNumber) {
475 result = sheetDataNode.insert_child_before("row", result);
476 result.append_attribute("r") = rowNumber;
477 }
478 }
479 }
480
481 // Update the hint for next time
482 if (hintRowNumber && hintRowNode) {
483 *hintRowNumber = rowNumber;
484 *hintRowNode = result;
485 }
486
487 return result;
488 }
489
502 inline std::vector<XLStyleIndex> getColumnStyles(XMLNode rowNode, uint16_t count)
503 {
504 std::vector<XLStyleIndex> styles(count, XLDefaultCellFormat);
505 XMLNode cols = rowNode.parent().parent().child("cols");
506 if (not cols.empty()) {
508 while (not col.empty()) {
509 int minCol = col.attribute("min").as_int(MAX_COLS + 1);
510 int maxCol = col.attribute("max").as_int(0);
511 uint32_t style = col.attribute("style").as_uint(XLDefaultCellFormat);
512
513 for (int i = minCol; i <= maxCol && i <= count; ++i) {
514 if (i > 0) styles[i - 1] = style;
515 }
517 }
518 }
519 return styles;
520 }
521
522 inline XLStyleIndex getColumnStyle(XMLNode rowNode, uint16_t colNo)
523 {
524 XMLNode cols = rowNode.parent().parent().child("cols");
525 if (not cols.empty()) {
527 while (not col.empty()) {
528 if (col.attribute("min").as_int(MAX_COLS + 1) <= colNo and col.attribute("max").as_int(0) >= colNo) // found
529 return col.attribute("style").as_uint(XLDefaultCellFormat);
531 }
532 }
533 return XLDefaultCellFormat; // if no col style was found
534 }
535
546 inline void setDefaultCellAttributes(XMLNode cellNode,
547 const std::string& cellRef,
548 XMLNode rowNode,
549 uint16_t colNo,
550 /**/ std::vector<XLStyleIndex> const& colStyles = {})
551 {
552 cellNode.append_attribute("r").set_value(cellRef.c_str());
553 XMLAttribute rowStyle = rowNode.attribute("s");
554 XLStyleIndex cellStyle; // scope declaration
555 if (rowStyle.empty()) { // if no explicit row style is set
556 if (colStyles.size() > 0) // if colStyles were provided
557 cellStyle =
558 (colNo > colStyles.size() ? XLDefaultCellFormat : colStyles[colNo - 1]); // determine cellStyle from colStyles
559 else // else: no colStyles provided
560 cellStyle = getColumnStyle(rowNode, colNo); // so perform a lookup
561 }
562 else // else: an explicit row style is set
563 cellStyle = rowStyle.as_uint(XLDefaultCellFormat); // use the row style
564
565 if (cellStyle != XLDefaultCellFormat) // if cellStyle was determined as not the default style (no point in setting that)
566 cellNode.append_attribute("s").set_value(cellStyle);
567 }
568
573 inline void setDefaultCellAttributes(XMLNode cellNode,
574 const char* cellRef,
575 XMLNode rowNode,
576 uint16_t colNo,
577 /**/ std::vector<XLStyleIndex> const& colStyles = {})
578 {
579 cellNode.append_attribute("r").set_value(cellRef);
580 XMLAttribute rowStyle = rowNode.attribute("s");
581 XLStyleIndex cellStyle;
582 if (rowStyle.empty()) {
583 if (colStyles.size() > 0)
584 cellStyle = (colNo > colStyles.size() ? XLDefaultCellFormat : colStyles[colNo - 1]);
585 else
586 cellStyle = getColumnStyle(rowNode, colNo);
587 }
588 else
589 cellStyle = rowStyle.as_uint(XLDefaultCellFormat);
590
591 if (cellStyle != XLDefaultCellFormat) cellNode.append_attribute("s").set_value(cellStyle);
592 }
593
605 uint16_t columnNumber,
606 uint32_t rowNumber = 0,
607 /**/ std::vector<XLStyleIndex> const& colStyles = {},
608 uint16_t* hintColNumber = nullptr,
609 XMLNode* hintCellNode = nullptr)
610 {
611 if (columnNumber < 1 or columnNumber > OpenXLSX::MAX_COLS) { // 2024-08-05: added range check
612 using namespace std::literals::string_literals;
613 throw XLException("XLWorksheet::column: columnNumber "s + std::to_string(columnNumber) + " is outside allowed range [1;"s +
614 std::to_string(MAX_COLS) + "]"s);
615 }
616 if (rowNode.empty()) return XMLNode{}; // 2024-05-28: return an empty node in case of empty rowNode
617
618 if (!rowNumber) rowNumber = rowNode.attribute("r").as_uint(); // if not provided, determine from rowNode
619
620 // ===== O(1) Hint Fast-Path
621 if (hintColNumber && hintCellNode && *hintColNumber == columnNumber && !hintCellNode->empty() && hintCellNode->parent() == rowNode) {
622 return *hintCellNode;
623 }
624
625 XMLNode cellNode;
626
627 // ===== Optimized Hint Crawl
628 if (hintColNumber && hintCellNode && !hintCellNode->empty() && hintCellNode->parent() == rowNode) {
629 cellNode = *hintCellNode;
630 if (columnNumber > *hintColNumber) {
631 uint16_t currentCol = *hintColNumber;
632 while (!cellNode.empty() && currentCol < columnNumber) {
633 cellNode = cellNode.next_sibling_of_type(node_element);
634 currentCol = cellNode.empty() ? 0 : extractColumnFromCellRef(cellNode.attribute("r").value());
635 }
636 if (currentCol > columnNumber || cellNode.empty()) {
637 if (cellNode.empty()) cellNode = rowNode.append_child("c");
638 else cellNode = rowNode.insert_child_before("c", cellNode);
639 char cellAddrBuf[16];
640 makeCellAddress(rowNumber, columnNumber, cellAddrBuf);
641 setDefaultCellAttributes(cellNode, cellAddrBuf, rowNode, columnNumber, colStyles);
642 }
643 goto update_hint;
644 }
645 else if (columnNumber < *hintColNumber) {
646 uint16_t currentCol = *hintColNumber;
647 while (!cellNode.empty() && currentCol > columnNumber) {
648 cellNode = cellNode.previous_sibling_of_type(node_element);
649 currentCol = cellNode.empty() ? 0 : extractColumnFromCellRef(cellNode.attribute("r").value());
650 }
651 if (currentCol < columnNumber || cellNode.empty()) {
652 if (cellNode.empty()) cellNode = rowNode.prepend_child("c");
653 else cellNode = rowNode.insert_child_after("c", cellNode);
654 char cellAddrBuf[16];
655 makeCellAddress(rowNumber, columnNumber, cellAddrBuf);
656 setDefaultCellAttributes(cellNode, cellAddrBuf, rowNode, columnNumber, colStyles);
657 }
658 goto update_hint;
659 }
660 }
661
662 // ===== Original Fallback Crawl
663 cellNode = rowNode.last_child_of_type(node_element);
664 {
665 uint16_t lastCellCol = cellNode.empty() ? 0 : extractColumnFromCellRef(cellNode.attribute("r").value());
666
667 if (cellNode.empty() or (lastCellCol < columnNumber)) {
668 cellNode = rowNode.append_child("c");
669 char cellAddrBuf[16];
670 makeCellAddress(rowNumber, columnNumber, cellAddrBuf);
671 setDefaultCellAttributes(cellNode, cellAddrBuf, rowNode, columnNumber, colStyles);
672 }
673 else if (lastCellCol - columnNumber < columnNumber) {
674 uint16_t currentCol = lastCellCol;
675 while (not cellNode.empty() and (currentCol > columnNumber)) {
676 cellNode = cellNode.previous_sibling_of_type(node_element);
677 currentCol = cellNode.empty() ? 0 : extractColumnFromCellRef(cellNode.attribute("r").value());
678 }
679 if (cellNode.empty() or (currentCol < columnNumber)) {
680 if (cellNode.empty()) cellNode = rowNode.prepend_child("c");
681 else cellNode = rowNode.insert_child_after("c", cellNode);
682 char cellAddrBuf[16];
683 makeCellAddress(rowNumber, columnNumber, cellAddrBuf);
684 setDefaultCellAttributes(cellNode, cellAddrBuf, rowNode, columnNumber, colStyles);
685 }
686 }
687 else {
688 cellNode = rowNode.first_child_of_type(node_element);
689 uint16_t currentCol = extractColumnFromCellRef(cellNode.attribute("r").value());
690 while (currentCol < columnNumber) {
691 cellNode = cellNode.next_sibling_of_type(node_element);
692 currentCol = extractColumnFromCellRef(cellNode.attribute("r").value());
693 }
694 if (currentCol > columnNumber) {
695 cellNode = rowNode.insert_child_before("c", cellNode);
696 char cellAddrBuf[16];
697 makeCellAddress(rowNumber, columnNumber, cellAddrBuf);
698 setDefaultCellAttributes(cellNode, cellAddrBuf, rowNode, columnNumber, colStyles);
699 }
700 }
701 }
702
703update_hint:
704 if (hintColNumber && hintCellNode) {
705 *hintColNumber = columnNumber;
706 *hintCellNode = cellNode;
707 }
708 return cellNode;
709 }
710
711 // XML ensure*/set*/appendAnd* helpers live in XLXmlHelpers.hpp (included above).
712
718 inline std::pair<uint32_t, uint32_t> getImageDimensions(const std::string& data)
719 {
720 if (data.size() < 8) return {0, 0};
721
722 // Check for PNG
723 if (reinterpret_cast<const uint8_t*>(data.data())[0] == 0x89 and data.substr(1, 3) == "PNG") {
724 if (data.size() < 24) return {0, 0};
725 // IHDR chunk starts at offset 12. Width at 16, height at 20 (4 bytes each, big-endian)
726 const uint8_t* p = reinterpret_cast<const uint8_t*>(data.data());
727 uint32_t w = (static_cast<uint32_t>(p[16]) << 24) | (static_cast<uint32_t>(p[17]) << 16) | (static_cast<uint32_t>(p[18]) << 8) |
728 static_cast<uint32_t>(p[19]);
729 uint32_t h = (static_cast<uint32_t>(p[20]) << 24) | (static_cast<uint32_t>(p[21]) << 16) | (static_cast<uint32_t>(p[22]) << 8) |
730 static_cast<uint32_t>(p[23]);
731 return {w, h};
732 }
733
734 // Check for JPEG
735 if (reinterpret_cast<const uint8_t*>(data.data())[0] == 0xFF and reinterpret_cast<const uint8_t*>(data.data())[1] == 0xD8) {
736 size_t offset = 2;
737 while (offset + 4 < data.size()) {
738 const uint8_t* p = reinterpret_cast<const uint8_t*>(data.data()) + offset;
739 if (p[0] != 0xFF) break;
740 uint8_t marker = p[1];
741 uint32_t length = (static_cast<uint32_t>(p[2]) << 8) | static_cast<uint32_t>(p[3]);
742
743 // SOF0 (Start Of Frame 0) marker is 0xFFC0. Others are 0xFFC1-0xFFC3, 0xFFC5-0xFFC7, 0xFFC9-0xFFCB, 0xFFCD-0xFFCF
744 if ((marker >= 0xC0 and marker <= 0xC3) or (marker >= 0xC5 and marker <= 0xC7) or (marker >= 0xC9 and marker <= 0xCB) ||
745 (marker >= 0xCD and marker <= 0xCF))
746 {
747 if (offset + 9 > data.size()) return {0, 0};
748 // Height is at offset 5, width at 7 (2 bytes each, big-endian)
749 uint32_t h = (static_cast<uint32_t>(p[5]) << 8) | static_cast<uint32_t>(p[6]);
750 uint32_t w = (static_cast<uint32_t>(p[7]) << 8) | static_cast<uint32_t>(p[8]);
751 return {w, h};
752 }
753 offset += length + 2;
754 }
755 }
756
757 return {0, 0};
758 }
759
760} // namespace OpenXLSX
761
762#endif // OPENXLSX_XLUTILITIES_HPP
Layer-2 OOXML DOM idioms built on the frozen XLXmlParser substrate.
XMLNode previous_sibling_of_type(T type_=node_element) const
Definition XLXmlParser.hpp:220
XMLAttribute append_attribute(const char *name_)
Definition XLXmlParser.cpp:114
XMLNode prepend_child(T type_=node_element)
Definition XLXmlParser.hpp:164
XMLNode child(const char *name_) const
Definition XLXmlParser.cpp:150
XMLNode last_child_of_type(T type_=node_element) const
Definition XLXmlParser.hpp:208
XMLAttribute attribute(const char *name_) const
Definition XLXmlParser.cpp:96
XMLNode insert_child_before(T type_, const XMLNode &node)
Definition XLXmlParser.hpp:176
XMLNode first_child_of_type(T type_=node_element) const
Definition XLXmlParser.hpp:204
bool empty() const
Definition XLXmlParser.cpp:58
XMLNode next_sibling_of_type(T type_=node_element) const
Definition XLXmlParser.hpp:216
XMLNode insert_child_after(T type_, const XMLNode &node)
Definition XLXmlParser.hpp:172
XMLNode append_child(T type_=node_element)
Definition XLXmlParser.hpp:160
XMLNode parent() const
Definition XLXmlParser.cpp:144
Definition XLException.hpp:60
Definition XLException.hpp:33
Definition XLException.hpp:78
Definition XLXmlParser.hpp:283
bool set_value(const char *rhs)
Definition XLXmlParser.cpp:533
unsigned long long as_ullong(unsigned long long def=0) const
Definition XLXmlParser.cpp:623
unsigned int as_uint(unsigned int def=0) const
Definition XLXmlParser.cpp:599
const char * value() const
Definition XLXmlParser.cpp:521
bool empty() const
Definition XLXmlParser.cpp:513
int as_int(int def=0) const
Definition XLXmlParser.cpp:593
Definition IXLCellProvider.hpp:24
std::string XLValueTypeString(XLValueType t)
Get a string representation of pugi::xml_node_type.
Definition XLUtilities.hpp:200
constexpr uint32_t MAX_ROWS
Definition XLConstants.hpp:19
constexpr XMLNodeType node_comment
Definition XLXmlParser.hpp:74
constexpr XMLNodeType node_document
Definition XLXmlParser.hpp:70
void ignore(const T &)
Get rid of compiler warnings about unused variables (-Wunused-variable) or unused parameters (-Wunusu...
Definition XLUtilities.hpp:192
std::string XLContentTypeString(OpenXLSX::XLContentType const &t)
Get a string representation of OpenXLSX::XLContentType.
Definition XLUtilities.hpp:258
constexpr XMLNodeType node_cdata
Definition XLXmlParser.hpp:73
int XMLNodeType
Definition XLXmlParser.hpp:68
constexpr const XLStyleIndex XLDefaultCellFormat
Definition XLStyles_Common.hpp:54
XLContentType
Definition XLContentTypes.hpp:38
@ Workbook
Definition XLContentTypes.hpp:39
@ Slicer
Definition XLContentTypes.hpp:64
@ Chart
Definition XLContentTypes.hpp:49
@ ControlProperties
Definition XLContentTypes.hpp:52
@ CoreProperties
Definition XLContentTypes.hpp:55
@ SharedStrings
Definition XLContentTypes.hpp:47
@ ChartColorStyle
Definition XLContentTypes.hpp:51
@ Styles
Definition XLContentTypes.hpp:46
@ Table
Definition XLContentTypes.hpp:59
@ Worksheet
Definition XLContentTypes.hpp:42
@ ExternalLink
Definition XLContentTypes.hpp:44
@ VBAProject
Definition XLContentTypes.hpp:54
@ PivotCacheDefinition
Definition XLContentTypes.hpp:66
@ Drawing
Definition XLContentTypes.hpp:48
@ PivotCacheRecords
Definition XLContentTypes.hpp:67
@ PivotTable
Definition XLContentTypes.hpp:63
@ CalculationChain
Definition XLContentTypes.hpp:53
@ Hyperlink
Definition XLContentTypes.hpp:61
@ Comments
Definition XLContentTypes.hpp:58
@ Unknown
Definition XLContentTypes.hpp:62
@ SlicerCache
Definition XLContentTypes.hpp:65
@ ExtendedProperties
Definition XLContentTypes.hpp:56
@ Persons
Definition XLContentTypes.hpp:69
@ WorkbookMacroEnabled
Definition XLContentTypes.hpp:41
@ ChartStyle
Definition XLContentTypes.hpp:50
@ Theme
Definition XLContentTypes.hpp:45
@ CustomProperties
Definition XLContentTypes.hpp:57
@ Relationships
Definition XLContentTypes.hpp:40
@ Chartsheet
Definition XLContentTypes.hpp:43
@ VMLDrawing
Definition XLContentTypes.hpp:60
@ ThreadedComments
Definition XLContentTypes.hpp:68
XLRelationshipType
An enum of the possible relationship (or XML document) types used in relationship (....
Definition XLRelationships.hpp:68
@ Workbook
Definition XLRelationships.hpp:72
@ Slicer
Definition XLRelationships.hpp:97
@ Chart
Definition XLRelationships.hpp:82
@ ControlProperties
Definition XLRelationships.hpp:91
@ CoreProperties
Definition XLRelationships.hpp:69
@ SharedStrings
Definition XLRelationships.hpp:88
@ ChartColorStyle
Definition XLRelationships.hpp:84
@ Macrosheet
Definition XLRelationships.hpp:76
@ Person
Definition XLRelationships.hpp:102
@ Styles
Definition XLRelationships.hpp:81
@ Table
Definition XLRelationships.hpp:93
@ Worksheet
Definition XLRelationships.hpp:73
@ ExternalLink
Definition XLRelationships.hpp:78
@ VBAProject
Definition XLRelationships.hpp:90
@ PivotCacheDefinition
Definition XLRelationships.hpp:99
@ Drawing
Definition XLRelationships.hpp:86
@ PrinterSettings
Definition XLRelationships.hpp:89
@ PivotCacheRecords
Definition XLRelationships.hpp:100
@ PivotTable
Definition XLRelationships.hpp:96
@ CalculationChain
Definition XLRelationships.hpp:77
@ Hyperlink
Definition XLRelationships.hpp:94
@ Comments
Definition XLRelationships.hpp:92
@ Unknown
Definition XLRelationships.hpp:95
@ SlicerCache
Definition XLRelationships.hpp:98
@ ExtendedProperties
Definition XLRelationships.hpp:70
@ ExternalLinkPath
Definition XLRelationships.hpp:79
@ Image
Definition XLRelationships.hpp:85
@ Dialogsheet
Definition XLRelationships.hpp:75
@ ChartStyle
Definition XLRelationships.hpp:83
@ Theme
Definition XLRelationships.hpp:80
@ CustomProperties
Definition XLRelationships.hpp:71
@ Chartsheet
Definition XLRelationships.hpp:74
@ VMLDrawing
Definition XLRelationships.hpp:87
@ ThreadedComments
Definition XLRelationships.hpp:101
char * makeCellAddress(uint32_t row, uint16_t col, char *buffer) noexcept
Generate cell address string directly without creating XLCellReference object. Performance optimizati...
Definition XLUtilities.hpp:159
constexpr XMLNodeType node_element
Definition XLXmlParser.hpp:71
void setDefaultCellAttributes(XMLNode cellNode, const std::string &cellRef, XMLNode rowNode, uint16_t colNo, std::vector< XLStyleIndex > const &colStyles={})
set the cell reference, and a default cell style attribute if and only if row or column style is !...
Definition XLUtilities.hpp:546
std::string xml_node_type_string(XMLNodeType t)
Get a string representation of XMLNodeType.
Definition XLUtilities.hpp:227
constexpr uint16_t MAX_COLS
Definition XLConstants.hpp:18
constexpr XMLNodeType node_doctype
Definition XLXmlParser.hpp:76
XLStyleIndex getColumnStyle(XMLNode rowNode, uint16_t colNo)
Definition XLUtilities.hpp:522
XLValueType
Enum defining the valid value types for a an Excel spreadsheet cell.
Definition XLCellValue.hpp:47
@ Float
Definition XLCellValue.hpp:47
@ RichText
Definition XLCellValue.hpp:47
@ String
Definition XLCellValue.hpp:47
@ Boolean
Definition XLCellValue.hpp:47
@ Error
Definition XLCellValue.hpp:47
@ Integer
Definition XLCellValue.hpp:47
@ Empty
Definition XLCellValue.hpp:47
std::string XLRelationshipTypeString(OpenXLSX::XLRelationshipType const &t)
Get a string representation of OpenXLSX::XLRelationshipType.
Definition XLUtilities.hpp:334
constexpr XMLNodeType node_pi
Definition XLXmlParser.hpp:77
OpenXLSX_xml_node XMLNode
Definition XLXmlParser.hpp:64
std::vector< XLStyleIndex > getColumnStyles(XMLNode rowNode, uint16_t count)
get the style attribute s for the indicated column, if any is set
Definition XLUtilities.hpp:502
std::pair< uint32_t, uint32_t > getImageDimensions(const std::string &data)
Extract image dimensions (width and height) from raw image data (PNG/JPEG).
Definition XLUtilities.hpp:718
bool isCleanXmlString(std::string_view sv) noexcept
Checks if a string contains only valid XML 1.0 characters.
Definition XLUtilities.hpp:35
constexpr XMLNodeType node_null
Definition XLXmlParser.hpp:69
XMLNode getCellNode(XMLNode rowNode, uint16_t columnNumber, uint32_t rowNumber=0, std::vector< XLStyleIndex > const &colStyles={}, uint16_t *hintColNumber=nullptr, XMLNode *hintCellNode=nullptr)
Retrieve the xml node representing the cell at the given row and column. If the node doesn't exist,...
Definition XLUtilities.hpp:604
size_t XLStyleIndex
Definition XLStyles_Common.hpp:36
void appendEscaped(std::string &out, std::string_view sv)
Fast XML escape: appends escaped characters to out to avoid intermediate allocations.
Definition XLUtilities.hpp:69
XMLNode getRowNode(XMLNode sheetDataNode, uint32_t rowNumber, uint32_t *hintRowNumber=nullptr, XMLNode *hintRowNode=nullptr)
Definition XLUtilities.hpp:414
constexpr XMLNodeType node_pcdata
Definition XLXmlParser.hpp:72
constexpr XMLNodeType node_declaration
Definition XLXmlParser.hpp:75
char * columnToLetters(uint16_t colNo, char *buffer) noexcept
Convert column number to column letter string (A, B, ..., Z, AA, AB, ..., XFD) Performance optimizati...
Definition XLUtilities.hpp:127
std::string sanitizeXmlString(std::string_view sv)
Removes invalid XML 1.0 control characters from a string to prevent file corruption.
Definition XLUtilities.hpp:51
uint16_t extractColumnFromCellRef(const char *cellRef) noexcept
Lightweight function to extract column number from a cell reference string. This is a performance-opt...
Definition XLUtilities.hpp:103