forked from nissl-lab/npoi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXSSFSheet.cs
More file actions
6652 lines (5927 loc) · 236 KB
/
XSSFSheet.cs
File metadata and controls
6652 lines (5927 loc) · 236 KB
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
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for Additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
using NPOI.HSSF.Util;
using NPOI.OpenXml4Net.Exceptions;
using NPOI.OpenXml4Net.OPC;
using NPOI.OpenXmlFormats.Dml.Spreadsheet;
using NPOI.OpenXmlFormats.Spreadsheet;
using NPOI.POIFS.Crypt;
using NPOI.SS;
using NPOI.SS.Formula;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using NPOI.Util;
using NPOI.XSSF.Model;
using NPOI.XSSF.UserModel.Helpers;
using SixLabors.Fonts;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Cysharp.Text;
using System.Xml;
using CT_Shape = NPOI.OpenXmlFormats.Vml.CT_Shape;
using ST_EditAs = NPOI.OpenXmlFormats.Dml.Spreadsheet.ST_EditAs;
using System.Xml.Linq;
using System.Diagnostics;
namespace NPOI.XSSF.UserModel
{
/// <summary>
/// High level representation of a SpreadsheetML worksheet. Sheets are the
/// central structures within a workbook, and are where a user does most of
/// his spreadsheet work. The most common type of sheet is the worksheet,
/// which is represented as a grid of cells.Worksheet cells can contain
/// text, numbers, dates, and formulas. Cells can also be formatted.
/// </summary>
public partial class XSSFSheet : POIXMLDocumentPart, ISheet
{
private static readonly POILogger logger = POILogFactory.GetLogger(typeof(XSSFSheet));
private static readonly double DEFAULT_ROW_HEIGHT = 15.0;
private static readonly double DEFAULT_MARGIN_HEADER = 0.3;
private static readonly double DEFAULT_MARGIN_FOOTER = 0.3;
private static readonly double DEFAULT_MARGIN_TOP = 0.75;
private static readonly double DEFAULT_MARGIN_BOTTOM = 0.75;
private static readonly double DEFAULT_MARGIN_LEFT = 0.7;
private static readonly double DEFAULT_MARGIN_RIGHT = 0.7;
public static int TWIPS_PER_POINT = 20;
//TODO make the two variable below private!
internal CT_Sheet sheet;
internal CT_Worksheet worksheet;
private readonly SortedList<int, XSSFRow> _rows = new SortedList<int, XSSFRow>();
private readonly SortedList<int, XSSFColumn> _columns = new SortedList<int, XSSFColumn>();
private List<XSSFHyperlink> hyperlinks;
private ColumnHelper columnHelper;
private CommentsTable sheetComments;
/// <summary>
/// cache of master shared formulas in this sheet. Master shared
/// formula is the first formula in a group of shared formulas is saved
/// in the f element.
/// </summary>
private Dictionary<int, CT_CellFormula> sharedFormulas;
private Dictionary<string, XSSFTable> tables;
private List<CellRangeAddress> arrayFormulas;
private readonly XSSFDataValidationHelper dataValidationHelper;
private XSSFDrawing drawing = null;
private CT_Pane Pane
{
get
{
if(GetDefaultSheetView().pane == null)
{
GetDefaultSheetView().AddNewPane();
}
return GetDefaultSheetView().pane;
}
}
#region Public properties
/// <summary>
/// Returns the parent XSSFWorkbook
/// </summary>
public IWorkbook Workbook
{
get
{
return (XSSFWorkbook) GetParent();
}
}
/// <summary>
/// Returns the name of this sheet
/// </summary>
public string SheetName
{
get
{
return sheet.name;
}
}
/// <summary>
/// Vertical page break information used for print layout view, page
/// layout view, drawing print breaksin normal view, and for printing
/// the worksheet.
/// </summary>
// YK: GetXYZArray() array accessors are deprecated in xmlbeans with
// JDK 1.5 support
public int[] ColumnBreaks
{
get
{
if(!worksheet.IsSetColBreaks() || worksheet.colBreaks.sizeOfBrkArray() == 0)
{
return [];
}
List<CT_Break> brkArray = worksheet.colBreaks.brk;
int[] breaks = new int[brkArray.Count];
for(int i = 0; i < brkArray.Count; i++)
{
CT_Break brk = brkArray[i];
breaks[i] = (int) brk.id - 1;
}
return breaks;
}
}
/// <summary>
/// Get the default column width for the sheet (if the columns do not
/// define their own width) in characters.
/// </summary>
public double DefaultColumnWidth
{
get
{
CT_SheetFormatPr pr = worksheet.sheetFormatPr;
return (pr == null || pr.defaultColWidth == 0.0) ? 8.43 : pr.defaultColWidth;
}
set
{
var pr = GetSheetTypeSheetFormatPr();
pr.defaultColWidth = value;
pr.baseColWidth = 0;
}
}
/// <summary>
/// Get the default row height for the sheet (if the rows do not define
/// their own height) in twips(1/20 of a point)
/// </summary>
public short DefaultRowHeight
{
get
{
return (short) ((decimal) DefaultRowHeightInPoints * TWIPS_PER_POINT);
}
set
{
DefaultRowHeightInPoints = (float) value / TWIPS_PER_POINT;
}
}
/// <summary>
/// Get the default row height for the sheet measued in point size
/// (if the rows do not define their own height).
/// </summary>
public float DefaultRowHeightInPoints
{
get
{
CT_SheetFormatPr pr = worksheet.sheetFormatPr;
return (float) (pr == null ? 0 : pr.defaultRowHeight);
}
set
{
CT_SheetFormatPr pr = GetSheetTypeSheetFormatPr();
pr.defaultRowHeight = value;
pr.customHeight = true;
}
}
/// <summary>
/// Whether the text is displayed in right-to-left mode in the window
/// </summary>
public bool RightToLeft
{
get
{
CT_SheetView view = GetDefaultSheetView();
return view != null && view.rightToLeft;
}
set
{
CT_SheetView view = GetDefaultSheetView();
view.rightToLeft = value;
}
}
/// <summary>
/// Get whether to display the guts or not, default value is true
/// </summary>
public bool DisplayGuts
{
get
{
CT_SheetPr sheetPr = GetSheetTypeSheetPr();
CT_OutlinePr outlinePr = sheetPr.outlinePr ?? new CT_OutlinePr();
return outlinePr.showOutlineSymbols;
}
set
{
CT_SheetPr sheetPr = GetSheetTypeSheetPr();
CT_OutlinePr outlinePr = sheetPr.outlinePr ?? sheetPr.AddNewOutlinePr();
outlinePr.showOutlineSymbols = value;
}
}
/// <summary>
/// Gets the flag indicating whether the window should show 0 (zero)
/// in cells Containing zero value. When false, cells with zero value
/// appear blank instead of Showing the number zero.
/// </summary>
public bool DisplayZeros
{
get
{
CT_SheetView view = GetDefaultSheetView();
return view == null || view.showZeros;
}
set
{
CT_SheetView view = GetSheetTypeSheetView();
view.showZeros = value;
}
}
/// <summary>
/// Gets the first row on the sheet
/// </summary>
public int FirstRowNum
{
get
{
if(_rows.Count == 0)
{
return 0;
}
else
{
foreach(int key in _rows.Keys)
{
return key;
}
throw new ArgumentOutOfRangeException();
}
}
}
/// <summary>
/// Gets the first column on the sheet
/// </summary>
public int FirstColumnNum
{
get
{
if(_columns.Count == 0)
{
return 0;
}
else
{
foreach(int key in _columns.Keys)
{
return key;
}
throw new ArgumentOutOfRangeException();
}
}
}
/// <summary>
/// Flag indicating whether the Fit to Page print option is enabled.
/// </summary>
public bool FitToPage
{
get
{
CT_SheetPr sheetPr = GetSheetTypeSheetPr();
CT_PageSetUpPr psSetup = (sheetPr == null || !sheetPr.IsSetPageSetUpPr())
? new CT_PageSetUpPr()
: sheetPr.pageSetUpPr;
return psSetup.fitToPage;
}
set
{
GetSheetTypePageSetUpPr().fitToPage = value;
}
}
/// <summary>
/// Returns the default footer for the sheet, creating one as needed.
/// You may also want to look at <see cref="FirstFooter"/>,
/// <see cref="OddFooter"/> and <see cref="EvenFooter"/>
/// </summary>
public IFooter Footer
{
get
{
// The default footer is an odd footer
return OddFooter;
}
}
/// <summary>
/// Returns the default header for the sheet, creating one as needed.
/// You may also want to look at <see cref="FirstFooter"/>,
/// <see cref="OddFooter"/> and <see cref="EvenFooter"/>
/// </summary>
public IHeader Header
{
get
{
// The default header is an odd header
return OddHeader;
}
}
/// <summary>
/// Returns the odd footer. Used on all pages unless other footers
/// also present, when used on only odd pages.
/// </summary>
public IFooter OddFooter
{
get
{
return new XSSFOddFooter(GetSheetTypeHeaderFooter());
}
}
/// <summary>
/// Returns the even footer. Not there by default, but when Set,
/// used on even pages.
/// </summary>
public IFooter EvenFooter
{
get
{
return new XSSFEvenFooter(GetSheetTypeHeaderFooter());
}
}
/// <summary>
/// Returns the first page footer. Not there by default, but when
/// Set, used on the first page.
/// </summary>
public IFooter FirstFooter
{
get
{
return new XSSFFirstFooter(GetSheetTypeHeaderFooter());
}
}
/// <summary>
/// Returns the odd header. Used on all pages unless other headers
/// also present, when used on only odd pages.
/// </summary>
public IHeader OddHeader
{
get
{
return new XSSFOddHeader(GetSheetTypeHeaderFooter());
}
}
/// <summary>
/// Returns the even header. Not there by default, but when
/// Set, used on even pages.
/// </summary>
public IHeader EvenHeader
{
get
{
return new XSSFEvenHeader(GetSheetTypeHeaderFooter());
}
}
/// <summary>
/// Returns the first page header. Not there by default, but when
/// Set, used on the first page.
/// </summary>
public IHeader FirstHeader
{
get
{
return new XSSFFirstHeader(GetSheetTypeHeaderFooter());
}
}
/// <summary>
/// Determine whether printed output for this sheet will be
/// horizontally centered.
/// </summary>
public bool HorizontallyCenter
{
get
{
CT_PrintOptions opts = worksheet.printOptions;
return opts != null && opts.horizontalCentered;
}
set
{
CT_PrintOptions opts = worksheet.IsSetPrintOptions()
? worksheet.printOptions
: worksheet.AddNewPrintOptions();
opts.horizontalCentered = value;
}
}
public int LastRowNum
{
get
{
return _rows.Count == 0 ? 0 : XSSFSheet.GetLastKey(_rows.Keys);
}
}
public int LastColumnNum
{
get
{
return _columns.Count == 0 ? 0 : XSSFSheet.GetLastKey(_columns.Keys);
}
}
/// <summary>
/// Returns the list of merged regions. If you want multiple regions,
/// this is faster than calling {@link #getMergedRegion(int)} each time.
/// </summary>
public List<CellRangeAddress> MergedRegions
{
get
{
List<CellRangeAddress> addresses = new List<CellRangeAddress>();
CT_MergeCells ctMergeCells = worksheet.mergeCells;
if(ctMergeCells == null)
{
return addresses;
}
foreach(CT_MergeCell ctMergeCell in ctMergeCells.mergeCell)
{
string ref1 = ctMergeCell.@ref;
addresses.Add(CellRangeAddress.ValueOf(ref1));
}
return addresses;
}
}
/// <summary>
/// Returns the number of merged regions defined in this worksheet
/// </summary>
public int NumMergedRegions
{
get
{
CT_MergeCells ctMergeCells = worksheet.mergeCells;
return ctMergeCells != null
? ctMergeCells.sizeOfMergeCellArray()
: 0;
}
}
public int NumHyperlinks
{
get
{
return hyperlinks.Count;
}
}
/// <summary>
/// Returns the information regarding the currently configured pane
/// (split or freeze).
/// </summary>
public PaneInformation PaneInformation
{
get
{
CT_Pane pane = GetDefaultSheetView().pane;
// no pane configured
if(pane == null)
{
return null;
}
CellReference cellRef = pane.IsSetTopLeftCell() ? new CellReference(pane.topLeftCell) : null;
return new PaneInformation((short) pane.xSplit,
(short) pane.ySplit,
cellRef == null
? (short) 0
: (short) cellRef.Row,
cellRef == null
? (short) 0
: cellRef.Col,
(byte) pane.activePane,
pane.state == ST_PaneState.frozen);
}
}
/// <summary>
/// Returns the number of phsyically defined rows (NOT the number of
/// rows in the sheet)
/// </summary>
public int PhysicalNumberOfRows
{
get
{
return _rows.Count;
}
}
/// <summary>
/// Returns the number of phsyically defined columns (NOT the number of
/// columns in the sheet)
/// </summary>
public int PhysicalNumberOfColumns
{
get
{
return _columns.Count;
}
}
/// <summary>
/// Gets the print Setup object.
/// </summary>
public IPrintSetup PrintSetup
{
get
{
return new XSSFPrintSetup(worksheet);
}
}
/// <summary>
/// Answer whether protection is enabled or disabled
/// </summary>
public bool Protect
{
get
{
return IsSheetLocked;
}
}
/// <summary>
/// Horizontal page break information used for print layout view, page
/// layout view, drawing print breaks in normal view, and for printing
/// the worksheet.
/// </summary>
//YK: GetXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support
public int[] RowBreaks
{
get
{
if(!worksheet.IsSetRowBreaks() || worksheet.rowBreaks.sizeOfBrkArray() == 0)
{
return [];
}
List<CT_Break> brkArray = worksheet.rowBreaks.brk;
int[] breaks = new int[brkArray.Count];
for(int i = 0; i < brkArray.Count; i++)
{
CT_Break brk = brkArray[i];
breaks[i] = (int) brk.id - 1;
}
return breaks;
}
}
/// <summary>
/// Flag indicating whether summary rows appear below detail in an
/// outline, when Applying an outline. When true a summary row is
/// inserted below the detailed data being summarized and a new outline
/// level is established on that row. When false a summary row is
/// inserted above the detailed data being summarized and a new outline
/// level is established on that row.
/// </summary>
public bool RowSumsBelow
{
get
{
CT_SheetPr sheetPr = worksheet.sheetPr;
CT_OutlinePr outlinePr = (sheetPr != null && sheetPr.IsSetOutlinePr())
? sheetPr.outlinePr
: null;
return outlinePr == null || outlinePr.summaryBelow;
}
set
{
EnsureOutlinePr().summaryBelow = value;
}
}
/// <summary>
/// When true a summary column is inserted to the right of the detailed
/// data being summarized and a new outline level is established on
/// that column. When false a summary column is inserted to the left of
/// the detailed data being summarized and a new outline level is
/// established on that column.
/// </summary>
public bool RowSumsRight
{
get
{
CT_SheetPr sheetPr = worksheet.sheetPr;
CT_OutlinePr outlinePr = (sheetPr != null && sheetPr.IsSetOutlinePr())
? sheetPr.outlinePr
: new CT_OutlinePr();
return outlinePr.summaryRight;
}
set
{
EnsureOutlinePr().summaryRight = value;
}
}
/// <summary>
/// A flag indicating whether scenarios are locked when the sheet
/// is protected.
/// </summary>
public bool ScenarioProtect
{
get
{
return worksheet.IsSetSheetProtection()
&& worksheet.sheetProtection.scenarios;
}
}
public short LeftCol
{
get
{
string cellRef = GetPane().topLeftCell;
if(cellRef == null)
{
return 0;
}
CellReference cellReference = new CellReference(cellRef);
return cellReference.Col;
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
/// The top row in the visible view when the sheet is first viewed
/// after opening it in a viewer
/// </summary>
public short TopRow
{
get
{
string cellRef = GetSheetTypeSheetView().topLeftCell;
if(cellRef == null)
{
return 0;
}
CellReference cellReference = new CellReference(cellRef);
return (short) cellReference.Row;
}
set
{
GetSheetTypeSheetView().topLeftCell = "A" + value.ToString();
}
}
/// <summary>
/// Determine whether printed output for this sheet will be vertically
/// centered.
/// </summary>
public bool VerticallyCenter
{
get
{
CT_PrintOptions opts = worksheet.printOptions;
return opts != null && opts.verticalCentered;
}
set
{
CT_PrintOptions opts = worksheet.IsSetPrintOptions()
? worksheet.printOptions
: worksheet.AddNewPrintOptions();
opts.verticalCentered = value;
}
}
/// <summary>
/// Gets the flag indicating whether this sheet should display formulas.
/// </summary>
public bool DisplayFormulas
{
get
{
return GetSheetTypeSheetView().showFormulas;
}
set
{
GetSheetTypeSheetView().showFormulas = value;
}
}
/// <summary>
/// Gets the flag indicating whether this sheet displays the lines
/// between rows and columns to make editing and Reading easier.
/// </summary>
public bool DisplayGridlines
{
get
{
return GetSheetTypeSheetView().showGridLines;
}
set
{
GetSheetTypeSheetView().showGridLines = value;
}
}
/// <summary>
/// Gets the flag indicating whether this sheet should display row and
/// column headings. Row heading are the row numbers to the side of the
/// sheet Column heading are the letters or numbers that appear above
/// the columns of the sheet
/// </summary>
public bool DisplayRowColHeadings
{
get
{
return GetSheetTypeSheetView().showRowColHeaders;
}
set
{
GetSheetTypeSheetView().showRowColHeaders = value;
}
}
/// <summary>
/// Returns whether gridlines are printed.
/// </summary>
public bool IsPrintGridlines
{
get
{
CT_PrintOptions opts = worksheet.printOptions;
return opts != null && opts.gridLines;
}
set
{
CT_PrintOptions opts = worksheet.IsSetPrintOptions()
? worksheet.printOptions
: worksheet.AddNewPrintOptions();
opts.gridLines = value;
}
}
/// <summary>
/// Returns whether row and column headings are printed.
/// </summary>
public bool IsPrintRowAndColumnHeadings
{
get
{
CT_PrintOptions opts = worksheet.printOptions;
return opts != null && opts.headings;
}
set
{
CT_PrintOptions opts = worksheet.IsSetPrintOptions()
? worksheet.printOptions
: worksheet.AddNewPrintOptions();
opts.headings = value;
}
}
/// <summary>
/// Whether Excel will be asked to recalculate all formulas when the
/// workbook is opened.
/// </summary>
public bool ForceFormulaRecalculation
{
get
{
if(worksheet.IsSetSheetCalcPr())
{
CT_SheetCalcPr calc = worksheet.sheetCalcPr;
return calc.fullCalcOnLoad;
}
return false;
}
set
{
CT_CalcPr calcPr = (Workbook as XSSFWorkbook).GetCTWorkbook().calcPr;
if(worksheet.IsSetSheetCalcPr())
{
// Change the current Setting
CT_SheetCalcPr calc = worksheet.sheetCalcPr;
calc.fullCalcOnLoad = value;
}
else if(value)
{
// Add the Calc block and set it
CT_SheetCalcPr calc = worksheet.AddNewSheetCalcPr();
calc.fullCalcOnLoad = value;
}
if(value && calcPr != null
&& calcPr.calcMode == ST_CalcMode.manual)
{
calcPr.calcMode = ST_CalcMode.auto;
}
}
}
/// <summary>
/// Flag indicating whether the sheet displays Automatic Page Breaks.
/// </summary>
public bool Autobreaks
{
get
{
CT_SheetPr sheetPr = GetSheetTypeSheetPr();
CT_PageSetUpPr psSetup = (sheetPr == null || !sheetPr.IsSetPageSetUpPr())
? new CT_PageSetUpPr()
: sheetPr.pageSetUpPr;
return psSetup.autoPageBreaks;
}
set
{
CT_SheetPr sheetPr = GetSheetTypeSheetPr();
CT_PageSetUpPr psSetup = sheetPr.IsSetPageSetUpPr()
? sheetPr.pageSetUpPr
: sheetPr.AddNewPageSetUpPr();
psSetup.autoPageBreaks = value;
}
}
/// <summary>
/// Returns a flag indicating whether this sheet is selected.
/// <para>
/// When only 1 sheet is selected and active, this value should be in
/// synch with the activeTab value. In case of a conflict, the Start
/// Part Setting wins and Sets the active sheet tab.
/// </para>
/// Note: multiple sheets can be selected, but only one sheet can be
/// active at one time.
/// </summary>
public bool IsSelected
{
get
{
CT_SheetView view = GetDefaultSheetView();
return view != null && view.tabSelected;
}
set
{
CT_SheetViews views = GetSheetTypeSheetViews();
foreach(CT_SheetView view in views.sheetView)
{
view.tabSelected = value;
}
}
}
/// <summary>
/// Return location of the active cell, e.g. <code>A1</code>.
/// </summary>
public CellAddress ActiveCell
{
get
{
string address = GetSheetTypeSelection().activeCell;
if(address == null)
{
return null;
}
return new CellAddress(address);
}
set
{
string ref1 = value.FormatAsString();
CT_Selection ctsel = GetSheetTypeSelection();
ctsel.activeCell = ref1;
ctsel.SetSqref(new string[] { ref1 });
}
}
/// <summary>
/// Does this sheet have any comments on it? We need to know, so we can
/// decide about writing it to disk or not
/// </summary>
public bool HasComments
{
get
{
if(sheetComments == null)
{
return false;
}
return sheetComments.NumberOfComments > 0;
}
}
internal int NumberOfComments
{
get
{
if(sheetComments == null)
{
return 0;
}
return sheetComments.NumberOfComments;
}
}
/// <summary>
/// true when Autofilters are locked and the sheet is protected.
/// </summary>
public bool IsAutoFilterLocked
{
get
{
return IsSheetLocked && SafeGetProtectionField().autoFilter;
}
}
/// <summary>
/// true when Deleting columns is locked and the sheet is protected.
/// </summary>
public bool IsDeleteColumnsLocked
{
get
{
return IsSheetLocked && SafeGetProtectionField().deleteColumns;
}
}
/// <summary>
/// true when Deleting rows is locked and the sheet is protected.
/// </summary>
public bool IsDeleteRowsLocked
{
get
{
return IsSheetLocked && SafeGetProtectionField().deleteRows;
}