forked from Konctantin/Excel4Delphi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExcel4Delphi.pas
7270 lines (6562 loc) · 218 KB
/
Excel4Delphi.pas
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
unit Excel4Delphi;
interface
uses
{$IFDEF MSWINDOWS}
Winapi.Windows,
{$ENDIF}
System.Classes,
System.SysUtils,
{$IFDEF FMX}
FMX.Graphics,
{$ELSE}
Vcl.Graphics,
{$ENDIF}
System.StrUtils,
System.UITypes,
System.Math,
System.RegularExpressions,
System.Generics.Collections,
System.Contnrs,
Excel4Delphi.Xml;
// 1 (topographical point) = 0.3528 mm
const _PointToMM: real = 0.3528;
type
/// <summary>
/// Data type of cell
/// </summary>
TZCellType = (ZENumber, ZEDateTime, ZEBoolean, ZEString, ZEError, ZEGeneral);
/// <summary>
/// Style lines of the cell border
/// </summary>
TZBorderType = (ZENone, ZEContinuous, ZEHair, ZEDot, ZEDash, ZEDashDot, ZEDashDotDot, ZESlantDashDot, ZEDouble);
/// <summary>
/// Horizontal alignment
/// </summary>
TZHorizontalAlignment = (ZHAutomatic, ZHLeft, ZHCenter, ZHRight, ZHFill, ZHJustify, ZHCenterAcrossSelection, ZHDistributed, ZHJustifyDistributed);
/// <summary>
/// Vertical alignment
/// </summary>
TZVerticalAlignment = (ZVAutomatic, ZVTop, ZVBottom, ZVCenter, ZVJustify, ZVDistributed, ZVJustifyDistributed);
/// <summary>
/// Fill pattern of the cell
/// </summary>
TZCellPattern = (
ZPNone, ZPSolid, ZPGray75, ZPGray50, ZPGray25, ZPGray125, ZPGray0625, ZPHorzStripe, ZPVertStripe,
ZPReverseDiagStripe, ZPDiagStripe, ZPDiagCross, ZPThickDiagCross, ZPThinHorzStripe, ZPThinVertStripe,
ZPThinReverseDiagStripe, ZPThinDiagStripe, ZPThinHorzCross, ZPThinDiagCross);
/// <summary>
/// Borders position.
/// </summary>
TZBordersPos = (bpLeft, bpTop, bpRight, bpBottom, bpDiagonalLeft, bpDiagonalRight);
/// <summary>
/// Vertical/horizontal split/freeze mode.
/// </summary>
TZSplitMode = (ZSplitNone, ZSplitFrozen, ZSplitSplit);
/// <summary>
/// View mode.
/// </summary>
TZViewMode = (zvmNormal, zvmPageBreakPreview);
/// <summary>
/// Visibility state of a sheet.
/// </summary>
TZSheetVisible = (svVisible, svHidden, svVeryHidden); //См. https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-xlsb/74cb1d22-b931-4bf8-997d-17517e2416e9
/// <summary>
/// An angle of the rotation (direction) for a text within a cell.
/// Nominative range is -90 .. +90, extended is -180 .. +180 (in degrees)
/// </summary>
TZCellTextRotate = -180 .. +359;
TMediaRec = record
FileName: string;
Content: TBytes;
end;
TProgressArgs = record
Current, Total: Integer;
end;
TExcelColor = record
Rgb: TColor;
Indexed: Byte;
Theme: Byte;
Tint: Single;
end;
TZSheet = class;
TZStyle = class;
TZFont = class;
TZWorkBook = class;
TExportOptions = class
Progress: TProc<TProgressArgs>;
ResetPageNumberOnEachSheet: Boolean;
BookmarkName: string;
end;
TZExport = class
protected
FWorkBook: TZWorkBook;
public
constructor Create(AWorkBook: TZWorkBook); virtual;
destructor Destroy(); override;
procedure ExportTo(AStream: TStream; ASheets: TArray<integer>; options: TExportOptions); virtual; abstract;
property WorkBook: TZWorkBook read FWorkBook;
end;
TRichString = class(TPersistent)
private
FText: string;
FFont: TZFont;
public
property Text: string read FText write FText;
property Font: TZFont read FFont write FFont;
constructor Create(); virtual;
destructor Destroy(); override;
procedure Assign(Source: TPersistent); override;
function GetHashCode(): integer; override;
end;
TRichText = class(TPersistent)
private
FList: TList<TRichString>;
public
constructor Create(); virtual;
destructor Destroy(); override;
procedure Assign(Source: TPersistent); override;
function GetHashCode(): integer; override;
property List: TList<TRichString> read FList;
class function FromText(text: string): TRichText;
function ToString(): string; override;
end;
TSharedStringBank = class
private
FStringDict: TDictionary<string, integer>;
FRichList: TObjectList<TRichText>;
public
constructor Create(); virtual;
destructor Destroy(); override;
function Add(value: string): integer; overload;
function Add(value: TRichText): integer; overload;
property List: TObjectList<TRichText> read FRichList;
end;
/// <summary>
/// Cell of spreadsheet.
/// </summary>
TZCell = class(TPersistent)
private
FRow, FCol: integer;
FFormula: string;
FData: string;
FCellType: TZCellType;
FCellStyle: integer;
FRichText: TRichText;
FSheet: TZSheet;
{$region 'to del'}
// эти поля нужно убирать
FHref: string;
FHRefScreenTip: string;
FComment: string;
FCommentAuthor: string;
FAlwaysShowComment: boolean; //default = false;
FShowComment: boolean; //default = false
{$endregion 'to del'}
procedure ApplyStyleValue(proc: TProc<TZStyle>);
function GetDataAsDouble: double;
procedure SetDataAsDouble(const Value: double);
procedure SetDataAsInteger(const Value: integer);
function GetDataAsInteger: integer;
function GetDataAsDateTime(): TDateTime;
procedure SetDataAsDateTime(const Value: TDateTime);
procedure SetDataAsString(const Value: string);
function GetStyle(): TZStyle;
function GetBgColor: TColor;
function GetBorderColor(num: TZBordersPos): TColor;
function GetBorderStyle(num: TZBordersPos): TZBorderType;
function GetBorderWidht(num: TZBordersPos): Byte;
function GetFontColor: TColor;
function GetFontSize: double;
function GetFontStyle: TFontStyles;
function GetHorizontalAlignment: TZHorizontalAlignment;
function GetIndentLevel(): integer;
function GetNumberFormat: string;
function GetRotate: TZCellTextRotate;
function GetVerticalAlignment: TZVerticalAlignment;
function GetVerticalText: Boolean;
function GetWrapText: Boolean;
procedure SetBgColor(const Value: TColor);
procedure SetBorderColor(num: TZBordersPos; const Value: TColor);
procedure SetBorderStyle(num: TZBordersPos; const Value: TZBorderType);
procedure SetBorderWidht(num: TZBordersPos; const Value: Byte);
procedure SetFontColor(const Value: TColor);
procedure SetFontSize(const Value: double);
procedure SetFontStyle(const Value: TFontStyles);
procedure SetHorizontalAlignment(const Value: TZHorizontalAlignment);
procedure SetIndentLevel(value: integer);
procedure SetNumberFormat(const Value: string);
procedure SetRotate(const Value: TZCellTextRotate);
procedure SetVerticalAlignment(const Value: TZVerticalAlignment);
procedure SetVerticalText(const Value: Boolean);
procedure SetWrapText(const Value: Boolean);
protected
constructor Create(ASheet: TZSheet; ACol, ARow: integer); virtual;
public
destructor Destroy(); override;
procedure Assign(Source: TPersistent); override;
/// <summary>
/// Clear cell data.
/// </summary>
procedure Clear();
/// <summary>
/// Current sheet.
/// </summary>
property Sheet: TZSheet read FSheet;
/// <summary>
/// Current cell column.
/// </summary>
property Col: integer read FCol;
/// <summary>
/// Current cell row.
/// </summary>
property Row: integer read FRow;
/// <summary>
/// Current cell style.
/// </summary>
property Style: TZStyle read GetStyle;
/// <summary>
/// Always show comment.
/// </summary>
property AlwaysShowComment: boolean read FAlwaysShowComment write FAlwaysShowComment default false;
/// <summary>
/// Comment text.
/// </summary>
property Comment: string read FComment write FComment;
/// <summary>
/// Author of comment.
/// </summary>
property CommentAuthor: string read FCommentAuthor write FCommentAuthor;
/// <summary>
/// Cell style number. <br />-1 by default.
/// </summary>
property CellStyle: integer read FCellStyle write FCellStyle default -1;
/// <summary>
/// Cell type. <br />ZEString by default.
/// </summary>
property CellType: TZCellType read FCellType write FCellType default ZEString;
/// <summary>
/// Specifies the value of this cell to show on screen.
/// </summary>
property Data: string read FData write FData;
/// <summary>
/// Formula in R1C1 style.
/// </summary>
property Formula: string read FFormula write FFormula;
/// <summary>
/// Specifies the URL to link this cell.
/// </summary>
property HRef: string read FHref write FHref;
/// <summary>
/// Displays the caption of URL to show on screen.
/// </summary>
property HRefScreenTip: string read FHRefScreenTip write FHRefScreenTip;
/// <summary>
/// Show comment. <br />False by default.
/// </summary>
property ShowComment: boolean read FShowComment write FShowComment default false;
/// <summary>
/// Rich formated text.
/// </summary>
property RichText: TRichText read FRichText write FRichText;
/// <summary>
/// Present cell data as double value
/// </summary>
property AsDouble: double read GetDataAsDouble write SetDataAsDouble;
/// <summary>
/// Present cell data as integer value
/// </summary>
property AsInteger: integer read GetDataAsInteger write SetDataAsInteger;
/// <summary>
/// Present cell data as TDateTime value
/// </summary>
property AsDateTime: TDateTime read GetDataAsDateTime write SetDataAsDateTime;
/// <summary>
/// Present cell data as string value
/// </summary>
property AsString: string read FData write SetDataAsString;
/// <summary>
/// Vertical content alignment
/// </summary>
property VerticalAlignment: TZVerticalAlignment read GetVerticalAlignment write SetVerticalAlignment;
/// <summary>
/// Horisontal content alignment
/// </summary>
property HorizontalAlignment: TZHorizontalAlignment read GetHorizontalAlignment write SetHorizontalAlignment;
/// <summary>
/// Indent level of cell value.
/// </summary>
property IndentLevel: integer read GetIndentLevel write SetIndentLevel;
/// <summary>
/// Background cell color
/// </summary>
property BgColor: TColor read GetBgColor write SetBgColor;
/// <summary>
/// Font color
/// </summary>
property FontColor: TColor read GetFontColor write SetFontColor;
/// <summary>
/// Font size
/// </summary>
property FontSize: double read GetFontSize write SetFontSize;
/// <summary>
/// Font style
/// </summary>
property FontStyle: TFontStyles read GetFontStyle write SetFontStyle;
/// <summary>
/// Border style
/// </summary>
property BorderStyle[num: TZBordersPos]: TZBorderType read GetBorderStyle write SetBorderStyle;
/// <summary>
/// Border width
/// </summary>
property BorderWidht[num: TZBordersPos]: Byte read GetBorderWidht write SetBorderWidht;
/// <summary>
/// Border color
/// </summary>
property BorderColor[num: TZBordersPos]: TColor read GetBorderColor write SetBorderColor;
/// <summary>
/// Word wrap
/// </summary>
property WrapText: Boolean read GetWrapText write SetWrapText;
/// <summary>
/// Vertical text
/// </summary>
property VerticalText: Boolean read GetVerticalText write SetVerticalText;
/// <summary>
/// Text rotation
/// </summary>
property Rotate: TZCellTextRotate read GetRotate write SetRotate;
/// <summary>
/// Number format
/// </summary>
property NumberFormat: string read GetNumberFormat write SetNumberFormat;
/// <summary>
/// Trying to convert probably number value and change cell type to number.
/// </summary>
procedure TryConvertToNumber();
/// <summary>
/// Trying to extract TDateTime value from cell content.
/// </summary>
function TryGetDate(const defaultValue: TDateTime = 0): TDateTime;
/// <summary>
/// Trying to extract integer value from cell content.
/// </summary>
function TryGetInteger(const defaultValue: Integer = 0): Integer;
/// <summary>
/// Trying to extract double value from cell content.
/// </summary>
function TryGetDouble(const defaultValue: Double = 0): Double;
/// <summary>
/// True if cell have no data.
/// </summary>
function IsEmpty(includeFormula: boolean = true): boolean;
/// <summary>
/// True if cell within merged cells.
/// </summary>
function IsMerged(): boolean;
/// <summary>
/// True if cell within merged cells and in left-top corner.
/// </summary>
function IsLeftTopMerged(): boolean;
/// <summary>
/// Return text from merged range.
/// </summary>
function GetMergedText(onlyFromTopCorner: boolean = true): string;
/// <summary>
/// Set borders around all cell's border.
/// </summary>
procedure SetBorderAround(borderWidth: Byte; borderColor: TColor = clBlack; borderStyle: TZBorderType = TZBorderType.ZEContinuous);
end;
/// <summary>
/// Border's style.
/// </summary>
TZBorderStyle = class (TPersistent)
private
FLineStyle: TZBorderType;
FWeight: byte;
FColor: TColor;
procedure SetLineStyle(const Value: TZBorderType);
procedure SetWeight(const Value: byte);
procedure SetColor(const Value: TColor);
public
constructor Create(); virtual;
procedure Assign(Source: TPersistent); override;
/// <returns>
/// True, when border equal to Source.
/// </returns>
function IsEqual(Source: TPersistent): boolean; virtual;
/// <summary>
/// Line style. <br />ZENone by default.
/// </summary>
property LineStyle: TZBorderType read FLineStyle write SetLineStyle default ZENone;
/// <summary>
/// Specifies the thickness of this border (0-3). <br />0 by default.
/// </summary>
property Weight: byte read FWeight write SetWeight default 0;
/// <summary>
/// Specifies the color of this border. <br />ClBlack by default.
/// </summary>
property Color: TColor read FColor write SetColor default ClBlack;
end;
/// <summary>
/// Borders of cell.
/// </summary>
TZBorder = class (TPersistent)
private
FBorder: array [0..5] of TZBorderStyle;
procedure SetBorder(Num: TZBordersPos; Const Value: TZBorderStyle);
function GetBorder(Num: TZBordersPos):TZBorderStyle;
public
constructor Create(); virtual;
destructor Destroy(); override;
procedure Assign(Source: TPersistent);override;
/// <summary>
/// Set border by border position.
/// </summary>
property Border[Num: TZBordersPos]: TZBorderStyle read GetBorder write SetBorder; default;
/// <returns>
/// True when borders equal Source.
/// </returns>
function IsEqual(Source: TPersistent): boolean; virtual;
/// <summary>
/// Left border.
/// </summary>
property Left: TZBorderStyle index bpLeft read GetBorder write SetBorder;
/// <summary>
/// Top border.
/// </summary>
property Top: TZBorderStyle index bpTop read GetBorder write SetBorder;
/// <summary>
/// Right border.
/// </summary>
property Right: TZBorderStyle index bpRight read GetBorder write SetBorder;
/// <summary>
/// Bottom border.
/// </summary>
property Bottom: TZBorderStyle index bpBottom read GetBorder write SetBorder;
/// <summary>
/// Diagonal from upper left to lower right.
/// </summary>
property DiagonalLeft : TZBorderStyle index bpDiagonalLeft read GetBorder write SetBorder;
/// <summary>
/// Diagonal from lower left to upper right.
/// </summary>
property DiagonalRight: TZBorderStyle index bpDiagonalRight read GetBorder write SetBorder;
end;
/// <summary>
/// Specifies how text is aligned within the cell.
/// </summary>
TZAlignment = class (TPersistent)
private
FHorizontal: TZHorizontalAlignment;
FVertical: TZVerticalAlignment;
FIndent: integer;
FRotate: TZCellTextRotate;
FWrapText: boolean;
FShrinkToFit: boolean; // true - уменьшает размер шрифта, чтобы текст поместился в ячейку,
// false - текст не уменьшается
FVerticalText: boolean; // true - текст по одной букве в строке вертикально
// false - по дефолту
procedure SetHorizontal(const Value: TZHorizontalAlignment);
procedure SetIndent(const Value: integer);
procedure SetRotate(const Value: TZCellTextRotate);
procedure SetShrinkToFit(const Value: boolean);
procedure SetVertical(const Value: TZVerticalAlignment);
procedure SetVerticalText(const Value: boolean);
procedure SetWrapText(const Value: boolean);
public
constructor Create(); virtual;
procedure Assign(Source: TPersistent); override;
/// <returns>
/// True when all properties equal to Source's properties.
/// </returns>
function IsEqual(Source: TPersistent): boolean; virtual;
/// <summary>
/// Specifies how text is aligned by horizontally within the cell.
/// </summary>
property Horizontal: TZHorizontalAlignment read FHorizontal write SetHorizontal default ZHAutomatic;
/// <summary>
/// Specifies how far the cell's text is indented.
/// </summary>
property Indent: integer read FIndent write SetIndent default 0;
/// <summary>
/// Specifies the rotation of the text within the cell (from -90 to 90).
/// </summary>
property Rotate: TZCellTextRotate read FRotate write SetRotate;
/// <summary>
/// If True then the text size will shrunk so to all of the text fits within the cell.
/// </summary>
property ShrinkToFit: boolean read FShrinkToFit write SetShrinkToFit default false;
/// <summary>
/// Specifies how text is aligned by vertically within the cell.
/// </summary>
property Vertical: TZVerticalAlignment read FVertical write SetVertical default ZVAutomatic;
/// <summary>
/// If True each letter is drawn horizontally, one above the other.
/// </summary>
property VerticalText: boolean read FVerticalText write SetVerticalText default false;
/// <summary>
/// Specifies whether the text in cell should wrap at the cell boundary.
/// </summary>
property WrapText: boolean read FWrapText write SetWrapText default false;
end;
/// <summary>
/// Excel Font - https://docs.microsoft.com/ru-ru/office/vba/api/excel.font(object)
/// </summary>
TZFont = class (TPersistent)
private
FColor: TColor;
FColorTheme: integer;
FSize: double;
FCharset: TFontCharset;
FFamily: byte;
FScheme: string;
FName: TFontName;
FStyle: TFontStyles;
FDoubleInderLine: boolean;
procedure SetColor(const Value: TColor);
public
constructor Create;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
procedure AssignTo(Dest: TPersistent); override;
function GetHashCode(): integer; override;
property Color: TColor read FColor write SetColor;
property Size: double read FSize write FSize;
property Charset: TFontCharset read FCharset write FCharset;
property ColorTheme: integer read FColorTheme write FColorTheme;
property Family: byte read FFamily write FFamily;
property Scheme: string read FScheme write FScheme;
property Name: TFontName read FName write FName;
property Style: TFontStyles read FStyle write FStyle;
property DoubleInderLine: boolean read FDoubleInderLine write FDoubleInderLine;
end;
/// <summary>
/// Cell style.
/// </summary>
TZStyle = class (TPersistent)
private
FBorder: TZBorder;
FAlignment: TZAlignment;
FFont: TZFont;
FBGColor: TColor;
FPatternColor: TColor;
FCellPattern: TZCellPattern;
FNumberFormatId: Integer;
FNumberFormat: string;
FProtect: boolean;
FHideFormula: boolean;
FSuperscript: boolean;
FSubscript: boolean;
procedure SetFont(const Value: TZFont);
procedure SetBorder(const Value: TZBorder);
procedure SetAlignment(const Value: TZAlignment);
procedure SetBGColor(const Value: TColor);
procedure SetPatternColor(const Value: TColor);
procedure SetCellPattern(const Value: TZCellPattern);
procedure SetSuperscript(const Value: boolean);
procedure SetSubscript(const Value: boolean);
protected
procedure SetNumberFormat(const Value: string); virtual;
public
constructor Create(); virtual;
destructor Destroy(); override;
procedure Assign(Source: TPersistent); override;
/// <summary>
/// True when style equal Source.
/// </summary>
function IsEqual(Source: TPersistent): boolean; virtual;
/// <summary>
/// Cell font.
/// </summary>
property Font: TZFont read FFont write SetFont;
/// <summary>
/// Cell borders.
/// </summary>
property Border: TZBorder read FBorder write SetBorder;
/// <summary>
/// Specifies how text is aligned within the cell.
/// </summary>
property Alignment: TZAlignment read FAlignment write SetAlignment;
/// <summary>
/// Background color of the cell. <br />clWindow by default.
/// </summary>
property BGColor: TColor read FBGColor write SetBGColor default clWindow;
/// <summary>
/// Color of fill pattern. <br />clWindow by default.
/// </summary>
property PatternColor: TColor read FPatternColor write SetPatternColor default clWindow;
/// <summary>
/// Indicates whether or not this cell is protected. <br />True by default.
/// </summary>
property Protect: boolean read FProtect write FProtect default true;
/// <summary>
/// Indicates whether or not this cell's formula should be hidden when sheet protection is enabled. <br />False by default.
/// </summary>
property HideFormula: boolean read FHideFormula write FHideFormula default false;
/// <summary>
/// Indicates whether or not the text is slightly above the baseline. <br />False by default.
/// </summary>
property Superscript: boolean read FSuperscript write SetSuperscript default false;
/// <summary>
/// Indicates whether or not the text is slightly below the baseline. <br />False by default.
/// </summary>
property Subscript: boolean read FSubscript write SetSubscript default false;
/// <summary>
/// Fill pattern of the cell. <br />ZPNone by default.
/// </summary>
property CellPattern: TZCellPattern read FCellPattern write SetCellPattern default ZPNone;
/// <summary>
/// Defines the number format that should be in cells referencing this style.
/// </summary>
property NumberFormat: string read FNumberFormat write SetNumberFormat;
property NumberFormatId: Integer read FNumberFormatId write FNumberFormatId default -1;
end;
/// <summary>
/// Contains styles of the document.
/// </summary>
TZStyles = class (TPersistent)
private
FDefaultStyle: TZStyle;
FStyles: array of TZStyle;
FCount: integer;
procedure SetDefaultStyle(const Value: TZStyle);
function GetStyle(num: integer): TZStyle;
procedure SetStyle(num: integer; const Value: TZStyle);
procedure SetCount(const Value: integer);
public
constructor Create(); virtual;
destructor Destroy(); override;
procedure Assign(Source: TPersistent); override;
/// <summary>
/// Add a Style.
/// </summary>
/// <param name="Style">
/// Style.
/// </param>
/// <param name="CheckMatch">
/// Checks the coincidence of this style with introduced in earlier styles.
/// <br />Return number of added (or, if CheckMatch = True, previously introduced) style.
/// </param>
function Add(const Style: TZStyle; CheckMatch: boolean = false): integer;
/// <summary>
/// Delete all styles.
/// </summary>
procedure Clear(); virtual;
/// <summary>
/// Delete style num, styles with a larger number are shifting.
/// </summary>
/// <param name="num">
/// Style number
/// </param>
/// <returns>
/// Return: 0 - if successfully deleted, -1 - can not delete style
/// </returns>
function DeleteStyle(num: integer):integer; virtual;
/// <summary>
/// Find number to match the Style introduced in earlier styles.
/// </summary>
/// <param name="Style">
/// Style.
/// </param>
/// <returns>
/// Return: -2 - if style not found, -1 - if style = DefaultStyle, 0..Count-1 - Style
/// </returns>
function Find(const Style: TZStyle): integer;
/// <summary>
/// Style num (-1 - DefaultStyle).
/// </summary>
property Items[num: integer]: TZStyle read GetStyle write SetStyle; default;
/// <summary>
/// Count styles in the document.
/// </summary>
property Count: integer read FCount write SetCount;
/// <summary>
/// Default style ( = Items[-1]).
/// </summary>
property DefaultStyle: TZStyle read FDefaultStyle write SetDefaultStyle;
end;
/// <summary>
/// Merged cells
/// </summary>
TZMergeCells = class
private
FSheet: TZSheet;
FCount: integer;
FMergeArea: Array of TRect;
function GetItem(Num: integer): TRect;
procedure SetItem(Num: integer; const rect: TRect);
public
constructor Create(ASheet: TZSheet); virtual;
destructor Destroy(); override;
/// <summary>
/// Adds a merged cell enclosed into rectangle.
/// </summary>
function AddRect(Rct:TRect): byte;
/// <summary>
/// Adds a merged cell enclosed into rectangle
/// </summary>
function AddRectXY(left,top,right,bottom: integer): byte;
/// <summary>
/// Delete merged cell num. <br />Return True if the cell is successfully deleted.
/// </summary>
function DeleteItem(num: integer): boolean;
/// <summary>
/// Returns the number of merged cell, in which the cell [ACol, ARow] is top left.
/// If returns a negative value - there is no such area.
/// </summary>
function InLeftTopCorner(ACol, ARow: integer): integer;
/// <summary>
/// Returns the number of merged cell that includes cell [ACol, ARow].
/// If returns a negative value - cell [ACol, ARow] is not contained in the Merged area.
/// </summary>
function InMergeRange(ACol, ARow: integer): integer;
/// <summary>
/// True if region cross with merged cells.
/// </summary>
function IsCrossWithArea(AID,AC1,AR1,AC2,AR2: integer): Boolean;
/// <summary>
/// Rows count in merged region.
/// </summary>
function MergedRows(ACol, ARow: integer): integer;
/// <summary>
/// Columns count in merged region.
/// </summary>
function MergedCols(ACol, ARow: integer): integer;
/// <summary>
/// Removes all merged cells.
/// </summary>
procedure Clear();
/// <summary>
/// Merged regions count.
/// </summary>
property Count: integer read FCount;
/// <summary>
/// Current merged region.
/// </summary>
property Items[Num: Integer]: TRect read GetItem write SetItem; default;
end;
TZCellColumn = array of TZCell;
/// <summary>
/// Common options for columns and rows. Ancestor for TZColOptions and TZRowOptions.
/// </summary>
TZRowColOptions = class(TPersistent)
private
FSheet: TZSheet;
FHidden: boolean;
FStyleID: integer;
FSize: real;
FAuto: boolean;
FBreaked: boolean;
FOutlineLevel: integer;
protected
function GetAuto(): boolean;
procedure SetAuto(Value: boolean);
function GetSizePoint(): real;
procedure SetSizePoint(Value: real);
function GetSizeMM(): real;
procedure SetSizeMM(Value: real);
function GetSizePix(): integer; virtual; abstract;
procedure SetSizePix(Value: integer); virtual; abstract;
public
constructor Create(ASheet: TZSheet); virtual;
procedure Assign(Source: TPersistent); override;
/// <summary>
/// True specifies that column or row is hidden.
/// </summary>
property Hidden: boolean read FHidden write FHidden default false;
/// <summary>
/// Specifies a style for column or row.
/// </summary>
property StyleID: integer read FStyleID write FStyleID default -1;
/// <summary>
/// Page break after column or row.
/// </summary>
property Breaked: boolean read FBreaked write FBreaked default false;
/// <summary>
/// Outlining level of the column/row, when outlining is on.
/// </summary>
property OutlineLevel: integer read FOutlineLevel write FOutlineLevel;
end;
/// <summary>
/// Column options.
/// </summary>
TZColOptions = class (TZRowColOptions)
protected
function GetSizePix(): integer; override;
procedure SetSizePix(Value: integer); override;
public
constructor Create(ASheet: TZSheet); override;
/// <summary>
/// If True, it means that this column should be autosized.
/// </summary>
property AutoFitWidth: boolean read GetAuto write SetAuto;
/// <summary>
/// Column width in points.
/// </summary>
property Width: real read GetSizePoint write SetSizePoint;
/// <summary>
/// Column width in mm.
/// </summary>
property WidthMM: real read GetSizeMM write SetSizeMM;
/// <summary>
/// Column width in pixels.
/// </summary>
property WidthPix: integer read GetSizePix write SetSizePix;
end;
/// <summary>
/// Row options.
/// </summary>
TZRowOptions = class (TZRowColOptions)
protected
function GetSizePix(): integer; override;
procedure SetSizePix(Value: integer); override;
public
constructor Create(ASheet: TZSheet); override;
/// <summary>
/// If True, it means that this row should be autosized.
/// </summary>
property AutoFitHeight: boolean read GetAuto write SetAuto;
/// <summary>
/// Row height in points (1 point = 1/72" = 0.3528 mm).
/// </summary>
property Height: real read GetSizePoint write SetSizePoint;
/// <summary>
/// Row height in mm.
/// </summary>
property HeightMM: real read GetSizeMM write SetSizeMM;
/// <summary>
/// Row height in pixels.
/// </summary>
property HeightPix: integer read GetSizePix write SetSizePix;
end;
/// <summary>
/// Repeating columns or rows when printing the sheet
/// </summary>
TZSheetPrintTitles = class(TPersistent)
private
FOwner: TZSheet;
FColumns: boolean;
FActive: boolean;
FTill: word;
FFrom: word;
procedure SetActive(const Value: boolean);
procedure SetFrom(const Value: word);
procedure SetTill(const Value: word);
function Valid(const AFrom, ATill: word): boolean;
procedure RequireValid(const AFrom, ATill: word);
public
procedure Assign(Source: TPersistent); override;
constructor Create(const owner: TZSheet; const ForColumns: boolean);
function ToString: string; override;
property From: word read FFrom write SetFrom;
property Till: word read FTill write SetTill;
property Active: boolean read FActive write SetActive;
end;
/// <summary>
/// Footer or header margins.
/// </summary>
TZHeaderFooterMargins = class (TPersistent)
private
FMarginTopBottom: word; //Bottom or top margin
FMarginLeft: word;
FMarginRight: word;
FHeight: word;
FUseAutoFitHeight: boolean; //If true then in LibreOffice Calc
//in window "Page style settings" on tabs "Header" or "Footer"
//check box "AutoFit height" will be checked.
public
constructor Create();
procedure Assign(Source: TPersistent); override;
function IsEqual(Source: TPersistent): boolean; virtual;
/// <summary>
/// Bottom / top margin of the footer / header in mm. <br />13 by default.
/// </summary>
property MarginTopBottom: word read FMarginTopBottom write FMarginTopBottom default 13;
/// <summary>
/// Left margin in mm. <br />0 by default.
/// </summary>
property MarginLeft: word read FMarginLeft write FMarginLeft default 0;
/// <summary>
/// Right margin in mm. <br />0 by default.
/// </summary>
property MarginRight: word read FMarginRight write FMarginRight default 0;
/// <summary>
/// Height of footer / header in mm. <br />7 by default.
/// </summary>
property Height: word read FHeight write FHeight default 7;
/// <summary>
/// Automatically fit height. <br />true by default.
/// </summary>
property UseAutoFitHeight: boolean read FUseAutoFitHeight write FUseAutoFitHeight default true;
end;
/// <summary>
/// Inherited from TPersistent. Sheet options.
/// </summary>
TZSheetOptions = class (TPersistent)
private
FActiveCol: word;
FActiveRow: word;
FMarginBottom: word;
FMarginLeft: word;
FMarginTop: word;
FMarginRight: word;
FHeaderMargins: TZHeaderFooterMargins;
FFooterMargins: TZHeaderFooterMargins;
FPortraitOrientation: boolean;
FCenterHorizontal: boolean;
FCenterVertical: boolean;
FStartPageNumber: integer;
FDifferentOddEven: Boolean;
FDifferentFirst: Boolean;
FHeader: string; //Header for all pages. When IsEvenFooterEqual = false - only for odd pages.
FFooter: string; //Footer for all pages. When IsEvenFooterEqual = false - only for odd pages.
FEvenHeader: string; //Header for even pages. Used only if IsEvenFooterEqual = false
FEvenFooter: string; //Footer for even pages. Used only if IsEvenFooterEqual = false
FFirstPageHeader: string;
FFirstPageFooter: string;
FHeaderBGColor: TColor;
FFooterBGColor: TColor;
FScaleToPercent: integer; //Document must be scaled to percentage value (100 - no scale)
FScaleToPages: integer; //Document scaled to fit a number of pages (1 - no scale)
FPaperSize: byte;
FPaperWidth: integer;
FPaperHeight: integer;
FPageOrderDown: boolean;
FFitToHeight: integer; //Number of vertical pages to fit on
FFitToWidth: integer; //Number of horizontal pages to fit on
FSplitVerticalMode: TZSplitMode;
FSplitHorizontalMode: TZSplitMode;
FSplitVerticalValue: integer; //Вроде можно вводить отрицательные
FSplitHorizontalValue: integer; //Измеряться будут:
// в пикселях, если SplitMode = ZSplitSplit
// в кол-ве строк/столбцов, если SplitMode = ZSplitFrozen
// Если SplitMode = ZSplitNone, то фиксация столбцов/ячеек не работает
function GetHeaderMargin(): word;
procedure SetHeaderMargin(Value: word);
function GetFooterMargin(): word;
procedure SetFooterMargin(Value: word);
public
constructor Create(); virtual;
destructor Destroy(); override;
procedure Assign(Source: TPersistent); override;
/// <summary>
/// Column number with active cell.
/// </summary>
property ActiveCol: word read FActiveCol write FActiveCol default 0;
/// <summary>
/// Row number with active cell.
/// </summary>
property ActiveRow: word read FActiveRow write FActiveRow default 0;
/// <summary>
/// Specifies the bottom margin on the page in millimeters.
/// </summary>
property MarginBottom: word read FMarginBottom write FMarginBottom default 25;
/// <summary>
/// Specifies the left margin on the page in millimeters 19mm (1.9sm) by default.
/// </summary>