-
Notifications
You must be signed in to change notification settings - Fork 395
/
worksheet.hpp
756 lines (603 loc) · 16.9 KB
/
worksheet.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
// Copyright (c) 2014-2016 Thomas Fussell
// Copyright (c) 2010-2015 openpyxl
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <iterator>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include <xlnt/xlnt_config.hpp>
#include <xlnt/cell/index_types.hpp>
#include <xlnt/packaging/relationship.hpp>
#include <xlnt/worksheet/page_margins.hpp>
#include <xlnt/worksheet/page_setup.hpp>
#include <xlnt/worksheet/sheet_view.hpp>
namespace xlnt {
class cell;
class cell_reference;
class cell_vector;
class column_properties;
class comment;
class const_range_iterator;
class footer;
class header;
class range;
class range_iterator;
class range_reference;
class relationship;
class row_properties;
class workbook;
struct date;
namespace detail {
class xlsx_consumer;
class xlsx_producer;
struct worksheet_impl;
} // namespace detail
/// <summary>
/// A worksheet is a 2D array of cells starting with cell A1 in the top-left corner
/// and extending indefinitely down and right as needed.
/// </summary>
class XLNT_API worksheet
{
public:
/// <summary>
/// Iterate over a non-const worksheet with an iterator of this type.
/// </summary>
using iterator = range_iterator;
/// <summary>
/// Iterate over a non-const worksheet with an iterator of this type.
/// </summary>
using const_iterator = const_range_iterator;
/// <summary>
/// Iterate in reverse over a non-const worksheet with an iterator of this type.
/// </summary>
using reverse_iterator = std::reverse_iterator<iterator>;
/// <summary>
/// Iterate in reverse order over a const worksheet with an iterator of this type.
/// </summary>
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
/// <summary>
/// Construct a null worksheet. No methods should be called on such a worksheet.
/// </summary>
worksheet();
/// <summary>
/// Copy constructor. This worksheet will point to the same memory as rhs's worksheet.
/// </summary>
worksheet(const worksheet &rhs);
/// <summary>
/// Returns a reference to the workbook this worksheet is owned by.
/// </summary>
class workbook &workbook();
/// <summary>
/// Returns a reference to the workbook this worksheet is owned by.
/// </summary>
const class workbook &workbook() const;
/// <summary>
/// Deletes data held in the worksheet that does not affect the internal data or display.
/// For example, unreference styles and empty cells will be removed.
/// </summary>
void garbage_collect();
// identification
/// <summary>
/// Returns the unique numeric identifier of this worksheet. This will sometimes but not necessarily
/// be the index of the worksheet in the workbook.
/// </summary>
std::size_t id() const;
/// <summary>
/// Set the unique numeric identifier. The id defaults to the lowest unused id in the workbook
/// so this should not be called without a good reason.
/// </summary>
void id(std::size_t id);
/// <summary>
/// Returns the title of this sheet.
/// </summary>
std::string title() const;
/// <summary>
/// Sets the title of this sheet.
/// </summary>
void title(const std::string &title);
// freeze panes
/// <summary>
/// Returns the top left corner of the region above and to the left of which panes are frozen.
/// </summary>
cell_reference frozen_panes() const;
/// <summary>
/// Freeze panes above and to the left of top_left_cell.
/// </summary>
void freeze_panes(cell top_left_cell);
/// <summary>
/// Freeze panes above and to the left of top_left_coordinate.
/// </summary>
void freeze_panes(const cell_reference &top_left_coordinate);
/// <summary>
/// Remove frozen panes. The data in those panes will be unaffected--this affects only the view.
/// </summary>
void unfreeze_panes();
/// <summary>
/// Returns true if this sheet has a frozen row, frozen column, or both.
/// </summary>
bool has_frozen_panes() const;
// container
/// <summary>
///
/// </summary>
class cell cell(column_t column, row_t row);
/// <summary>
///
/// </summary>
const class cell cell(column_t column, row_t row) const;
/// <summary>
///
/// </summary>
class cell cell(const cell_reference &reference);
/// <summary>
///
/// </summary>
const class cell cell(const cell_reference &reference) const;
/// <summary>
///
/// </summary>
bool has_cell(const cell_reference &reference) const;
/// <summary>
///
/// </summary>
class range range(const std::string &reference_string);
/// <summary>
///
/// </summary>
class range range(const range_reference &reference);
/// <summary>
///
/// </summary>
const class range range(const std::string &reference_string) const;
/// <summary>
///
/// </summary>
const class range range(const range_reference &reference) const;
/// <summary>
///
/// </summary>
class range rows() const;
/// <summary>
///
/// </summary>
class range rows(const std::string &range_string) const;
/// <summary>
///
/// </summary>
class range rows(int row_offset, int column_offset) const;
/// <summary>
///
/// </summary>
class range rows(const std::string &range_string, int row_offset, int column_offset) const;
/// <summary>
///
/// </summary>
class range columns() const;
// properties
/// <summary>
///
/// </summary>
xlnt::column_properties &column_properties(column_t column);
/// <summary>
///
/// </summary>
const xlnt::column_properties &column_properties(column_t column) const;
/// <summary>
///
/// </summary>
bool has_column_properties(column_t column) const;
/// <summary>
///
/// </summary>
void add_column_properties(column_t column, const class column_properties &props);
/// <summary>
/// Calculate the width of the given column. This will be the default column width if
/// a custom width is not set on this column's column_properties.
/// </summary>
double column_width(column_t column) const;
/// <summary>
///
/// </summary>
xlnt::row_properties &row_properties(row_t row);
/// <summary>
///
/// </summary>
const xlnt::row_properties &row_properties(row_t row) const;
/// <summary>
///
/// </summary>
bool has_row_properties(row_t row) const;
/// <summary>
///
/// </summary>
void add_row_properties(row_t row, const class row_properties &props);
/// <summary>
/// Calculate the height of the given row. This will be the default row height if
/// a custom height is not set on this row's row_properties.
/// </summary>
double row_height(row_t row) const;
// positioning
/// <summary>
///
/// </summary>
cell_reference point_pos(int left, int top) const;
/// <summary>
///
/// </summary>
cell_reference point_pos(const std::pair<int, int> &point) const;
/// <summary>
///
/// </summary>
std::string unique_sheet_name(const std::string &value) const;
// named range
/// <summary>
///
/// </summary>
void create_named_range(const std::string &name, const std::string &reference_string);
/// <summary>
///
/// </summary>
void create_named_range(const std::string &name, const range_reference &reference);
/// <summary>
///
/// </summary>
bool has_named_range(const std::string &name);
/// <summary>
///
/// </summary>
class range named_range(const std::string &name);
/// <summary>
///
/// </summary>
void remove_named_range(const std::string &name);
// extents
/// <summary>
///
/// </summary>
row_t lowest_row() const;
/// <summary>
///
/// </summary>
row_t highest_row() const;
/// <summary>
///
/// </summary>
row_t next_row() const;
/// <summary>
///
/// </summary>
column_t lowest_column() const;
/// <summary>
///
/// </summary>
column_t highest_column() const;
/// <summary>
///
/// </summary>
range_reference calculate_dimension() const;
// cell merge
/// <summary>
///
/// </summary>
void merge_cells(const std::string &reference_string);
/// <summary>
///
/// </summary>
void merge_cells(const range_reference &reference);
/// <summary>
///
/// </summary>
void merge_cells(column_t start_column, row_t start_row, column_t end_column, row_t end_row);
/// <summary>
///
/// </summary>
void unmerge_cells(const std::string &reference_string);
/// <summary>
///
/// </summary>
void unmerge_cells(const range_reference &reference);
/// <summary>
///
/// </summary>
void unmerge_cells(column_t start_column, row_t start_row, column_t end_column, row_t end_row);
/// <summary>
///
/// </summary>
std::vector<range_reference> merged_ranges() const;
// append
/// <summary>
///
/// </summary>
void append();
/// <summary>
///
/// </summary>
void append(const std::vector<std::string> &cells);
/// <summary>
///
/// </summary>
void append(const std::vector<int> &cells);
/// <summary>
///
/// </summary>
void append(const std::unordered_map<std::string, std::string> &cells);
/// <summary>
///
/// </summary>
void append(const std::unordered_map<int, std::string> &cells);
/// <summary>
///
/// </summary>
void append(const std::vector<int>::const_iterator begin, const std::vector<int>::const_iterator end);
// operators
/// <summary>
///
/// </summary>
bool operator==(const worksheet &other) const;
/// <summary>
///
/// </summary>
bool operator!=(const worksheet &other) const;
/// <summary>
///
/// </summary>
bool operator==(std::nullptr_t) const;
/// <summary>
///
/// </summary>
bool operator!=(std::nullptr_t) const;
/// <summary>
///
/// </summary>
void operator=(const worksheet &other);
/// <summary>
///
/// </summary>
class cell operator[](const cell_reference &reference);
/// <summary>
///
/// </summary>
const class cell operator[](const cell_reference &reference) const;
/// <summary>
///
/// </summary>
class range operator[](const range_reference &reference);
/// <summary>
///
/// </summary>
const class range operator[](const range_reference &reference) const;
/// <summary>
///
/// </summary>
class range operator[](const std::string &range_string);
/// <summary>
///
/// </summary>
const class range operator[](const std::string &range_string) const;
/// <summary>
///
/// </summary>
class range operator()(const cell_reference &top_left, const cell_reference &bottom_right);
/// <summary>
///
/// </summary>
const class range operator()(const cell_reference &top_left, const cell_reference &bottom_right) const;
/// <summary>
///
/// </summary>
bool compare(const worksheet &other, bool reference) const;
// page
/// <summary>
///
/// </summary>
bool has_page_setup() const;
/// <summary>
///
/// </summary>
xlnt::page_setup page_setup() const;
/// <summary>
///
/// </summary>
void page_setup(const struct page_setup &setup);
/// <summary>
///
/// </summary>
bool has_page_margins() const;
/// <summary>
///
/// </summary>
xlnt::page_margins page_margins() const;
/// <summary>
///
/// </summary>
void page_margins(const class page_margins &margins);
// auto filter
/// <summary>
///
/// </summary>
range_reference auto_filter() const;
/// <summary>
///
/// </summary>
void auto_filter(const std::string &range_string);
/// <summary>
///
/// </summary>
void auto_filter(const xlnt::range &range);
/// <summary>
///
/// </summary>
void auto_filter(const range_reference &reference);
/// <summary>
///
/// </summary>
void clear_auto_filter();
/// <summary>
///
/// </summary>
bool has_auto_filter() const;
/// <summary>
///
/// </summary>
void reserve(std::size_t n);
/// <summary>
///
/// </summary>
bool has_header_footer() const;
/// <summary>
///
/// </summary>
class header_footer header_footer() const;
/// <summary>
///
/// </summary>
void header_footer(const class header_footer &new_header_footer);
/// <summary>
///
/// </summary>
void parent(class workbook &wb);
/// <summary>
///
/// </summary>
std::vector<std::string> formula_attributes() const;
/// <summary>
///
/// </summary>
xlnt::sheet_state sheet_state() const;
/// <summary>
///
/// </summary>
void sheet_state(xlnt::sheet_state state);
/// <summary>
///
/// </summary>
iterator begin();
/// <summary>
///
/// </summary>
iterator end();
/// <summary>
///
/// </summary>
const_iterator begin() const;
/// <summary>
///
/// </summary>
const_iterator end() const;
/// <summary>
///
/// </summary>
const_iterator cbegin() const;
/// <summary>
///
/// </summary>
const_iterator cend() const;
/// <summary>
///
/// </summary>
class range iter_cells(bool skip_null);
/// <summary>
///
/// </summary>
void print_title_rows(row_t first_row, row_t last_row);
/// <summary>
///
/// </summary>
void print_title_rows(row_t last_row);
/// <summary>
///
/// </summary>
void print_title_cols(column_t first_column, column_t last_column);
/// <summary>
///
/// </summary>
void print_title_cols(column_t last_column);
/// <summary>
///
/// </summary>
std::string print_titles() const;
/// <summary>
///
/// </summary>
void print_area(const std::string &print_area);
/// <summary>
///
/// </summary>
range_reference print_area() const;
/// <summary>
///
/// </summary>
bool has_view() const;
/// <summary>
///
/// </summary>
sheet_view view(std::size_t index = 0) const;
/// <summary>
///
/// </summary>
void add_view(const sheet_view &new_view);
// page breaks
/// <summary>
/// Remove all manual column and row page breaks (represented as dashed
/// blue lines in the page view in Excel).
/// </summary>
void clear_page_breaks();
/// <summary>
/// Returns vector where each element represents a row which will break a page below it.
/// </summary>
const std::vector<row_t> &page_break_rows() const;
/// <summary>
/// Add a page break at the given row.
/// </summary>
void page_break_at_row(row_t row);
/// <summary>
/// Returns vector where each element represents a column which will break a page to the right.
/// </summary>
const std::vector<column_t> &page_break_columns() const;
/// <summary>
/// Add a page break at the given column.
/// </summary>
void page_break_at_column(column_t column);
private:
friend class cell;
friend class const_range_iterator;
friend class range_iterator;
friend class workbook;
friend class detail::xlsx_consumer;
friend class detail::xlsx_producer;
/// <summary>
///
/// </summary>
void register_comments_in_manifest();
/// <summary>
///
/// </summary>
worksheet(detail::worksheet_impl *d);
/// <summary>
///
/// </summary>
detail::worksheet_impl *d_;
};
} // namespace xlnt