OpenXLSX 1.12.1
Modern C++ Excel Library (Fork of OpenXLSX by Kenneth Troldal Balslev)
Loading...
Searching...
No Matches
XLConstants.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_XLCONSTANTS_HPP
12#define OPENXLSX_XLCONSTANTS_HPP
13
14#include <cstdint>
15
16namespace OpenXLSX
17{
18 inline constexpr uint16_t MAX_COLS = 16'384;
19 inline constexpr uint32_t MAX_ROWS = 1'048'576;
20
22 {
23 uint32_t val;
24 explicit XLRowIndex(uint32_t v) : val(v) {}
25 operator uint32_t() const { return val; }
26 };
27
29 {
30 uint16_t val;
31 explicit XLColIndex(uint16_t v) : val(v) {}
32 operator uint16_t() const { return val; }
33 };
34
35 inline namespace IndexLiterals
36 {
37 inline XLRowIndex operator""_row(unsigned long long v) { return XLRowIndex(static_cast<uint32_t>(v)); }
38 inline XLColIndex operator""_col(unsigned long long v) { return XLColIndex(static_cast<uint16_t>(v)); }
39 } // namespace IndexLiterals
40
42 {
43 public:
44 XLDistance() = default;
45 static XLDistance Pixels(uint32_t px) { return XLDistance(static_cast<uint64_t>(px) * 9525); }
46 static XLDistance Centimeters(double cm) { return XLDistance(static_cast<uint64_t>(cm * 360000.0)); }
47 static XLDistance Inches(double inch) { return XLDistance(static_cast<uint64_t>(inch * 914400.0)); }
48
49 static XLDistance Points(double pt) { return XLDistance(static_cast<uint64_t>(pt * 12700.0)); }
50 static XLDistance EMU(uint64_t emu) { return XLDistance(emu); }
51
52 [[nodiscard]] uint64_t getEMU() const { return m_emu; }
53 [[nodiscard]] uint32_t getPixels() const { return static_cast<uint32_t>(m_emu / 9525); }
54 [[nodiscard]] double getInches() const { return static_cast<double>(m_emu) / 914400.0; }
55
56 private:
57 explicit XLDistance(uint64_t emu) : m_emu(emu) {}
58 uint64_t m_emu{0};
59 };
60
61 inline namespace DistanceLiterals
62 {
63 inline XLDistance operator""_px(unsigned long long px) { return XLDistance::Pixels(static_cast<uint32_t>(px)); }
64 inline XLDistance operator""_cm(long double cm) { return XLDistance::Centimeters(static_cast<double>(cm)); }
65 inline XLDistance operator""_cm(unsigned long long cm) { return XLDistance::Centimeters(static_cast<double>(cm)); }
66
67 inline XLDistance operator""_inch(long double inch) { return XLDistance::Inches(static_cast<double>(inch)); }
68 inline XLDistance operator""_inch(unsigned long long inch) { return XLDistance::Inches(static_cast<double>(inch)); }
69
70 inline XLDistance operator""_pt(long double pt) { return XLDistance::Points(static_cast<double>(pt)); }
71 inline XLDistance operator""_pt(unsigned long long pt) { return XLDistance::Points(static_cast<double>(pt)); }
72
73 } // namespace DistanceLiterals
74
75 // anchoring a comment shape below these values was not possible in LibreOffice - TBC with MS Office
76 inline constexpr uint16_t MAX_SHAPE_ANCHOR_COLUMN = 13067; // column "SHO"
77 inline constexpr uint32_t MAX_SHAPE_ANCHOR_ROW = 852177;
78} // namespace OpenXLSX
79
80#endif // OPENXLSX_XLCONSTANTS_HPP
Definition XLConstants.hpp:42
static XLDistance Inches(double inch)
Definition XLConstants.hpp:47
static XLDistance EMU(uint64_t emu)
Definition XLConstants.hpp:50
double getInches() const
Definition XLConstants.hpp:54
static XLDistance Centimeters(double cm)
Definition XLConstants.hpp:46
static XLDistance Points(double pt)
Definition XLConstants.hpp:49
uint32_t getPixels() const
Definition XLConstants.hpp:53
uint64_t getEMU() const
Definition XLConstants.hpp:52
static XLDistance Pixels(uint32_t px)
Definition XLConstants.hpp:45
Definition XLConstants.hpp:62
Definition XLConstants.hpp:36
Definition IXLCellProvider.hpp:24
constexpr uint32_t MAX_ROWS
Definition XLConstants.hpp:19
constexpr uint16_t MAX_SHAPE_ANCHOR_COLUMN
Definition XLConstants.hpp:76
constexpr uint32_t MAX_SHAPE_ANCHOR_ROW
Definition XLConstants.hpp:77
constexpr uint16_t MAX_COLS
Definition XLConstants.hpp:18
Definition XLConstants.hpp:29
uint16_t val
Definition XLConstants.hpp:30
XLColIndex(uint16_t v)
Definition XLConstants.hpp:31
Definition XLConstants.hpp:22
uint32_t val
Definition XLConstants.hpp:23
XLRowIndex(uint32_t v)
Definition XLConstants.hpp:24