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

xlnt-community / xlnt / 796b5d63-faf9-48e9-946d-5f649cf3d172

05 Mar 2025 05:11AM UTC coverage: 82.27% (+0.4%) from 81.87%
796b5d63-faf9-48e9-946d-5f649cf3d172

push

circleci

web-flow
Fix workbook comparisons, cleanup of included headers (#59)

This PR does the following:
1. Fixes issue https://github.com/xlnt-community/xlnt/issues/58. Please
read the issue for detailed infos.
2. Changes / removes a few definitions of `XLNT_API(_INTERNAL)` which
were defined in the wrong places (e.g. `.cpp` file, or in the header
although the function was implemented in the header too).
3. Cleans up many unnecessary or missing headers which I found along the
way.
4. Added `operator!=` to many classes to ease such comparisons and
improve programming experience.

103 of 143 new or added lines in 20 files covered. (72.03%)

3 existing lines in 2 files now uncovered.

11554 of 14044 relevant lines covered (82.27%)

1176465.94 hits per line

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

42.55
./source/worksheet/header_footer.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/worksheet/header_footer.hpp>
27

28
namespace xlnt {
29

30
bool header_footer::has_header() const
×
31
{
32
    return !odd_headers_.empty() || !even_headers_.empty() || has_first_page_header();
×
33
}
34

35
bool header_footer::has_footer() const
×
36
{
37
    return !odd_headers_.empty() || !even_headers_.empty() || has_first_page_footer();
×
38
}
39

40
bool header_footer::align_with_margins() const
1✔
41
{
42
    return align_with_margins_;
1✔
43
}
44

45
header_footer &header_footer::align_with_margins(bool align)
18✔
46
{
47
    align_with_margins_ = align;
18✔
48
    return *this;
18✔
49
}
50

51
bool header_footer::different_odd_even() const
28✔
52
{
53
    return different_odd_even_;
28✔
54
}
55

56
bool header_footer::different_first() const
22✔
57
{
58
    return !first_headers_.empty() || !first_footers_.empty();
22✔
59
}
60

61
bool header_footer::scale_with_doc() const
1✔
62
{
63
    return scale_with_doc_;
1✔
64
}
65

66
header_footer &header_footer::scale_with_doc(bool scale)
18✔
67
{
68
    scale_with_doc_ = scale;
18✔
69
    return *this;
18✔
70
}
71

72
// Normal Header
73

74
bool header_footer::has_header(location where) const
27✔
75
{
76
    return odd_headers_.count(where) > 0 || has_first_page_header(where);
27✔
77
}
78

79
void header_footer::clear_header()
×
80
{
81
    odd_headers_.clear();
×
82
    even_headers_.clear();
×
83
    first_headers_.clear();
×
84
}
×
85

86
void header_footer::clear_header(location where)
3✔
87
{
88
    odd_headers_.erase(where);
3✔
89
    even_headers_.erase(where);
3✔
90
    first_headers_.erase(where);
3✔
91
}
3✔
92

93
header_footer &header_footer::header(location where, const std::string &text)
3✔
94
{
95
    return header(where, rich_text(text));
3✔
96
}
97

98
header_footer &header_footer::header(location where, const rich_text &text)
27✔
99
{
100
    odd_headers_[where] = text;
27✔
101
    return *this;
27✔
102
}
103

104
rich_text header_footer::header(location where) const
14✔
105
{
106
    return odd_headers_.at(where);
14✔
107
}
108

109
// First Page Header
110

111
bool header_footer::has_first_page_header() const
×
112
{
113
    return !first_headers_.empty();
×
114
}
115

116
bool header_footer::has_first_page_header(location where) const
19✔
117
{
118
    return first_headers_.count(where) > 0;
19✔
119
}
120

121
void header_footer::clear_first_page_header()
×
122
{
123
    first_headers_.clear();
×
124
}
×
125

126
void header_footer::clear_first_page_header(location where)
×
127
{
128
    first_headers_.erase(where);
×
129
}
×
130

131
header_footer &header_footer::first_page_header(location where, const rich_text &text)
×
132
{
133
    first_headers_[where] = text;
×
134
    return *this;
×
135
}
136

137
rich_text header_footer::first_page_header(location where) const
×
138
{
139
    return first_headers_.at(where);
×
140
}
141

142
// Odd/Even Header
143

144
bool header_footer::has_odd_even_header() const
×
145
{
146
    return different_odd_even() && !odd_headers_.empty();
×
147
}
148

149
bool header_footer::has_odd_even_header(location where) const
6✔
150
{
151
    return different_odd_even() && odd_headers_.count(where) > 0;
6✔
152
}
153

154
void header_footer::clear_odd_even_header()
×
155
{
156
    odd_headers_.clear();
×
157
    even_headers_.clear();
×
158
    different_odd_even_ = false;
×
159
}
×
160

161
void header_footer::clear_odd_even_header(location where)
×
162
{
163
    odd_headers_.erase(where);
×
164
    even_headers_.erase(where);
×
165
}
×
166

167
header_footer &header_footer::odd_even_header(location where, const rich_text &odd, const rich_text &even)
×
168
{
169
    odd_headers_[where] = odd;
×
170
    even_headers_[where] = even;
×
171
    different_odd_even_ = true;
×
172

173
    return *this;
×
174
}
175

176
rich_text header_footer::odd_header(location where) const
×
177
{
178
    return odd_headers_.at(where);
×
179
}
180

181
rich_text header_footer::even_header(location where) const
×
182
{
183
    return even_headers_.at(where);
×
184
}
185

186
// Normal Footer
187

188
bool header_footer::has_footer(location where) const
27✔
189
{
190
    return odd_footers_.count(where) > 0;
27✔
191
}
192

193
void header_footer::clear_footer()
×
194
{
195
    odd_footers_.clear();
×
196
    even_footers_.clear();
×
197
    first_footers_.clear();
×
198
}
×
199

200
void header_footer::clear_footer(location where)
3✔
201
{
202
    odd_footers_.erase(where);
3✔
203
    even_footers_.erase(where);
3✔
204
    first_footers_.erase(where);
3✔
205
}
3✔
206

207
header_footer &header_footer::footer(location where, const std::string &text)
3✔
208
{
209
    return footer(where, rich_text(text));
3✔
210
}
211

212
header_footer &header_footer::footer(location where, const rich_text &text)
29✔
213
{
214
    odd_footers_[where] = text;
29✔
215
    return *this;
29✔
216
}
217

218
rich_text header_footer::footer(location where) const
15✔
219
{
220
    return odd_footers_.at(where);
15✔
221
}
222

223
// First Page footer
224

225
bool header_footer::has_first_page_footer() const
×
226
{
227
    return different_first() && !first_footers_.empty();
×
228
}
229

230
bool header_footer::has_first_page_footer(location where) const
6✔
231
{
232
    return different_first() && first_footers_.count(where) > 0;
6✔
233
}
234

235
void header_footer::clear_first_page_footer()
×
236
{
237
    first_footers_.clear();
×
238
}
×
239

240
void header_footer::clear_first_page_footer(location where)
×
241
{
242
    first_footers_.erase(where);
×
243
}
×
244

245
header_footer &header_footer::first_page_footer(location where, const rich_text &text)
×
246
{
247
    first_footers_[where] = text;
×
248
    return *this;
×
249
}
250

251
rich_text header_footer::first_page_footer(location where) const
×
252
{
253
    return first_footers_.at(where);
×
254
}
255

256
// Odd/Even Footer
257

258
bool header_footer::has_odd_even_footer() const
×
259
{
260
    return different_odd_even() && !even_footers_.empty();
×
261
}
262

263
bool header_footer::has_odd_even_footer(location where) const
6✔
264
{
265
    return different_odd_even() && even_footers_.count(where) > 0;
6✔
266
}
267

268
void header_footer::clear_odd_even_footer()
×
269
{
270
    odd_footers_.clear();
×
271
    even_footers_.clear();
×
272
}
×
273

274
void header_footer::clear_odd_even_footer(location where)
×
275
{
276
    odd_footers_.erase(where);
×
277
    even_footers_.erase(where);
×
278
}
×
279

280
header_footer &header_footer::odd_even_footer(location where, const rich_text &odd, const rich_text &even)
×
281
{
282
    odd_footers_[where] = odd;
×
283
    even_footers_[where] = even;
×
284
    different_odd_even_ = true;
×
285

286
    return *this;
×
287
}
288

289
rich_text header_footer::odd_footer(location where) const
×
290
{
291
    return odd_footers_.at(where);
×
292
}
293

294
rich_text header_footer::even_footer(location where) const
×
295
{
296
    return even_footers_.at(where);
×
297
}
298

299
bool header_footer::operator==(const header_footer &rhs) const
6✔
300
{
301
    return align_with_margins_ == rhs.align_with_margins_
6✔
302
        && different_odd_even_ == rhs.different_odd_even_
6✔
303
        && scale_with_doc_ == rhs.scale_with_doc_
6✔
304
        && odd_headers_ == rhs.odd_headers_
6✔
305
        && even_headers_ == rhs.even_headers_
6✔
306
        && first_headers_ == rhs.first_headers_
6✔
307
        && odd_footers_ == rhs.odd_footers_
6✔
308
        && even_footers_ == rhs.even_footers_
6✔
309
        && first_footers_ == rhs.first_footers_;
12✔
310
}
311

NEW
312
bool header_footer::operator!=(const header_footer &rhs) const
×
313
{
NEW
314
    return !(*this == rhs);
×
315
}
316

317
} // 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