• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

xlnt-community / xlnt / c67f863f-2500-4a79-8882-3e703a3e5f61

25 Jan 2026 09:06PM UTC coverage: 83.928% (+1.1%) from 82.793%
c67f863f-2500-4a79-8882-3e703a3e5f61

Pull #87

circleci

doomlaur
Specify that the character limit for worksheet titles is in Unicode characters, not bytes
Pull Request #87: Improve documentation when exceptions are thrown (fixes #81)

15263 of 19954 branches covered (76.49%)

722 of 901 new or added lines in 37 files covered. (80.13%)

15 existing lines in 5 files now uncovered.

12491 of 14883 relevant lines covered (83.93%)

12216.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

72.18
./source/styles/style.cpp
1
// Copyright (c) 2014-2022 Thomas Fussell
2
// Copyright (c) 2010-2015 openpyxl
3
// Copyright (c) 2024-2025 xlnt-community
4
//
5
// Permission is hereby granted, free of charge, to any person obtaining a copy
6
// of this software and associated documentation files (the "Software"), to deal
7
// in the Software without restriction, including without limitation the rights
8
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
// copies of the Software, and to permit persons to whom the Software is
10
// furnished to do so, subject to the following conditions:
11
//
12
// The above copyright notice and this permission notice shall be included in
13
// all copies or substantial portions of the Software.
14
//
15
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
// THE SOFTWARE
22
//
23
// @license: http://www.opensource.org/licenses/mit-license.php
24
// @author: see AUTHORS file
25

26
#include <xlnt/styles/alignment.hpp>
27
#include <xlnt/styles/border.hpp>
28
#include <xlnt/styles/fill.hpp>
29
#include <xlnt/styles/font.hpp>
30
#include <xlnt/styles/number_format.hpp>
31
#include <xlnt/styles/protection.hpp>
32
#include <xlnt/styles/style.hpp>
33
#include <detail/implementations/style_impl.hpp>
34
#include <detail/implementations/stylesheet.hpp>
35

36
namespace {
37

38
std::vector<xlnt::number_format>::iterator find_number_format(
363✔
39
    std::vector<xlnt::number_format> &number_formats, std::size_t id)
40
{
41
    return std::find_if(number_formats.begin(), number_formats.end(),
363✔
42
        [id](const xlnt::number_format &nf) { return nf.id() == id; });
417✔
43
}
44

45
} // namespace
46

47
namespace xlnt {
48

49
style::style(detail::style_impl *d)
1,054✔
50
    : d_(d)
1,054✔
51
{
52
}
1,054✔
53

54
bool style::hidden() const
×
55
{
56
    return d_->hidden_style;
×
57
}
58

59
style style::hidden(bool value)
×
60
{
61
    d_->hidden_style = value;
×
62
    return style(d_);
×
63
}
64

65
std::size_t style::builtin_id() const
1✔
66
{
67
    if (!d_->builtin_id.is_set())
1!
68
    {
69
        throw xlnt::invalid_attribute("the style does not use a builtin style");
3✔
70
    }
UNCOV
71
    return d_->builtin_id.get();
×
72
}
73

74
bool style::builtin() const
1✔
75
{
76
    return d_->builtin_id.is_set();
1✔
77
}
78

79
std::string style::name() const
33✔
80
{
81
    return d_->name;
33✔
82
}
83

84
style style::name(const std::string &name)
×
85
{
86
    d_->name = name;
×
87
    return *this;
×
88
}
89

90
bool style::custom_builtin() const
×
91
{
92
    return d_->builtin_id.is_set() && d_->custom_builtin;
×
93
}
94

95
bool style::operator==(const style &other) const
9✔
96
{
97
    return name() == other.name();
9✔
98
}
99

100
bool style::operator!=(const style &other) const
×
101
{
102
    return !operator==(other);
×
103
}
104

105
xlnt::alignment style::alignment() const
12✔
106
{
107
    if (d_->alignment_id.is_set())
12✔
108
    {
109
        return d_->parent->alignments.at(d_->alignment_id.get());
2✔
110
    }
111
    return {};
10✔
112
}
113

114
style style::alignment(const xlnt::alignment &new_alignment, optional<bool> applied)
2✔
115
{
116
    d_->alignment_id = d_->parent->find_or_add(d_->parent->alignments, new_alignment);
2✔
117
    d_->alignment_applied = applied;
2✔
118

119
    return *this;
2✔
120
}
121

122
xlnt::border style::border() const
13✔
123
{
124
    if (d_->border_id.is_set())
13!
125
    {
126
        return d_->parent->borders.at(d_->border_id.get());
13✔
127
    }
NEW
128
    return {};
×
129
}
130

131
style style::border(const xlnt::border &new_border, optional<bool> applied)
342✔
132
{
133
    d_->border_id = d_->parent->find_or_add(d_->parent->borders, new_border);
342✔
134
    d_->border_applied = applied;
342✔
135

136
    return *this;
342✔
137
}
138

139
xlnt::fill style::fill() const
13✔
140
{
141
    if (d_->fill_id.is_set())
13!
142
    {
143
        return d_->parent->fills.at(d_->fill_id.get());
13✔
144
    }
NEW
145
    return {};
×
146
}
147

148
style style::fill(const xlnt::fill &new_fill, optional<bool> applied)
342✔
149
{
150
    d_->fill_id = d_->parent->find_or_add(d_->parent->fills, new_fill);
342✔
151
    d_->fill_applied = applied;
342✔
152

153
    return *this;
342✔
154
}
155

156
xlnt::font style::font() const
12✔
157
{
158
    if (d_->font_id.is_set())
12!
159
    {
160
        return d_->parent->fonts.at(d_->font_id.get());
12✔
161
    }
NEW
162
    return {};
×
163
}
164

165
style style::font(const xlnt::font &new_font, optional<bool> applied)
342✔
166
{
167
    d_->font_id = d_->parent->find_or_add(d_->parent->fonts, new_font);
342✔
168
    d_->font_applied = applied;
342✔
169

170
    return *this;
342✔
171
}
172

173
xlnt::number_format style::number_format() const
19✔
174
{
175
    if (d_->number_format_id.is_set())
19!
176
    {
177
        auto match = find_number_format(d_->parent->number_formats,
19✔
178
            d_->number_format_id.get());
19✔
179

180
        if (match != d_->parent->number_formats.end())
19!
181
        {
182
            return *match;
19✔
183
        }
184
    }
185

NEW
186
    return {};
×
187
}
188

189
style style::number_format(const xlnt::number_format &new_number_format, optional<bool> applied)
348✔
190
{
191
    auto copy = new_number_format;
348✔
192

193
    if (!copy.has_id())
348✔
194
    {
195
        copy.id(d_->parent->next_custom_number_format_id());
4✔
196
        d_->parent->number_formats.push_back(copy);
4✔
197
    }
198
    else if (find_number_format(d_->parent->number_formats, copy.id())
344✔
199
        == d_->parent->number_formats.end())
688✔
200
    {
201
        d_->parent->number_formats.push_back(copy);
342✔
202
    }
203

204
    d_->number_format_id = copy.id();
348✔
205
    d_->number_format_applied = applied;
348✔
206

207
    return *this;
348✔
208
}
348✔
209

210
xlnt::protection style::protection() const
12✔
211
{
212
    if (d_->protection_id.is_set())
12✔
213
    {
214
        return d_->parent->protections.at(d_->protection_id.get());
2✔
215
    }
216
    return {};
10✔
217
}
218

219
style style::protection(const xlnt::protection &new_protection, optional<bool> applied)
2✔
220
{
221
    d_->protection_id = d_->parent->find_or_add(d_->parent->protections, new_protection);
2✔
222
    d_->protection_applied = applied;
2✔
223

224
    return *this;
2✔
225
}
226

227
bool style::has_alignment() const
2✔
228
{
229
    return d_->alignment_id.is_set();
2✔
230
}
231

UNCOV
232
bool style::alignment_applied() const
×
233
{
234
    return d_->alignment_applied.is_set()
×
235
        ? d_->alignment_applied.get()
×
236
        : d_->alignment_id.is_set();
×
237
}
238

239
bool style::has_border() const
1✔
240
{
241
    return d_->border_id.is_set();
1✔
242
}
243

UNCOV
244
bool style::border_applied() const
×
245
{
246
    return d_->border_applied.is_set()
×
247
        ? d_->border_applied.get()
×
248
        : d_->border_id.is_set();
×
249
}
250

251
bool style::has_fill() const
1✔
252
{
253
    return d_->fill_id.is_set();
1✔
254
}
255

UNCOV
256
bool style::fill_applied() const
×
257
{
258
    return d_->fill_applied.is_set()
×
259
        ? d_->fill_applied.get()
×
260
        : d_->fill_id.is_set();
×
261
}
262

263
bool style::has_font() const
1✔
264
{
265
    return d_->font_id.is_set();
1✔
266
}
267

UNCOV
268
bool style::font_applied() const
×
269
{
270
    return d_->font_applied.is_set()
×
271
        ? d_->font_applied.get()
×
272
        : d_->font_id.is_set();
×
273
}
274

275
bool style::has_number_format() const
1✔
276
{
277
    return d_->number_format_id.is_set();
1✔
278
}
279

280
bool style::number_format_applied() const
2✔
281
{
282
    return d_->number_format_applied.is_set()
2✔
283
        ? d_->number_format_applied.get()
2!
284
        : d_->number_format_id.is_set();
2✔
285
}
286

287
bool style::has_protection() const
2✔
288
{
289
    return d_->protection_id.is_set();
2✔
290
}
291

UNCOV
292
bool style::protection_applied() const
×
293
{
294
    return d_->protection_applied.is_set()
×
295
        ? d_->protection_applied.get()
×
296
        : d_->protection_id.is_set();
×
297
}
298

299
bool style::pivot_button() const
2✔
300
{
301
    return d_->pivot_button_;
2✔
302
}
303

304
void style::pivot_button(bool show)
1✔
305
{
306
    d_->pivot_button_ = show;
1✔
307
}
1✔
308

309
bool style::quote_prefix() const
2✔
310
{
311
    return d_->quote_prefix_;
2✔
312
}
313

314
void style::quote_prefix(bool quote)
1✔
315
{
316
    d_->quote_prefix_ = quote;
1✔
317
}
1✔
318

319
} // namespace xlnt
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc