Sign in Join
Wiki copytemporary

FPSpreadsheet/pl: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: FPSpreadsheet/pl

OldNewLine
1+> **Warning:** **Ta strona została przetłumaczona w dniu 2021-01-27 i może nie być aktualna. Dlatego skorzystaj także z witryny angielskiej**
2+
3+Biblioteka fpSpreadsheet oferuje wygodny sposób generowania i czytania arkuszy kalkulacyjnych w różnych formatach. Biblioteka jest napisana w bardzo elastyczny sposób, z możliwością łatwego rozszerzenia do obsługi dowolnej liczby formatów.
4+
5+Zrzut ekranu spready demo programu dostarczonego z fpspreadsheet przedstawiający plik XLS:
6+
7+> **Note:** **Możesz także pobrać program spready demo za pomocą komendy: svn checkout <http://svn.code.sf.net/p/lazarus-ccr/svn/applications/spready>**
8+
9+<figure>
10+<img src="fpsgrid.png" title="fpsgrid.png" />
11+<figcaption>fpsgrid.png</figcaption>
12+</figure>
13+
14+## Dokumentacja
15+
16+Ta strona wiki zawiera najnowszą wersję development/trunk FPSpreadsheet dostępną za pośrednictwem subversion. Zobacz sekcję Wersje stabilne aby zapoznać się z dokumentacją dotyczącą stabilnej wersji, którą możesz także pobrać.
17+
18+## API Documentation
19+
20+### Dokumentacja API
21+
22+Plik pomocy w formacie CHM można znaleźć w folderze *docs* pakietu instalacyjnego FPSpreadsheet. Jeśli jeszcze nie zainstalowałeś pakietu, wykonaj następujące czynności: [<http://svn.code.sf.net/p/lazarus-ccr/svn/components/fpspreadsheet/docs/fpspreadsheet-api.chm>](http://svn.code.sf.net/p/lazarus-ccr/svn/components/fpspreadsheet/docs/fpspreadsheet-api.chm) aby pobrać *fpspreadsheet-api.chm*.
23+
24+Drugi plik CHM dostępny w folderze *docs*, *fpspreadsheet-wiki.chm*, to migawka stron wiki związanych z FPSpreadsheet, spakowana w pojedynczy plik pomocy.
25+
26+### Podstawy
27+
28+Najmniejsze elementy w arkuszu kalkulacyjnym to **cells** (komórki) zawierające dane. Komórki mogą zawierać różne typy danych, takie jak ciągi, liczby, daty, godziny, wartości logiczne lub formuły. Ponadto komórki mogą zawierać informacje o formatowaniu, tj. Styl czcionki, kolor tła, wyrównanie tekstu itp.
29+
30+Komórki są ułożone w strukturę przypominającą siatkę, zwaną **worksheet** (arkuszem roboczym) lub **spreadsheet** (arkuszem kalkulacyjnym), składającą się z **rows** (wierszy) i **columns** (kolumn). Każda komórka ma unikalny adres podany w indeksie wiersza i kolumny.
31+
32+Arkusze są połączone w **workbook** (skoroszyt), który reprezentuje dokument aplikacji arkusza kalkulacyjnego. Skoroszyt przechowuje również informacje, które są potrzebne dla wszystkich arkuszy roboczych, tj. lista czcionek, listy formatu komórek i liczb itp.
33+
34+FPSpreadsheet ma tę samą strukturę - zawiera `TCell`, `TsWorksheet` i `TsWorkbook`.
35+
36+#### Skoroszyt
37+
38+Klasa `TsWorkbook` jest główną klasą widoczną dla użytkownika. Zapewnia metody odczytu danych i zapisywania do plików. Wszechstronna struktura biblioteki zapewnia dostęp do różnych popularnych formatów plików, takich jak Excel *.xls* lub *.xlsx*, a także OpenOffice/LibreOffice *.ods*.
39+
40+Format pliku jest określony przez typ `TsSpreadsheetFormat` zdefiniowany w module `fpstypes`
41+
42+``` pascal
43+type
44+ TsSpreadsheetFormat = (sfExcel2, sfExcel5, sfExcel8, sfExcelXML, sfOOXML,
45+ sfOpenDocument, sfCSV, sfHTML, sfWikiTable_Pipes, sfWikiTable_WikiMedia, sfUser);
46+```
47+
48+gdzie:
49+
50+- `sfExcel2`, `sfExcel5`, `sfExcel8` oznacza wersje binarnego formatu xls używanego przez program Excel („BIFF” = „Binary Interchange File Format”), przy czym `sfExcel8` jest najnowszym formatem.
51+
52+- `sfOOXML` odpowiada nowszemu formatowi xlsx wprowadzonemu przez Excel2007
53+- `sfExcelXML` to format xml, który został wprowadzony przez Microsoft w Office XP i 2003. Niezbyt popularny.
54+- `sfOpenDocument` to format arkusza kalkulacyjnego używany przez OpenOffice/LibreOffice; Domyślnie pliki mają rozszerzenie *.ods*.
55+- `sfCSV` odnosi się do plików tekstowych rozdzielanych przecinkami (domyślne rozszerzenie *.csv*); mogą one być czytelne dla dowolnego edytora tekstu i dla wszystkich arkuszy kalkulacyjnych, ale nie zawierają informacji o formatowaniu.
56+- `sfHTML` oznacza standardowy format HTML używany w przeglądarkach internetowych.
57+- `sfWikiTable_Pipes` i `sfWikiTable_WikiMedia` to format używany przez tabele w witrynach wiki.
58+- `sfUser` jest potrzebny do zarejestrowania formatu zdefiniowanego przez użytkownika. Nie ma planów wdrożenia „starych” formatów plików, takich jak Excel3.0/4.0 czy Lotus. Możliwe jest jednak utworzenie własnych klas czytania i pisania, aby rozszerzyć funkcjonalność FPSpreadsheet - zobacz sekcję poniżej o Dodawanie nowych formatów plików
59+
60+Podczas stosowania FPSpreadsheet pierwszym zadaniem jest utworzenie instancji skoroszytu:
61+
62+``` pascal
63+var
64+ MyWorkbook: TsWorkbook;
65+begin
66+ MyWorkbook := TsWorkbook.Create;
67+ ...
68+```
69+
70+Czytanie plików arkuszy kalkulacyjnych odbywa się (między innymi) metodami skoroszytowymi
71+
72+- `procedure ReadFromFile(AFileName: string):`\
73+ Czyta plik o podanej nazwie i automatycznie rozpoznaje poprawny format pliku.
74+- `procedure ReadFromFile(AFileName: string; AFormat: TsSpreadsheetFormat):`\
75+ Odczytuje plik, ale zakłada, że ​​format pliku jest określony przez `AFormat`.
76+
77+Do zapisywania do pliku można użyć następujących metod skoroszytu:
78+
79+- `procedure WriteToFile(const AFileName: string; const AFormat: TsSpreadsheetFormat; const AOverwriteExisting: Boolean = False)`:\
80+ Zapisuje skoroszyt do podanego pliku przy użyciu podanego formatu arkusza kalkulacyjnego. Jeśli plik już istnieje, zostanie on automatycznie nadpisany, jeśli `AOverwriteExisting` ma wartość `true`:
81+- `procedure WriteToFile(const AFileName: String; const AOverwriteExisting: Boolean = False)`:\
82+ tak samo, ale format pliku jest określany na podstawie podanego rozszerzenia pliku (w przypadku xls Excela używana jest najnowsza wersja `sfExcel8`).
83+
84+Po wywołaniu tych metod warto przyjrzeć się właściwości `ErrorMsg` skoroszytu, w której gromadzone są komunikaty z powodu błędów lub ostrzeżeń, które mogły wystąpić podczas odczytu/zapisu. Ta właściwość zwraca wielowierszowy ciąg, który jest najlepiej wyświetlany w komponencie memo; jeśli wszystko było w porządku, jest to pusty ciąg.
85+
86+<b>Uwaga:</b> PSpreadsheets zapewnia wyspecjalizowane moduły do odczytu i zapisu w każdym formacie pliku. Te moduły nie są dostępne automatycznie, musisz je jawnie dodać do klauzuli **uses**. FPSpreadsheet zgłosi „nieobsługiwany format pliku”, jeśli nie zostanie znaleziony żaden pasujący moduł do odczytu/zapisu. Oto lista nazw takich modułów:
87+
88+- *xlsbiff2*, *xlsbiff5* i *xlsbiff8* la binarnych formatów plików xls odpowiednio `sfExcel2`, `sfExcel5` i `sfExcel8`,
89+- *xlsxOOXML* dla formatu pliku xlsx `sfOOXML` programu Excel 2007 i nowszych,
90+- *xlsXML* dla formatu xml programów Excel XP i 2003,
91+- *fpsopendocument* dla formatu pliku `sfOpenDocument` programów OpenOffice/LibreOffice,
92+- *fpsCSV* dla plików tekstowych z wartościami oddzielonymi przecinkami (csv),
93+- *fpsHTML* dla plików HTML,
94+- *wikitables* dla `sfWikiTable_Pipes` i `sfWikiTable_WikiMedia`,
95+- lub po prostu dodaj *fpsallformats*, aby uzyskać obsługę odczytu/zapisu dla wszystkich obsługiwanych formatów plików.
96+
97+#### Arkusz roboczy
98+
99+Skoroszyt zawiera listę instancji `TsWorksheet`. Odpowiadają one zakładkom, które widzisz w programie Excel lub Open/LibreOffice. Podczas czytania pliku arkusza kalkulacyjnego poszczególne arkusze są tworzone automatycznie zgodnie z zawartością pliku. Kiedy arkusz kalkulacyjny jest tworzony ręcznie, aby zapisać go w pliku, arkusz roboczy musi zostać utworzony przez *dodanie* go do skoroszytu:
100+
101+``` pascal
102+var
103+ MyWorkbook: TsWorkbook;
104+ MyWorksheet: TsWorksheet;
105+begin
106+ MyWorkbook := TsWorkbook.Create;
107+ MyWorksheet := MyWorkbook.AddWorksheet('My_Table');
108+ // 'My_Table' to „nazwa” arkusza
109+ ...
110+```
111+
112+Dostęp do już istniejących arkuszy roboczych można uzyskać przy użyciu metod `TsWorkbook`
113+
114+- `function GetFirstWorksheet: TsWorksheet`: pobiera pierwszy arkusz ze skoroszytu.
115+- `function GetWorksheetByIndex(AIndex: Cardinal): TsWorksheet`: zwraca arkusz z podanym indeksem (począwszy od 0).
116+- `function GetWorksheetByName(AName: String): TsWorksheet`: zwraca arkusz o podanej nazwie, która była używana podczas dodawania arkusza.
117+
118+Liczbę już istniejących arkuszy można sprawdzić wywołując metodę `GetWorksheetCount`.
119+
120+#### Komórka
121+
122+Wreszcie arkusz roboczy zapewnia dostęp do komórek. Nowo utworzony arkusz, jak w powyższym przykładzie, jest pusty i nie zawiera żadnych komórek. Komórki są dodawane przez przypisanie do nich danych lub atrybutów za pomocą jednej z metod `WriteXXXX` arkusza. Jak już wspomniano, komórka jest adresowana przez indeks wiersza i kolumny, do których należy. Jak zwykle, indeksy wierszy i kolumn zaczynają się od 0. W związku z tym komórka „A1” należy do wiersza 0 i kolumny 0. Należy zauważyć, że indeksy wierszy i kolumn są zawsze podawane w tej kolejności, która *różni się od konwencji stosowanej w* `TStringGrid`. Poniższy przykład tworzy komórkę pod adresem A1 i umieszcza w niej liczbę `1.0`.
123+
124+``` pascal
125+var
126+ MyWorkbook: TsWorkbook;
127+ MyWorksheet: TsWorksheet;
128+begin
129+ MyWorkbook := TsWorkbook.Create;
130+ MyWorksheet := MyWorkbook.AddWorksheet('My_Table');
131+ MyWorksheet.WriteNumber(0, 0, 1.0); //„A1” ma rząd=0 i kolumnę=0
132+ ...
133+```
134+
135+Możliwy jest również bezpośredni dostęp do komórek za pomocą metod skoroszytu `FindCell(ARow, ACol)` lub `GetCell(ARow, ACol)`. Obie funkcje istnieją również w wersji przeciążonej, do której można przekazać adres komórki w notacji Excela: `FindCell(ACellStr: String)` lub `GetCell(ACellStr: String)`. Należy pamiętać, że te funkcje zwracają wskaźnik `pointer` do danej komórki (typ `PCell`). Nie zapomnij odwołać się do wskaźników! Różnica między `FindCell` i `GetCell` polega na tym, że pierwsza zwraca wartość `nil`, jeśli komórka jeszcze nie istnieje, a druga tworzy pustą komórkę w tym przypadku.
136+
137+``` pascal
138+if MyWorksheet.FindCell('A1') = nil then
139+ WriteLn('Komórka A1 nie istnieje.');
140+```
141+
142+##### Podstawowy rekord TCell
143+
144+Oto deklaracja typu danych komórki:
145+
146+``` pascal
147+type
148+ TCell = record
149+ { Lokalizacja komórki }
150+ Worksheet: TsWorksheet;
151+ Col: Cardinal; // od zera
152+ Row: Cardinal; // od zera
153+
154+ { Indeks formatu zapisu }
155+ FormatIndex: Integer;
156+
157+ { Flagi stanu }
158+ Flags: TsCellFlags; // (cfHasComment, cfMerged, cfHyperlink, ...)
159+
160+ { Zawartość komórki }
161+ UTF8StringValue: String; // ciąg nie może być częścią rekordu wariantowego
162+ case ContentType: TCellContentType of // który musi znajdować się na końcu deklaracji
163+ cctEmpty : (); // nie ma żadnych danych
164+ cctFormula : (); // UTF8StringValue znajduje się poza rekordem wariantowym
165+ cctNumber : (Numbervalue: Double);
166+ cctUTF8String : (); // FormulaValue znajduje się poza rekordem wariantowym
167+ cctDateTime : (DateTimevalue: TDateTime);
168+ cctBool : (BoolValue: boolean);
169+ cctError : (ErrorValue: TsErrorValue);
170+ end;
171+ PCell = ^TCell;
172+```
173+
174+Pole `ContentType` wskazuje, jaki typ danych jest przechowywany w komórce:
175+
176+``` pascal
177+type
178+ TCellContentType = (cctEmpty, cctFormula, cctNumber, cctUTF8String, cctDateTime, cctBool, cctError);
179+```
180+
181+Zgodnie z tym polem odpowiednie dane można znaleźć w polach
182+
183+- `NumberValue` (dla `ContentType=cctNumber`), lub
184+- `UTF8StringValue` (dla `ContentType=cctUTF8String`), lub
185+- `DateTimeValue` (dla `ContentType=cctDateTime`), lub
186+- `BoolValue` (dla `ContentType=cctBool`), tj. `TRUE` lub `FALSE`, lub
187+- `ErrorValue` (dla `ContentType=cctError`).
188+
189+Ze względu na użycie rekordu wariantu większość z tych wartości zachodzi na siebie, tj. modyfikacja `NumberValue` wpływa również na inne wartości. Dlatego zawsze bierz pod uwagę wartość `ContentType` podczas bezpośredniego dostępu do rekordu `TCell` (metody arkusza omówione poniżej uwzględniają to automatycznie).
190+
191+Pole `Flags` mówi, czy z komórką są powiązane dodatkowe dane, które nie są zawarte w rekordzie komórki, zwykle w celu zaoszczędzenia pamięci:
192+
193+``` pascal
194+type
195+ TsCellFlag = (cfHasComment, cfHyperlink, cfMerged, cfHasFormula, cf3dFormula);
196+ TsCellFlags = set of TsCellFlag;
197+```
198+
199+- `cfHasComment`: Rekord komentarza można znaleźć w `Comments` arkusza.
200+- `cfHyperlink`: Komórka zawiera hiperłącze przechowywane w `Hyperlinks` arkusza.
201+- `cfMerged`: Komórka należy do scalonego bloku i rozciąga się na kilka komórek.
202+- `cfHasFormula`: Komórka jest powiązana z formułą, która jest przechowywana w `Formulas` arkusza.
203+- `cf3dFormula`: Formuła skojarzona z komórką zawierającą elementy odwołujące się do innych arkuszy tego samego skoroszytu.
204+
205+> **Note:** Po obliczeniu formuły lub po odczytaniu pliku, formuła komórki w `ContentType` jest konwertowana na wynik. Wówczas obecność formuły można wykryć tylko przez wywołanie funkcji `HasFormula(cell)` dla odpytywanej komórki (`cell: PCell`) w module *fpsUtils*; ta funkcja sprawdza obecność elementu `cfHasFormula` we flagach komórki.
206+
207+##### Jak dodawać i czytać dane do/z komórki
208+
209+Dodawanie wartości do komórki jest najłatwiejsze przy użyciu jednej z metod arkusza `WriteXXXX`. Najważniejsze z nich to:
210+
211+``` pascal
212+type
213+ TsWorksheet = class
214+ ...
215+ { Zapisywanie wartości walutowych }
216+ function WriteCurrency(ARow, ACol: Cardinal; AValue: Double;
217+ ANumFormat: TsNumberFormat = nfCurrency; ADecimals: Integer = 2;
218+ ACurrencySymbol: String = '?'; APosCurrFormat: Integer = -1;
219+ ANegCurrFormat: Integer = -1): PCell; overload;
220+ procedure WriteCurrency(ACell: PCell; AValue: Double;
221+ ANumFormat: TsNumberFormat = nfCurrency; ADecimals: Integer = -1;
222+ ACurrencySymbol: String = '?'; APosCurrFormat: Integer = -1;
223+ ANegCurrFormat: Integer = -1); overload;
224+ function WriteCurrency(ARow, ACol: Cardinal; AValue: Double;
225+ ANumFormat: TsNumberFormat; ANumFormatString: String): PCell; overload;
226+ procedure WriteCurrency(ACell: PCell; AValue: Double;
227+ ANumFormat: TsNumberFormat; ANumFormatString: String); overload;
228+
229+ { Zapisywanie wartości daty/czasu }
230+ function WriteDateTime(ARow, ACol: Cardinal; AValue: TDateTime): PCell; overload;
231+ procedure WriteDateTime(ACell: PCell; AValue: TDateTime); overload;
232+ function WriteDateTime(ARow, ACol: Cardinal; AValue: TDateTime;
233+ ANumFormat: TsNumberFormat; ANumFormatStr: String = ''): PCell; overload;
234+ procedure WriteDateTime(ACell: PCell; AValue: TDateTime;
235+ ANumFormat: TsNumberFormat; ANumFormatStr: String = ''); overload;
236+ function WriteDateTime(ARow, ACol: Cardinal; AValue: TDateTime;
237+ ANumFormatStr: String): PCell; overload;
238+ procedure WriteDateTime(ACell: PCell; AValue: TDateTime;
239+ ANumFormatStr: String); overload;
240+
241+ { Zapisywanie wartości liczbowych }
242+ function WriteNumber(ARow, ACol: Cardinal; ANumber: double): PCell; overload;
243+ procedure WriteNumber(ACell: PCell; ANumber: Double); overload;
244+ function WriteNumber(ARow, ACol: Cardinal; ANumber: double;
245+ ANumFormat: TsNumberFormat; ADecimals: Byte = 2): PCell; overload;
246+ procedure WriteNumber(ACell: PCell; ANumber: Double;
247+ ANumFormat: TsNumberFormat; ADecimals: Byte = 2); overload;
248+ function WriteNumber(ARow, ACol: Cardinal; ANumber: double;
249+ ANumFormat: TsNumberFormat; ANumFormatString: String): PCell; overload;
250+ procedure WriteNumber(ACell: PCell; ANumber: Double;
251+ ANumFormat: TsNumberFormat; ANumFormatString: String); overload;
252+
253+ { Zapisywanie ciągów typu string }
254+ function WriteText(ARow, ACol: Cardinal; AText: ansistring;
255+ ARichTextParams: TsRichTextParams = nil): PCell; overload;
256+ procedure WriteText(ACell: PCell; AText: String;
257+ ARichTextparams: TsRichTextParams = nil); overload;
258+
259+ // stare metody typu string, jak "WriteUTF8Text" są teraz przestarzałe
260+ ...
261+```
262+
263+Niektóre z tych metod istnieją w przeciążonych wersjach, w których parametry formatowania komórki można dodać razem z wartością komórki. Odpowiednio jak do zapisu, istnieje również kilka metod arkusza `worksheet` do odczytu wartości komórek:
264+
265+``` pascal
266+type
267+ TsWorksheet = class
268+ ...
269+ { Odczytywanie zawartości komórki jako ciągu }
270+ function ReadAsText(ARow, ACol: Cardinal): string; overload;
271+ function ReadAsText(ACell: PCell): string; overload;
272+ function ReadAsText(ACell: PCell; AFormatSettings: TFormatSettings): string; overload;
273+
274+ { Odczytywanie zawartości komórki jako liczby }
275+ function ReadAsNumber(ARow, ACol: Cardinal): Double; overload;
276+ function ReadAsNumber(ACell: PCell): Double; overload;
277+ function ReadNumericValue(ACell: PCell; out AValue: Double): Boolean;
278+
279+ { Odczytywanie zawartości komórki jako wartości daty/czasu }
280+ function ReadAsDateTime(ARow, ACol: Cardinal; out AResult: TDateTime): Boolean; overload;
281+ function ReadAsDateTime(ACell: PCell; out AResult: TDateTime): Boolean; overload;
282+ ...
283+```
284+
285+##### Indeks do formatu komórki
286+
287+`FormatIndex` jest to indeks <span id="id_cellformatrecord">rekordu formatu komórki</span>. Opisuje on atrybuty formatowania komórki. Te rekordy są zbierane przez wewnętrzną listę skoroszytu i są zdefiniowane w następujący sposób:
288+
289+``` pascal
290+type
291+ TsCellFormat = record
292+ FontIndex: Integer;
293+ TextRotation: TsTextRotation;
294+ HorAlignment: TsHorAlignment;
295+ VertAlignment: TsVertAlignment;
296+ Border: TsCellBorders;
297+ BorderStyles: TsCellBorderStyles;
298+ Background: TsFillPattern;
299+ NumberFormatIndex: Integer;
300+ NumberFormat: TsNumberFormat;
301+ NumberFormatStr: String;
302+ BiDiMode: TsBiDiMode; // bdDefault, bdLTR {kierunek pisania od lewej do prawej}, bdRTL {od prawej do lewej)
303+ Protection: TsCellProtection; // cpLockCell, cpHideFormulas
304+ UsedFormattingFields: TsUsedFormattingFields;
305+ //uffTextRotation, uffFont, uffBold, uffBorder, uffBackground, uffNumberFormat, uffWordWrap, uffHorAlign, uffVertAlign, uffBiDi
306+ end;
307+```
308+
309+- `FontIndex`: czcionka tekstu jako określenie indeksu na liście czcionek skoroszytu
310+- `TextRotation`: określa, czy tekst komórki jest zapisywany poziomo czy pionowo
311+- `HorAlignment`: tekst wyrównany do lewej, wyśrodkowany w poziomie lub wyrównany do prawej
312+- `VertAlignment`: tekst wyrównany do góry, na dole lub wyśrodkowany w pionie
313+- `Border`: zestaw flag wskazujących, że - jeśli są ustawione - linia graniczna jest rysowana przy lewej, górnej, prawej lub dolnej krawędzi komórki. Linie są rysowane zgodnie ze standardami `BorderStyles`, które określają styl linii i kolor obramowania.
314+- `Background`: rekord określający wypełnienie tła komórki (styl wzoru, kolor wzoru i kolor tła - patrz rozdział na temat tła komórki poniżej).
315+- `NumberFormat` i `NumberFormatStr` określają sposób formatowania wartości liczbowych lub daty/czasu (np. liczba miejsc dziesiętnych, długi lub krótki format daty itp.).
316+- Podczas formatowania komórki uwzględniane są tylko te atrybuty formatu, dla których flaga jest ustawiona w `UsedFormattingFields`. Jeśli flaga nie jest dołączona, odpowiedni atrybut jest ignorowany i zastępowany jego wartością domyślną.
317+
318+Aby określić format dla danej komórki, wywołaj odpowiednią metodę arkusza `WriteXXXX`, aby pobrać format wywołaj `ReadXXXX`. Te metody zwykle pobierają wskaźnik do komórki jako parametr, ale istnieją również przeciążone wersje, które akceptują indeks wierszy i kolumn. Ponadto style formatowania można również zastosować bezpośrednio do komórki za pomocą [[Helper types|rekordu pomocniczego]] zaimplementowanego w module *fpsCell*.
319+
320+Aby uzyskać bardziej szczegółowy opis, zobacz formatowanie komórek poniżej.
321+
322+#### Kolumny i wiersze
323+
324+Rekordy kolumn i wierszy są dodawane do każdej kolumny i wiersza o właściwościach innych niż domyślne:
325+
326+``` pascal
327+type
328+ TCol = record
329+ Col: Cardinal;
330+ Width: Single;
331+ ColWidthType: TsColWidthType; // = (cwtDefault, cwtCustom)
332+ FormatIndex: Integer;
333+ Options: TsColRowOptions; // set of [croHidden, croPageBreak]
334+ end;
335+ PCol = ^TCol;
336+
337+ TRow = record
338+ Row: Cardinal;
339+ Height: Single;
340+ RowHeightType: TsRowHeightType; // = (rhtDefault, rhtCustom, rhtAuto)
341+ FormatIndex: Integer;
342+ Options: TsColRowOptions; // set of [croHidden, croPageBreak]
343+ Hidden: Boolean;
344+ PageBreak: Boolean;
345+ end;
346+ PRow = ^TRow;
347+```
348+
349+##### Szerokość kolumny / wysokość wiersza
350+
351+**Szerokość kolumn** i **Wysokość wierszy** można określić w różnych jednostkach zdefiniowanych przez typ `TsSizeUnits = (suChars, suLines, suMillimeters, suCentimeters, suPoints, suInches)`. `suChars` odnosi się do znaków liczby `0` mieszczących się w szerokości kolumny - w ten sposób Excel definiuje szerokości kolumn. `suLines` to liczba linii tekstu mieszczących się na wysokości wiersza. Obie jednostki są oparte na rozmiarze znaku domyślnej czcionki skoroszytu. Pozostałe jednostki to konwencjonalne jednostki długości fizycznej (1 cm = 10 mm, 1 cal = 25,4 mm = 72 punkty). Akceptowane są wartości ułamkowe. Skoroszyt i arkusze robocze przechowują wewnętrznie długości w milimetrach (`MyWorkbook.Units`).
352+
353+Aplikacje pakietu Office zazwyczaj automatycznie dostosowują wysokość wierszy zgodnie z czcionką lub rotacją tekstu w zawartości komórki. Ten przypadek jest identyfikowany przez `RowHeightType` o wartości `rhtAuto`. Ponieważ arkusz nie może bardzo dokładnie obliczyć rozmiaru tekstu, automatyczne wysokości wierszy nie są zapisywane przez FPSpreadsheet; są one zastępowane przez **domyślną wysokość wiersza**. Domyślna wysokość wiersza jest również używana, jeśli wiersz jest pusty, tj. gdy nie zawiera żadnych komórek danych. Jej wartość można zmienić, wywołując metodę `WriteDefaultRowHeight()` arkusza lub używając właściwości arkusza `DefaultRowHeight`. W `WriteDefaultRowHeight()` jednostki muszą być określone, podczas gdy w `DefaultRowHeight` zakłada się, że są to linie. Podobnie, **domyślną szerokość kolumny** można określić za pomocą funkcji `WriteDefaultColWidth()` lub właściwości `DefaultColWidth` (w znakach).
354+
355+W celu przekroczenia automatycznych i domyślnych wysokości wierszy wywołaj metodę arkusza `WriteRowHeight()`. Te rekordy wierszy są identyfikowane przez `RowHeightType` o wartości `rhtCustom`. W ten sam sposób szerokość kolumn można ustawić na określoną wartość, wywołując `WriteColWidth()`. `ColWidthType` tych kolumn to `cwtCustom`.
356+
357+Wysokość/szerokość konkretnego wiersza/kolumny można pobrać za pomocą metod `GetRowHeight` lub `GetColWidth`. Zwróć uwagę, że te metody zwracają domyślne wysokości wierszy/szerokości kolumn, jeśli nie ma rekordów `TRow`/`TCol`.
358+
359+``` pascal
360+type TsWorksheet = class
361+ ...
362+ { Ustaw wysokość wiersza }
363+ procedure WriteRowHeight(ARowIndex: Cardinal; AHeight: Single; AUnits: TsSizeUnits);
364+ { Ustaw szerokość kolumny }
365+ procedure WriteColWidth(AColIndex: Cardinal; AWidth: Single; AUnits: TsSizeUnits);
366+ { Ustaw domyślną wysokość wiersza }
367+ procedure WriteDefaultRowHeight(AHeight: Single; AUnits: TsSizeUnits);
368+ { Ustaw domyślną szerokość kolumny }
369+ procedure WriteDefaultColWidth(AWidth: Single; AUnits: TsSizeUnits);
370+
371+ { Zwróć wysokość wiersza }
372+ function GetRowHeight(ARowIndex: Cardinal; AUnits: TsSizeUnits): Single;
373+ { Zwróć szerokość kolumny }
374+ function GetColWidth(AColIndex: Cardinal; AUnits: TsSizeUnits): Single;
375+ { Zwróć domyślną wysokość wiersza }
376+ function ReadDefaultRowHeight(AUnits: TsSizeUnits): Single;
377+ { Zwróć domyślną szerokość kolumny }
378+ function ReadDefaultColWidth(AUnits: TsSizeUnits): Single;
379+
380+ property DefaultRowHeight: Single; // w liniach tekstu
381+ property DefaultColWidht: Single; // w liczbie znaków
382+```
383+
384+Istnieją również przeciążone wersje tych metod, które nie wymagają parametru `AUnits`. W tym przypadku wysokości wierszy są określane jako liczba linii tekstu, a szerokości kolumn są określane jako liczba znaków. Zauważ, że te warianty pochodzą z poprzednich wersji i są teraz przestarzałe.
385+
386+##### Formaty kolumn i wierszy
387+
388+Element `FormatIndex` formatu rekordów wierszy i kolumn ma zastosowanie do całego wiersza lub całej kolumny. Razem z komórkami te formaty są przechowywane jako rekordy `TsCellFormat` na wewnętrznej liście skoroszytów. `FormatIndex` jest indeksem właściwości formatu na tej liście. Zobacz szczegóły w sekcji Formatowanie komórek. **Formaty wierszy i kolumn** są stosowane głównie do pustych komórek, ale po dodaniu nowej komórki automatycznie otrzyma ona format wiersza lub kolumny. (Jeśli zarówno wiersz, jak i kolumna mają różne formaty, zostanie użyty format wiersza).
389+
390+Tutaj jest lista metod arkusza dostępna dla formatowania kolumn i wierszy:
391+
392+``` Pascal
393+type TsWorksheet = class
394+ // Przypisuje format do kolumny lub wiersza
395+ procedure WriteColFormatIndex(ACol: Cardinal; AFormatIndex: Integer);
396+ procedure WriteRowFormatIndex(ARow: Cardinal; AFormatIndex: Integer);
397+
398+ // Odczytuje format kolumny lub wiersza
399+ function GetColFormatIndex(ACol: Cardinal): Integer;
400+ function GetRowFormatIndex(ARow: Cardinal): Integer;
401+
402+ // Zwraca czcionkę przypisaną do kolumny lub wiersza
403+ function ReadColFont(ACol: PCol): TsFont;
404+ function ReadRowFont(ARow: PRow): TsFont;
405+
406+ // Sprawdza, czy jakakolwiek kolumna lub wiersz ma specjalny format
407+ function HasRowFormats: Boolean;
408+ function HasColFormats: Boolean;
409+```
410+
411+##### Hidden columns / rows
412+
413+Adding the flag `croHidden` to the row's or column's `Options` hides the row or column in the Office application (or in TsWorksheetGrid). The following worksheet methods are helpers to handle **row/column visibility**:
414+
415+``` pascal
416+type TsWorksheet = class
417+ ...
418+ { Hide column/row }
419+ procedure HideCol(ACol: Cardinal);
420+ procedure HideRow(ARow: Cardinal);
421+
422+ { Show a previously hidden column/row }
423+ procedure ShowCol(ACol: Cardinal);
424+ procedure ShowRow(ARow: Cardinal);
425+
426+ { Check whether column/row is hidden }
427+ function ColHidden(ACol: Cardinal): Boolean;
428+ function RowHidden(ARow: Cardinal): Boolean;
429+```
430+
431+##### Page breaks
432+
433+The flag `croPageBreak` can be added to the row's or column's `Options` in order to force a **page break** before the corresponding row or column when the worksheet is printed by the Office applications. Note that FPSpreadsheet itself does not support printing. The following worksheet methods help with page breaks:
434+
435+``` pascal
436+type TsWorksheet = class
437+ ...
438+ { Enforce a page break before the specified column/row }
439+ procedure AddPageBreakToCol(ACol: Cardinal);
440+ procedure AddPageBreakToRow(ARow: Cardinal);
441+
442+ { Removes a page break previously added to a column/row }
443+ procedure RemovePageBreakFromCol(ACol: Cardinal);
444+ procedure RemovePageBreakFromRow(ARow: Cardinal);
445+
446+ { Checks whether a page break is forced before the specified column/row }
447+ function IsPageBreakCol(ACol: Cardinal): Boolean;
448+ function IsPageBreakRow(ARow: Cardinal): Boolean;
449+```
450+
451+#### Events
452+
453+Worksheets and workbooks fire a series of events such as OnChangeCell, OnChangeFont, etc. The events usually are intended for interaction with the [[FPSpreadsheet tutorial: Writing a mini spreadsheet application|visual spreadsheet controls]]. If you need to attach your own handlers you should make sure that the original handler is called, at least in a gui program using the spreadsheet controls. Or you use the events provided by the visual controls themselves, e.g. [[TsWorksheetGrid|WorksheetGrid]]`.OnEditingDone` instead of `WorksheetGrid.Worksheet.OnChangeCell`.
454+
455+### Formulas
456+
457+Two kinds of formulas are supported by FPSpreadsheet:
458+
459+- **String formulas**: These are written in strings just like in the office applications, for example `"=ROUND(A1+B1,0)"`. They are used internally in the files of Open/LibreOffice and Excel *.xlsx*.
460+- **RPN formulas** are used internally by the binary *.xls* Excel files. They are written in Reverse Polish Notation (RPN), for example: `A1, B1, Add, 0, ROUND`. If a spreadsheet containing formulas is to be saved in a binary Excel format, the RPN formulas required are generated automatically.
461+
462+FPSpreadsheet can convert between string and rpn formulas. Formulas in both types can be calculated.
463+
464+In older versions of FPSpreadsheet, formulas were stored directly in the cell record. This was given up to have parsed formulas available for faster calculation. The formulas are stored in the tree `Formulas` of the worksheet. The formula record contains the row and column index of the cell to which the formula belongs, the string representation of the formula, as well as the parser tree for quick evaluation.
465+
466+FPSpreadsheet supports the majority of the formulas provided by the common spreadsheet applications. However, when reading a file created by these applications, there is always a chance that an unsupported formula is contained. To avoid crashing of fpspreadsheet, reading of formulas is disabled by default; the cell displays only the result of the formula written by the Office application. To activate reading of formulas add the element `boReadformulas` to the workbook's `Options` before opening the file. If an error occurs in this case the reader normally catches the exception, writes the exception message into the workbook's errorlog and continues reading. If you want reading to stop you must add the `boAbortReadingOnFormulaError` to the workbook `Options`.
467+
468+Formulas can link to data in other sheets of the same workbook ("3d formulas") by applying the Excel syntax (see below). External links to spreadsheets in other files are not supported.
469+
470+Calculation of formulas is normally not needed when a file is written by FPSpreadsheet for opening in an Office application because that automatically calculates the formula results. If the same file, however, is openend by an application based on FPSpreadsheet the calculated cells would be empty because the formulas are not automatically calculated by default. To activate calculation of formulas before writing a spreadsheet to file you have to add the option `boCalcBeforeSaving` to the workbook's `Options`.
471+
472+If FPSpreadshet is used in an interactive application (such as the *spready* demo found in the *examples* folder of the FPSpreadsheet installation) it is desirable to calculate formulas automatically whenever formula strings or cell values are changed by the user. This can be achieved by the option `boAutoCalc` in the workbook's `Options`.
473+
474+The most general setting regarding formulas, therefore, is
475+
476+``` pascal
477+ MyWorkbook.Options := MyWorkbook.Options + [boReadFormulas, boCalcBeforeSaving, boAutoCalc];
478+```
479+
480+Calculation of formulas can be triggered manually by calling the method `CalcFormulas` of the worksheet or workbook. The latter is absolutely required when the workbook contains 3d formulas where the result of one cell can affect cells in other sheets. If there are only within-sheet formulas then the worksheet's `CalcFormulas` is sufficient.
481+
482+#### String formulas
483+
484+String formulas are written in the same way as in the Office applications. The worksheet method for creating a string formula is `WriteFormula`:
485+
486+``` pascal
487+var
488+ MyWorksheet: TsWorksheet;
489+//...
490+ MyWorksheet.WriteFormula(0, 1, '=ROUND(A1+B2+1.215,0)');
491+ // By default, use dot as decimal and comma as list separator!
492+```
493+
494+A few notes on **syntax**:
495+
496+- The leading `=` character which identifies formulas in the Office applications is not absolutely necessary here and can be dropped. The formula is stored in the cell record without it.
497+- The case of the formula name is ignored.
498+- Spaces can be added for better readability, but they will be lost when saving.
499+- Strings must be enclosed in double quotes.
500+- The corner points of a cell range must be separated by a colon (":"), e.g. `A1:C3`. Unordered ranges will be rearranged when the formula is parsed, i.e. `C3:A1` becomes `A1:C3`.
501+- Links to other worksheets must follow the Excel syntax which separates the sheetname and cell address by a "!". An single cell, for example, can be linked by `Sheet1!A1`. An range of sheets must be placed before the cell or cell range, e.g. `Sheet1:Sheet2!A1:C3`. Note that the Open/LibreOffice syntax with a separating point and reference to the corner points of the 3d box (i.e., `Sheet1.A1:Sheet2.C3`) is not supported. Note also that the worksheet(s) to which the formula links must exist at the time when the formula is added; otherwise the link will be replaced by the error code `#REF!`, and the formula will not be usable even if the missing sheet is added later.
502+- Normally, floating point numbers must be entered with a dot as decimal separator, and a comma must be used to separate function arguments.
503+- Setting the optional parameter `ALocalized` of the worksheet methods `WriteFormula` to `TRUE`, however, allows to use localized decimal and list separators taken from the workbook's `FormatSettings` - see *spready* demo.
504+
505+``` pascal
506+var
507+ MyWorksheet: TsWorksheet;
508+//...
509+ MyWorksheet.WriteFormula(0, 1, '=ROUND(A1+B2+1,215;0)', true);
510+ // Because of the "true" the formula parser accepts the comma as decimal and the
511+ // semicolon as list separator if the workbook's FormatSettings are set up like this.
512+```
513+
514+Use the worksheet methods `ReadFormula` or `ReadFormulaAsString` to retrieve the string formula assigned to the cell. The pointer to the cell must be given as a parameter. The latter function accepts an additional (boolean) parameter `ALocalized` to use the decimal and list separators of the workbook's `FormatSettings` for creation of the formula string.
515+
516+``` pascal
517+var
518+ MyWorksheet: TsWorksheet;
519+ cell: PCell;
520+//...
521+ cell := MyWorksheet.FindCell(0, 1);
522+ WriteLn('The formula in internal format is ', MyworkSheet.ReadFormula(cell));
523+ WriteLn('The localized formula is ', MyWorksheet.ReadFormulaAsString(cell, true));
524+//-------------------------------------------------------------------
525+// For the previous example, this will result in the following output
526+The formula in internal format is ROUND(A1+B2+1.215,0)
527+The localized formula is ROUND(A1+B2+1,215;0)
528+```
529+
530+#### RPN formulas
531+
532+At application level, string formulas are mainly used, and RPN formulas are of little practical importance. Therefore, documentation of RPN formulas has been removed from this main FPSpreadsheet wiki and can be found in the article [[RPN Formulas in FPSpreadsheet|"RPN Formulas in FPSpreadsheet"]].
533+
534+#### Shared formulas and array formulas
535+
536+- **Shared formulas** are only supported for reading (from Excel files).
537+- **Array formulas** are not supported, currently.
538+
539+#### List of built-in formulas
540+
541+FPSpreadsheet supports more than 80 built-in formulas. In order not to blow up this wiki page too much documentation of these formulas has been moved to the [[FPSpreadsheet: List of formulas|separate document "List of formulas"]].
542+
543+To learn more about the functions available, look at file *testcases_calcrpnformula.inc* in the *tests* folder of the FPSpreadsheet installation where every function is included with at least one sample.
544+
545+#### Extending FPSpreadsheet by user-defined formulas
546+
547+Although the built-in formulas cover most of the applications there may be a need to access a formula which is available in the Office application, but not in FPSpreadsheet. For this reason, the library supports a registration mechanism which allows to add user-defined functions to the spreadsheets. This can be done by calling the procedure `RegisterFunction` from the unit *fpsExprParser*:
548+
549+``` pascal
550+procedure RegisterFunction(const AName: ShortString; const AResultType: Char;
551+ const AParamTypes: String; const AExcelCode: Integer; ACallBack: TsExprFunctionCallBack); overload;
552+
553+procedure RegisterFunction(const AName: ShortString; const AResultType: Char;
554+ const AParamTypes: String; const AExcelCode: Integer; ACallBack: TsExprEventCallBack); overload;
555+```
556+
557+- `AName` specifies the name under which the function will be called in the spreadsheet. It must match the name of the formula in the Office application.
558+- `AResultType` is a character which identifies the data type of the function result:
559+ - `'F'` - floating point number
560+ - `'I'` - integer
561+ - `'D'` - date/time
562+ - `'B'` - boolean
563+ - `'S'` - string
564+ - `'C'` - cell address, e.g. 'A1'
565+ - `'R'` - cell range address, e.g. 'A1:C3'
566+- `AParamTypes` is a string in which each character identifies the data type of the corresponding argument. In addition to the list shown above the following symbols can be used:
567+ - `'?'` - any type
568+ - `'+'` - must be the last character. It means that the preceding character is repeated indefinitely. This allows for an arbitrary argument count. Please note, however, that Excel supports only up to 30 arguments.
569+ - lowercase `'f', 'i', 'd', 'b', 's'` indicate optional parameters of the type explained above. Of course, uppercase symbols cannot follow lower-case symbols.
570+- `AExcelCode` is the identifier of the function in xls files. See "OpenOffice Documentation of the Microsoft Excel File Format", section 3.11, for a list.
571+- `ACallback` identifies which function is called by FPSpreadsheet for calculation of the formula. It can either be a procedure or an event handler.
572+
573+``` pascal
574+type
575+ TsExprFunctionCallBack = procedure (var Result: TsExpressionResult; const Args: TsExprParameterArray);
576+ TsExprFunctionEvent = procedure (var Result: TsExpressionResult; const Args: TsExprParameterArray) of object;
577+```
578+
579+The `TsExpressionResult` is a variant record containing result or argument data of several types:
580+
581+``` pascal
582+type
583+ TsResultType = (rtEmpty, rtBoolean, rtInteger, rtFloat, rtDateTime, rtString,
584+ rtCell, rtCellRange, rtError, rtAny);
585+
586+ TsExpressionResult = record
587+ Worksheet : TsWorksheet;
588+ ResString : String;
589+ case ResultType : TsResultType of
590+ rtEmpty : ();
591+ rtError : (ResError : TsErrorValue);
592+ rtBoolean : (ResBoolean : Boolean);
593+ rtInteger : (ResInteger : Int64);
594+ rtFloat : (ResFloat : TsExprFloat);
595+ rtDateTime : (ResDateTime : TDatetime);
596+ rtCell : (ResRow, ResCol : Cardinal);
597+ rtCellRange : (ResCellRange : TsCellRange);
598+ rtString : ();
599+ end;
600+
601+ TsExprParameterArray = array of TsExpressionResult;
602+```
603+
604+As an example we show here the code for the `CONCATENATE()` formula which joins two or more strings:
605+
606+``` pascal
607+const
608+ INT_EXCEL_SHEET_FUNC_CONCATENATE = 336;
609+...
610+ RegisterFunction('CONCATENATE', 'S', 'S+', INT_EXCEL_SHEET_FUNC_CONCATENATE, @fpsCONCATENATE);
611+
612+procedure fpsCONCATENATE(var Result: TsExpressionResult; const Args: TsExprParameterArray);
613+// CONCATENATE( text1, text2, ... text_n )
614+var
615+ s: String;
616+ i: Integer;
617+begin
618+ s := '';
619+ for i:=0 to Length(Args)-1 do
620+ begin
621+ if Args[i].ResultType = rtError then
622+ begin
623+ Result := ErrorResult(Args[i].ResError);
624+ exit;
625+ end;
626+ s := s + ArgToString(Args[i]);
627+ // "ArgToString" simplifies getting the string from a TsExpressionResult as
628+ // a string may be contained in the ResString and in the ResCell fields.
629+ // There is such a function for each basic data type.
630+ end;
631+ Result := StringResult(s);
632+ // "StringResult" stores the string s in the ResString field of the
633+ // TsExpressionResult and sets the ResultType to rtString.
634+ // There is such a function for each basic data type.
635+end;
636+```
637+
638+There is a worked-out example (*demo_formula_func.pas*) in the folder *examples/other* of the FPSpreadsheet installation. In this demo, four financial functions (`FV()`, `PV()`, `PMT()`, `RATE()`) are added to FPSpreadsheet.
639+
640+#### Unsupported formulas
641+
642+Sometimes it is required to create files for the Office applications with formulas not supported by fpspreadsheet. This is possible to some extent when the workbook option `boIgnoreFormulas` is active. Then any arbitrary formula can be written to a cell, and the formula is not checked and not evaluated. The workbook can be written to an .ods or .xlsx file. The old xls file format cannot be used because the formula would have to be parsed to create the rpn formula needed.
643+
644+In folder *examples/other* you can find the sample project *demo_ignore_formula* which creates an ods file with references to another data file - external references normally are not supported by fpspreadsheet, and thus the ignore-formulas workaround must be used. Note that this example does not work with xlsx because Excel writes information on the external links to separate xml files within the xlsx container.
645+
646+### Cell formatting
647+
648+#### Number and date/time formats
649+
650+Numbers and date/time values can be displayed in a variety of formats. In FPSpreadsheet this can be achieved in two ways:
651+
652+- using **built-in number formats** by specifiying a value for the `NumberFormat` of the cell
653+- using a custom **format string**.
654+
655+Number formats can be specified by these worksheet methods:
656+
657+``` pascal
658+type
659+ TsWorksheet = class
660+ public
661+ // Set number formats alone
662+ function WriteNumberFormat(ARow, ACol: Cardinal; ANumberFormat: TsNumberFormat;
663+ const AFormatString: String = ''): PCell; overload;
664+ procedure WriteNumberFormat(ACell: PCell; ANumberFormat: TsNumberFormat;
665+ const AFormatString: String = ''); overload;
666+
667+ function WriteNumberFormat(ARow, ACol: Cardinal; ANumFormat: TsNumberFormat;
668+ ADecimals: Integer; ACurrencySymbol: String = ''; APosCurrFormat: Integer = -1;
669+ ANegCurrFormat: Integer = -1): PCell; overload;
670+ procedure WriteNumberFormat(ACell: PCell; ANumFormat: TsNumberFormat;
671+ ADecimals: Integer; ACurrencySymbol: String = '';
672+ APosCurrFormat: Integer = -1; ANegCurrFormat: Integer = -1); overload;
673+
674+ function WriteFractionFormat(ARow, ACol: Cardinal; AMixedFraction: Boolean;
675+ ANumeratorDigits, ADenominatorDigits: Integer): PCell; overload;
676+ procedure WriteFractionFormat(ACell: PCell; AMixedFraction: Boolean;
677+ ANumeratorDigits, ADenominatorDigits: Integer); overload;
678+
679+ // Set date/time formats alone
680+ function WriteDateTimeFormat(ARow, ACol: Cardinal; ANumberFormat: TsNumberFormat;
681+ const AFormatString: String = ''): PCell; overload;
682+ procedure WriteDateTimeFormat(ACell: PCell; ANumberFormat: TsNumberFormat;
683+ const AFormatString: String = ''); overload;
684+
685+ // Set cell values and number formats in one call
686+
687+ // number values
688+ function WriteNumber(ARow, ACol: Cardinal; ANumber: double;
689+ AFormat: TsNumberFormat = nfGeneral; ADecimals: Byte = 2;
690+ ACurrencySymbol: String = ''): PCell; overload;
691+ procedure WriteNumber(ACell: PCell; ANumber: Double; AFormat: TsNumberFormat = nfGeneral;
692+ ADecimals: Byte = 2; ACurrencySymbol: String = ''); overload;
693+ function WriteNumber(ARow, ACol: Cardinal; ANumber: double;
694+ AFormat: TsNumberFormat; AFormatString: String): PCell; overload;
695+ procedure WriteNumber(ACell: PCell; ANumber: Double;
696+ AFormat: TsNumberFormat; AFormatString: String); overload;
697+
698+ // date/time values
699+ function WriteDateTime(ARow, ACol: Cardinal; AValue: TDateTime;
700+ AFormat: TsNumberFormat = nfShortDateTime; AFormatStr: String = ''): PCell; overload;
701+ procedure WriteDateTime(ACell: PCell; AValue: TDateTime;
702+ AFormat: TsNumberFormat = nfShortDateTime; AFormatStr: String = ''); overload;
703+ function WriteDateTime(ARow, ACol: Cardinal; AValue: TDateTime;
704+ AFormatStr: String): PCell; overload;
705+ procedure WriteDateTime(ACell: PCell; AValue: TDateTime;
706+ AFormatStr: String); overload;
707+
708+ // currency values
709+ function WriteCurrency(ARow, ACol: Cardinal; AValue: Double;
710+ AFormat: TsNumberFormat = nfCurrency; ADecimals: Integer = 2;
711+ ACurrencySymbol: String = '?'; APosCurrFormat: Integer = -1;
712+ ANegCurrFormat: Integer = -1): PCell; overload;
713+ procedure WriteCurrency(ACell: PCell; AValue: Double;
714+ AFormat: TsNumberFormat = nfCurrency; ADecimals: Integer = -1;
715+ ACurrencySymbol: String = '?'; APosCurrFormat: Integer = -1;
716+ ANegCurrFormat: Integer = -1); overload;
717+ function WriteCurrency(ARow, ACol: Cardinal; AValue: Double;
718+ AFormat: TsNumberFormat; AFormatString: String): PCell; overload;
719+ procedure WriteCurrency(ACell: PCell; AValue: Double;
720+ AFormat: TsNumberFormat; AFormatString: String); overload;
721+ ...
722+```
723+
724+##### Built-in number formats
725+
726+The **built-in formats** are defined by the enumeration `TsNumberFormat`. In spite of its name, the elements cover both number and date/time values:
727+
728+``` pascal
729+type
730+ TsNumberFormat = (
731+ // general-purpose for all numbers
732+ nfGeneral,
733+ // numbers
734+ nfFixed, nfFixedTh, nfExp, nfPercentage, nfFraction,
735+ // currency
736+ nfCurrency, nfCurrencyRed,
737+ // dates and times
738+ nfShortDateTime, nfShortDate, nfLongDate, nfShortTime, nfLongTime,
739+ nfShortTimeAM, nfLongTimeAM, nfDayMonth, nfMonthYear, nfTimeInterval,
740+ // other (using format string)
741+ nfCustom);
742+```
743+
744+- **nfGeneral** corresponds to the default formatting showing as many decimals as possible (the number `3.141592654` would be unchanged.)
745+- **nfFixed** limits the decimals. The number of decimal places has to be specified in the call to `WriteNumber`. Example: with 2 decimals, the number `3.141592654` becomes `3.14`.
746+- **nfFixedTh**: similar to `nfFixed`, but adds a thousand separator when the number is displayed as a string: The number `3.141592654` would remain like in the previous example because it is too small to show thousand separators. But the number `314159.2654` would become `314,159.26`, for 2 decimals.
747+- **nfExp** selects exponential presentation, i.e. splits off the exponent. The parameter `ADecimals` in `WriteNumber` determines how many decimal places are used. (The number `3.141592654` becomes `3.14E+00` in case of two decimals).
748+- **nfPercentage** displays the number as a percentage. This means that the value is multiplied by 100, and a percent sign is added. Again, specify in `ADecimals` how many decimal places are to be shown. (The number `3.141592654` is displayed as `314.92%`, in case of 2 decimals).
749+- **nfFraction** presents a number as a fraction. Details (mixed fraction?, maximum digit count for numerator or denominator) for can be specified in the worksheet method `WriteFractionFormat`.
750+- **nfCurrency** displays the number together with a currency symbol, and there are special rules how to display negative values (in brackets, or minus sign before or after the number). The FormatSettings of the workbook are used to define the currency sign and the way numbers are displayed (`FormatSettings.CurrencyString` for the currency symbol, `FormatSettings.CurrencyFormat` for positive, `FormatSettings.NegCurrFormat` for negative values). These settings can be overridden by specifying them in the call to `WriteCurrency` directly.
751+- **nfCurrendyRed** like `nfCurrency`, in addition negative values are displayed in red.
752+- **nfShortDateTime** presents the DateTimeValue of the cell in "short date/time format", i.e. days + two digit months + two digit year + hours + minutes, no seconds. The order of the date parts is taken from the workbook's `FormatSettings`. This applies also to the other date/time formats.
753+- **nfShortDate** creates a date string showing day + two-digit month + two-digit year
754+- **nfShortTime** creates a time string showing hours + minutes.
755+- **nfLongTime**, similar, but includes seconds as well
756+- **nfShortTimeAM**, similar to `nfShortTime`, but uses the AM/PM time format, i.e. hours go up to 12, and AM or PM is added to specify morning or evening/afternoon.
757+- **nfLongTimeAM**, like `nfShortTimeAM`, but includes seconds
758+- **nfTimeInterval**, like `nfLongTime`, but there can be more than 24 hours. The interval can also be expressed in minutes or seconds, if the format strings `[n]:ss`, or `[s]`, respectively, are used.
759+- **nfCustom** allows to specify a dedicated formatting string.
760+
761+As already noted the workbook has a property `FormatSettings` which provides additional information to control the resulting formatting. This is essentially a copy of the `DefaultFormatSettings` declared in the *sysutils* unit (the elements `LongDateFormat` and `ShortDateFormat` are slightly modified to better match the default settings in the main spreadsheet applications). The main purpose of the `FormatSettings` is to add a simple way of localization to the number formats.
762+
763+##### Number format strings
764+
765+In addition to these pre-defined formats, more specialized formatting can be achieved by using the format constant `nfCustom` along with a dedicated **format string**. The format string is constructed according to Excel syntax which is close to the syntax of fpc's `FormatFloat` and `FormatDateTime` commands (accepted as well, see the online-help for these functions).
766+
767+Here is a basic list of the symbols used:
768+
769+<table>
770+<thead>
771+<tr>
772+<th>Symbol</th>
773+<th>Meaning</th>
774+<th>Format string: Number --&gt; Output string</th>
775+</tr>
776+</thead>
777+<tbody>
778+<tr>
779+<td><code>General</code></td>
780+<td>Displays all decimal places of the number</td>
781+<td><code>'General'</code>:<br />
782+1.2345678 --&gt; <code>'1.2345678'</code></td>
783+</tr>
784+<tr>
785+<td><code>0</code></td>
786+<td>Displays insignificant zeros if a number has less digits than there are zeros in the format. If used for decimal places then the number is rounded to as many decimal places as 0s are found.</td>
787+<td><code>'000'</code>: 1 --&gt; <code>'001'</code><br />
788+<code>'0.0'</code>: 1 --&gt; <code>'1.0'</code><br />
789+<code>'0.0'</code>: 1.2345678 --&gt; <code>'1.2'</code></td>
790+</tr>
791+<tr>
792+<td><code>*</code></td>
793+<td>Like "0" above, but does not display insignificant zeros.</td>
794+<td><code>'0.*'</code>: 1 --&gt; <code>'1.'</code><br />
795+<code>'0.*'</code>: 1.2345678 --&gt; <code>'1.2'</code></td>
796+</tr>
797+<tr>
798+<td><code>?</code></td>
799+<td>Like "0" above, but insignificant zeros are replaced by space characters. Good for aligning decimal points and fractions</td>
800+<td><code>'??0'</code>: 1 --&gt; <code>' 1'</code><br />
801+<code>'0.0??'</code>: 1 --&gt; <code>'1.0 '</code></td>
802+</tr>
803+<tr>
804+<td><code>.</code></td>
805+<td>Decimal separator; will be replaced by the value used in the <code>DecimalSeparator</code> of the workbook's <code>FormatSettings</code></td>
806+<td><code>'0.00'</code>: 8.9 --&gt; <code>'8.90'</code></td>
807+</tr>
808+<tr>
809+<td><code>,</code></td>
810+<td>Thousand separator; will be replaced by the value used in the <code>ThousandSeparator</code> of the workbook's <code>FormatSettings</code>. If at the end of a number formatting sequence the displayed value is divided by 1000.</td>
811+<td><code>'#,##0.00'</code>: 1200 --&gt; <code>'1,200.00'</code><br />
812+<code>'0.00,'</code>: 1200 --&gt; <code>'1.20'</code></td>
813+</tr>
814+<tr>
815+<td><code>E+</code>, <code>e+</code></td>
816+<td>Displays a number in exponential format. The digits used for the exponent are defined by the number of zeros added the this symbol. The sign of the exponent is shown for positive and negative exponents.</td>
817+<td><code>'0.00E+00'</code>: 1200 --&gt; <code>1.20E+03</code></td>
818+</tr>
819+<tr>
820+<td><code>E-</code>, <code>e-</code></td>
821+<td>Displays a number in exponential format. The digits used for the exponent are defined by the number of zeros added the this symbol. The sign of the exponent is shown only for negative exponents.</td>
822+<td><code>'0.00e-000'</code>: 1200 --&gt; <code>1.20e003</code></td>
823+</tr>
824+<tr>
825+<td><code>%</code></td>
826+<td>Displays the number as a "percentage", i.e. the number is multiplied by 100 and a <code>%</code> sign is added.</td>
827+<td><code>'0.0%'</code>: 0.75 --&gt; <code>75.0%</code></td>
828+</tr>
829+<tr>
830+<td><code>/</code></td>
831+<td>This symbol has two meanings: if the cell represents a "number" then the slash indicates formatting as fraction, place holders for numerator and denominator must follow. If the cell represents a "date/time" then the slash indicates the date separator which will be replaced by the <code>DateSeparator</code> of the workbook's <code>FormatSettings</code></td>
832+<td><code>'#/#'</code>: 1.5 --&gt; <code>'3/2'</code><br />
833+<code>'# #/#'</code>: 1.5 --&gt; <code>'1 1/2'</code><br />
834+<code>'# #/16'</code>: 1.5 --&gt; <code>'1 8/16'</code><br />
835+also: see date/time examples below</td>
836+</tr>
837+<tr>
838+<td><code>:</code></td>
839+<td>Separator between hours, minutes and seconds of a date/time value. Will be replaced by the <code>TimeSeparator</code> of the workbook's <code>FormatSettings</code>.</td>
840+<td>see examples below</td>
841+</tr>
842+<tr>
843+<td><code>yyyy</code></td>
844+<td>Place holder for the year of a date/time value. The year is displayed as a four-digit number.</td>
845+<td><code>'yyyy/mm/dd'</code>:<br />
846+Jan 3, 2012 --&gt; <code>'2012-01-03'</code><br />
847+In this example, the <code>DateSeparator</code> is a dash character (<code>-</code>).</td>
848+</tr>
849+<tr>
850+<td><code>yy</code></td>
851+<td>Place holder for the year of a date/time value. The year is displayed as a two-digit number.</td>
852+<td><code>'yy/mm/dd'</code>:<br />
853+Jan 3, 2012 --&gt; <code>'12-01-03'</code></td>
854+</tr>
855+<tr>
856+<td><code>m</code></td>
857+<td>Place holder for the month of a date/time value. The month is shown as a number without extra digits.<br />
858+Please note that the <code>m</code> code can also be interpreted as the "minutes" of a time value (see below).</td>
859+<td><code>'yyyy/m/dd'</code>:<br />
860+Jan 3, 2012 --&gt; <code>'2012-1-03'</code></td>
861+</tr>
862+<tr>
863+<td><code>mm</code></td>
864+<td>Place holder for the month of a date/time value. The month is shown as a two-digit number, i.e. a leading zero is added for January to September.<br />
865+Please note that the <code>mm</code> code can also be interpreted as the "minutes" of a time value (see below).</td>
866+<td><code>'yyyy/mm/dd'</code>:<br />
867+Jan 3, 2012 --&gt; <code>'2012-01-03'</code></td>
868+</tr>
869+<tr>
870+<td><code>mmm</code></td>
871+<td>Place holder for the month of a date/time value. The month is displayed by its abbreviated name.</td>
872+<td><code>'yyyy/mmm/dd'</code>:<br />
873+Jan 3, 2012 --&gt; <code>'2012-Jan-03'</code></td>
874+</tr>
875+<tr>
876+<td><code>mmmm</code></td>
877+<td>Place holder for the month of a date/time value. The month is displayed by its full name.<br />
878+</td>
879+<td><code>'yyyy/mmm/dd'</code>:<br />
880+Jan 3, 2012 --&gt; <code>'2012-January-03'</code></td>
881+</tr>
882+<tr>
883+<td><code>d</code></td>
884+<td>Place holder for the day of a date/time value to be displayed as a number. The day is displayed as a simple number, without adding a leading zero.</td>
885+<td><code>'yyyy/mm/d'</code>:<br />
886+Jan 3, 2012 --&gt; <code>'2012-01-3'</code></td>
887+</tr>
888+<tr>
889+<td><code>dd</code></td>
890+<td>Place holder for the day of a date/time value to be displayed as a number. <code>dd</code> adds a leading zero to single-digit day numbers.</td>
891+<td><code>'yyyy/mm/dd'</code>:<br />
892+Jan 3, 2012 --&gt; <code>'2012-01-03'</code></td>
893+</tr>
894+<tr>
895+<td><code>ddd</code></td>
896+<td>Place holder for the day of a date/time value. The day is displayed as its abbreviated name.</td>
897+<td><code>'dddd, yyyy/mm/ddd'</code>:<br />
898+Jan 03, 2012 --&gt; <code>'Tue 2012-01-03'</code></td>
899+</tr>
900+<tr>
901+<td><code>dddd</code></td>
902+<td>Place holder for the day of a date/time value. The day is displayed as its full name.</td>
903+<td><code>'dddd, yyyy/mmmm/dd'</code>:<br />
904+Jan 03, 2012 --&gt; <code>'Tuesday 2012-01-03'</code></td>
905+</tr>
906+<tr>
907+<td><code>h</code></td>
908+<td>Place holder of the hour part of a date/time value. The hour is displayed as a simple number, without adding a leading zero.</td>
909+<td><code>'h:mm'</code>:<br />
910+0.25 --&gt; <code>'6:00'</code></td>
911+</tr>
912+<tr>
913+<td><code>hh</code></td>
914+<td>Place holder of the hour part of a date/time value. The hour is displayed with a leading zero if the hour is less than 10.</td>
915+<td><code>'hh:mm'</code>:<br />
916+0.25 --&gt; <code>'06:00'</code></td>
917+</tr>
918+<tr>
919+<td><code>[hh]</code>, or <code>[h]</code></td>
920+<td>Displays elapsed time such that the hour part can become greater than 23</td>
921+<td><code>'[h]:mm'</code>:<br />
922+1.25 --&gt; <code>'30:00'</code></td>
923+</tr>
924+<tr>
925+<td><code>m</code></td>
926+<td>Place holder of the minutes part of a date/time value. The minutes are shown as a simple number without adding a leading zero. Note that if the <code>m</code> codes are surrounded by date symbols (<code>y</code>, <code>d</code>) then they are interpreted as "month".</td>
927+<td><code>'h:m'</code>:<br />
928+0.25 --&gt; <code>'6:0'</code></td>
929+</tr>
930+<tr>
931+<td><code>mm</code></td>
932+<td>Place holder of the minutes part of a date/time value. Single-digit minutes are displayed with a leading zero. Note that if the <code>mm</code> code is surrounded by date symbols (<code>y</code>, <code>d</code>) then it is interpreted as "month".</td>
933+<td><code>'h:mm'</code>:<br />
934+0.25 --&gt; <code>'6:00'</code></td>
935+</tr>
936+<tr>
937+<td><code>[mm]</code>, or <code>[m]</code></td>
938+<td>Displays elapsed time such that the minute part can become greater than 59</td>
939+<td><code>'[mm]:ss'</code>:<br />
940+1.25 --&gt; <code>'1800:00'</code></td>
941+</tr>
942+<tr>
943+<td><code>s</code></td>
944+<td>Place holder of the seconds part of a date/time value. The seconds are displayed as a simple number, without adding a leading zero.</td>
945+<td><code>'hh:mm:s'</code>:<br />
946+0.25 --&gt; <code>'06:00:0'</code></td>
947+</tr>
948+<tr>
949+<td><code>ss</code></td>
950+<td>Place holder of the seconds part of a date/time value. Single-digit seconds are displayed with a leading zero.</td>
951+<td><code>'hh:mm:ss'</code>:<br />
952+0.25 --&gt; <code>'06:00:00'</code></td>
953+</tr>
954+<tr>
955+<td><code>[ss]</code>, or <code>[s]</code></td>
956+<td>Displays elapsed time such that the seconds part can become greater than 59</td>
957+<td><code>'[ss]'</code>:<br />
958+1.25 --&gt; <code>'108000'</code></td>
959+</tr>
960+<tr>
961+<td><code>AM/PM</code>, <code>am/pm</code>, <code>A/P</code>, or <code>a/p</code></td>
962+<td>Displays the time in the 12-hour format.</td>
963+<td><code>'hh:mm:ss AM/PM'</code>:<br />
964+0.25 --&gt; <code>'6:00:00 AM'</code></td>
965+</tr>
966+<tr>
967+<td><code>"</code></td>
968+<td>The text enclosed by quotation marks is inserted into the formatted strings literally.</td>
969+<td><code>'yyyy"/"mm"/"dd'</code>:<br />
970+Jan 3, 2012 --&gt; <code>'2012/01/03'</code> (i.e. the <code>/</code> is not replaced by the <code>DateSeparator</code> of the workbook).</td>
971+</tr>
972+<tr>
973+<td><code>\</code></td>
974+<td>The next character of the format string appears in the result string literally. The <code>\</code> itself does not show up.</td>
975+<td><code>'yyyy\/mm\/dd'</code>:<br />
976+Jan 3, 2012 --&gt; <code>'2012/01/03'</code></td>
977+</tr>
978+<tr>
979+<td><code>;</code></td>
980+<td>A format string can contain up to three sections separated by the semicolon. The first section is used for positive numbers, the second section for negative numbers, and the third section for zero numbers. If the third section is missing then a zero value is formatted as specified in the first section. If the second section is missing as well then all values are formatted according to the first section.</td>
981+<td><code>'"#,##0"$"';-#,##0"$";"-"'</code>:<br />
982+1200 --&gt; <code>'1,200$'</code><br />
983+-1200 --&gt; <code>'1,200$'</code><br />
984+0 --&gt; <code>'-'</code></td>
985+</tr>
986+<tr>
987+<td><code>(</code>, and <code>)</code></td>
988+<td>Sometimes used for currency values to indicate negative numbers, instead of minus sign</td>
989+<td><code>'#,##0"$";(#,##0)"$"'</code>:<br />
990+-1200 --&gt; <code>'(1200)$'</code></td>
991+</tr>
992+<tr>
993+<td><code>[red]</code></td>
994+<td>The formatted string is displayed in the specified color. Instead of <code>[red]</code>, you can use accordingly <code>[black]</code>, <code>[white]</code>, <code>[green]</code>, <code>[blue]</code>, <code>[magenta]</code>, <code>[yellow]</code>, or <code>[cyan]</code>. Often used to highlight negative currency values.</td>
995+<td><code>'"$" #,##0.00;[red]("$" #,##0.00)'</code>:<br />
996+-1200 --&gt; '<span style="color:#FF0000"><code>($ 1200.00)</code></span>'</td>
997+</tr>
998+<tr>
999+<td></td>
1000+<td></td>
1001+<td></td>
1002+</tr>
1003+</tbody>
1004+</table>
1005+
1006+#### Colors
1007+
1008+FPSpreadsheet supports colors for text, cell background, and cell borders. The basic EGA colors are declared in unit *fpstypes* as constants:
1009+
1010+<figure>
1011+<img src="DefaultPalette.png" title="Predefined colors" />
1012+<figcaption>Predefined colors</figcaption>
1013+</figure>
1014+
1015+``` pascal
1016+type
1017+ TsColor = DWORD;
1018+
1019+const
1020+ scBlack = $00000000;
1021+ scWhite = $00FFFFFF;
1022+ scRed = $000000FF;
1023+ scGreen = $0000FF00;
1024+ scBlue = $00FF0000;
1025+ scYellow = $0000FFFF;
1026+ scMagenta = $00FF00FF;
1027+ scCyan = $00FFFF00;
1028+ scDarkRed = $00000080;
1029+ scDarkGreen = $00008000;
1030+ scDarkBlue = $00800000;
1031+ scOlive = $00008080;
1032+ scPurple = $00800080;
1033+ scTeal = $00808000;
1034+ scSilver = $00C0C0C0;
1035+ scGray = $00808080;
1036+ scGrey = scGray; // redefine to allow different spelling
1037+
1038+ // Identifier for undefined color
1039+ scNotDefined = $40000000;
1040+
1041+ // Identifier for transparent color
1042+ scTransparent = $20000000;
1043+```
1044+
1045+The `TsColor` represents the **rgb value** of a color, a single byte being used for the red, green, and blue components. The resulting number is in little endian notation, i.e. the red value comes first in memory: `$00BBGGRR`. (This is directly compatible with the color values as defined in the *graphics* unit.)
1046+
1047+The high order byte is usually zero but is used internally to identify special color values, such as for undefined or transparent colors.
1048+
1049+> **Note:** In older versions of the library colors were defined as indexes into a color palette. **THIS IS NO LONGER WORKING.**
1050+
1051+Unit *fpsutils* contains some useful functions for **modification of colors**:
1052+
1053+- `function GetColorName(AColor: TsColor): String;`\
1054+ returns the name of the colors defined above, or a string showing the rgb components for other colors.
1055+- `function HighContrastColor(AColor: TsColor): TsColor;`\
1056+ returns `scBlack` for a "bright", `scWhite` for a "dark" input color.
1057+- `function TintedColor(AColor: TsColor; tint: Double): TsColor;`\
1058+ brightens or darkens a color by applying a factor `tint = -1..+1`, where `-1` means "100% darken", `+1` means "100% brighten", and `0` means "no change". The hue of the color is preserved.
1059+
1060+#### Cell background
1061+
1062+The cell background can be filled by predefined patterns which are identified by the record `TsFillPattern`:
1063+
1064+``` pascal
1065+type
1066+ TsFillPattern = record
1067+ Style: TsFillStyle; // fill style pattern as defined below
1068+ FgColor: TsColor; // forground color of the fill pattern
1069+ BgColor: TsColor; // background color of the fill pattern
1070+ end;
1071+
1072+ TsFillStyle = (fsNoFill, fsSolidFill, fsGray75, fsGray50, fsGray25, fsGray12, fsGray6,
1073+ fsStripeHor, fsStripeVert, fsStripeDiagUp, fsStripeDiagDown,
1074+ fsThinStripeHor, fsThinStripeVert, fsThinStripeDiagUp, fsThinStripeDiagDown,
1075+ fsHatchDiag, fsThinHatchDiag, fsThickHatchDiag, fsThinHatchHor);
1076+```
1077+
1078+- Use the worksheet method `WriteBackground` to assign a fill pattern to a specific cell. Besides the cell address, this method requires the type of the fill pattern (`TsFillStyle`), and the foreground and background colors as specified by their `TsColor` values.
1079+- The fill pattern of a particular cell can be retrieved by calling the workbook method `ReadBackground`.
1080+- The simplified method `WriteBackgroundColor` can be used to achieve a uniform background color.
1081+- **Limitations:**
1082+ - OpenDocument files support only uniform fills. The background color is a mixture of the foreground and background rgb components in a ratio defined by the fill pattern.
1083+ - BIFF2 files support only a 12.5% black-and-white shaded pattern.
1084+
1085+``` pascal
1086+type
1087+ TsWorksheet = class
1088+ public
1089+ function WriteBackground(ARow, ACol: Cardinal; AStyle: TsFillStyle; APatternColor, ABackgroundColor: TsColor): PCell; overload;
1090+ procedure WriteBackground(ACell: PCell; AStyle: TsFillStyle; APatternColor, ABackgroundColor: TsColor); overload;
1091+
1092+ function WriteBackgroundColor(ARow, ACol: Cardinal; AColor: TsColor): PCell; overload;
1093+ procedure WriteBackgroundColor(ACell: PCell; AColor: TsColor); overload;
1094+
1095+ function ReadBackground(ACell: PCell): TsFillPattern;
1096+ function ReadBackgroundColor(ACell: PCell): TsColor; overload;
1097+ // ...
1098+ end;
1099+
1100+var
1101+ cell: PCell;
1102+...
1103+ // Example 1: Assign a pattern of thin, horizontal, yellow stripes on a blue background to empty cell A1 (row 0, column 0)
1104+ MyWorksheet.WriteBackground(0, 0, fsThinStripeHor, scYellow, scBlue);
1105+
1106+ // Example 2: Uniform gray background color of cell B1 (row 0, column 1) containing the number 3.14
1107+ cell := MyWorksheet.WriteNumber(0, 1, 3.14);
1108+ MyWorksheet.WriteBackgroundColor(cell, clSilver);
1109+```
1110+
1111+#### Cell borders
1112+
1113+Cells can be emphasized by drawing border lines along their edges or diagonal lines. There are four borders plus two diagonals enumerated in the data type `TsCellBorder`:
1114+
1115+``` pascal
1116+type
1117+ TsCellBorder = (cbNorth, cbWest, cbEast, cbSouth, dbDiagUp, dbDiagDown);
1118+ TsCellBorders = set of TsCellBorder;
1119+```
1120+
1121+In order to show a border line add the corresponding border to the cell's set `Borders` (type `TsCellBorders`, see above). In this way, each cell edge can be handled separately. Use the worksheet method `WriteBorders` for this purpose. This example adds top and bottom borders to the edges A1 and B1:
1122+
1123+``` pascal
1124+ MyWorksheet.WriteBorders(0, 0, [cbNorth, cbSouth]); // A1: row 0, column 0
1125+ MyWorksheet.WriteBorders(0, 1, [cbNorth, cbSourth]); // B1: row 0, column 1
1126+```
1127+
1128+Lines usually are drawn as thin, solid, black lines. But it is possible to modify **line style** and **color** of each line. For this purpose, the cell provides an array of `TsCellBorderStyle` records:
1129+
1130+``` pascal
1131+type
1132+ TsLineStyle = (lsThin, lsMedium, lsDashed, lsDotted, lsThick, lsDouble, lsHair,
1133+ lsMediumDash, lsDashDot, lsMediumDashDot, lsDashDotDot, lsMediumDashDotDot, lsSlantDashDot);
1134+
1135+ TsCellBorderStyle = record
1136+ LineStyle: TsLineStyle;
1137+ Color: TsColor;
1138+ end;
1139+
1140+ TsCellBorderStyles = array[TsCellBorder] of TsCellBorderStyle;
1141+
1142+ TsWorksheet = class
1143+ public
1144+ function WriteBorderStyle(ARow, ACol: Cardinal; ABorder: TsCellBorder; AStyle: TsCellBorderStyle): PCell; overload;
1145+ procedure WriteBorderStyle(ACell: PCell; ABorder: TsCellBorder; AStyle: TsCellBorderStyle); overload;
1146+
1147+ function WriteBorderStyle(ARow, ACol: Cardinal; ABorder: TsCellBorder; ALineStyle: TsLineStyle; AColor: TsColor): PCell; overload;
1148+ procedure WriteBorderStyle(ACell: PCell; ABorder: TsCellBorder; ALineStyle: TsLineStyle; AColor: TsColor); overload;
1149+
1150+ function WriteBorderColor(ARow, ACol: Cardinal; ABorder: TsCellBorder; AColor: TsColor): PCell; overload;
1151+ proceure WriteBorderColor(ACell: PCell; ABorder: TsCellBorder; AColor: TsColor): PCell; overload;
1152+
1153+ function WriteBorderLineStyle(ARow, ACol: Cardinal; ABorder: TsCellBorder; ALineStyle: TsLineStyle): PCell; overload;
1154+ procedure WriteBorderLineStyle(ACell: PCell; ABorder: TsCellBorder; ALineStyle: TsLineStyle): PCell; overload;
1155+
1156+ function WriteBorderStyles(ARow, ACol: Cardinal; const AStyles: TsCellBorderStyles): PCell; overload;
1157+ procedure WriteBorderStyles(ACell: PCell; const AStyles: TsCellBorderStyles); overload;
1158+
1159+ function WriteBorders(ARow, ACol: Cardinal; ABorders: TsCellBorders): PCell; overload
1160+ procedure WriteBorders(ACell: PCell; ABorders: TsCellBorders); overload
1161+
1162+ function ReadCellBorders(ACell: PCell): TsCellBorders;
1163+ function ReadCellBorderStyle(ACell: PCell; ABorder: TsCellBorder): TsCellBorderStyle;
1164+ function ReadCellBorderStyles(ACell: PCell): TsCellBorderStyles;
1165+ ...
1166+ end;
1167+```
1168+
1169+The style of a given cell border can be specified by the following methods provided by the worksheet:
1170+
1171+- **WriteBorderStyle** assigns a cell border style record to one border of the cell. There are two overloaded versions of this method: one takes an entire `TsCellBorderStyle` record, the other one takes the individual record elements.
1172+- **WriteBorderColor** changes the color of a given border without affecting the line style of this border.
1173+- **WriteBorderLineStyle** sets the line style of the border only, but leaves the color unchanged.
1174+- **WriteBorderStyles** sets the border style of all borders of a given cell at once. Useful for copying border styles from one cell to other cells.
1175+
1176+This example adds a thin black border to the top, and a thick blue border to the bottom of cells A1 and B1:
1177+
1178+``` pascal
1179+var
1180+ cellA1, cellB1: PCell;
1181+...
1182+ cellA1 := MyWorksheet.WriteBorders(0, 0, [cbNorth, cbSouth]); // cell A1: row 0, column 0
1183+ MyWorksheet.WriteBorderStyle(cellA1, cbNorth, lsThin, scBlack);
1184+ MyWorksheet.WriteBorderStyle(cellA1, cbSouth, lsThick, scBlue);
1185+
1186+ cellB1 := MyWorksheet.WriteBorders(0, 1, [cbNorth, cbSouth]); // cell B1: row 0, column 1
1187+ MyWorksheet.WriteBorderStyles(cellB1, cellA1^.BorderStyles); // copy all border styles from cell A1 to B1
1188+```
1189+
1190+> **Note:** Diagonal lines are not supported by *sfExcel2* and *sfExcel5* - they are just omitted. *sfExcel8* and *sfOOXML* use the same linestyle and color for both diagonals; when writing the border style of the diagonal-up line is assumed to be valid also for the diagonal-down line. Some writers do not support all the line styles of the `TsLineStyle` enumeration. In this case, appropriate replacement line styles are used.
1191+
1192+#### Fonts
1193+
1194+The cell text can displayed in various fonts. For this purpose, the workbook provides a list of `TsFont` items:
1195+
1196+``` pascal
1197+type
1198+ TsFont = class
1199+ FontName: String;
1200+ Size: Single;
1201+ Style: TsFontStyles;
1202+ Color: TsColor;
1203+ Position: TsFontPosition;
1204+ end;
1205+```
1206+
1207+- The **FontName** corresponds to the name of the font as used by the operational system. In Windows, an example would be "Times New Roman".
1208+- The **FontSize** is given in "points", i.e. units 1/72 inch which are commonly used in Office applications.
1209+- The **FontStyle** is a set of the items `fssBold`, `fssItalic`, `fssStrikeout`, and `fssUnderline` which form the enumeration type `TsFontStyle`. The "normal" font corresponds to an empty set.
1210+- The **Color** determines the foreground color of the text characters given in rgb presentation as discussed above.
1211+- The **Position** is either `fpNormal`, `fpSuperscript`, or `fpSubscript` and indicates whether the font size should be decreased by about 1/3 and the characters should be displaced up (superscript) or down (subscript).
1212+
1213+Every cell is provided with an **index into the font list**.
1214+
1215+In order to assign a particular font to a cell, use one of the following methods of `TsSpreadsheet`:
1216+
1217+``` pascal
1218+type
1219+ TsSpreadsheet = class
1220+ public
1221+ function WriteFont(ARow, ACol: Cardinal; const AFontName: String;
1222+ AFontSize: Single; AFontStyle: TsFontStyles; AFontColor: TsColor): Integer; overload;
1223+ procedure WriteFont(ARow, ACol: Cardinal; AFontIndex: Integer); overload;
1224+ function WriteFontColor(ARow, ACol: Cardinal; AFontColor: TsColor): Integer;
1225+ function WriteFontSize(ARow, ACol: Cardinal; ASize: Integer): Integer;
1226+ function WriteFontStyle(ARow, ACol: Cardinal; AStyle: TsFontStyles): Integer;
1227+ // plus: overloaded versions accepting a pointer to a cell record instead of the row and column index as parameter
1228+ // ...
1229+ end;
1230+```
1231+
1232+- **WriteFont** assigns a font to the cell. If the font does not yet exist in the font list a new entry is created. The function returns the index of the font in the font list. In addition, there is an overloaded version which only takes the font index as a parameter.
1233+- **WriteFontColor** replaces the color of the font that is currently assigned to the cell by a new one. Again, a new font list item is created if the font with the new color does not yet exist. The function returns the index of the font in the list.
1234+- **WriteFontSize** replaces the size of the currently used font of the cell.
1235+- **WriteFontStyle** replaces the style (normal, bold, italic, etc.) of the currently used cell font.
1236+
1237+The workbook's font list contains at least one item which is the **default font** for cells with unmodified fonts. By default, this is 10-point "Arial". Use the workbook method `SetDefaultFont` to assign a different font to the first list item.
1238+
1239+The font at a given index of the font list can be looked up by calling the workbook function `GetFont`. The count of available fonts is returned by `GetFontCount`.
1240+
1241+Here is an **example** which decreases the size of all 10-point "Arial" fonts to 9-point:
1242+
1243+``` pascal
1244+var
1245+ i: Integer;
1246+ font: TsFont;
1247+begin
1248+ for i := 0 to MyWorkbook.GetFontCount-1 do
1249+ begin
1250+ font := MyWorkbook.GetFont(i);
1251+ if (font.FontName = 'Arial') and (font.Size = 10.0) then
1252+ font.Size := 9.0;
1253+ end;
1254+end;
1255+```
1256+
1257+#### Rich-text formatting
1258+
1259+In addition to using a specific font for each cell it is also possible to specify particular font attributes for individual characters or groups of characters in each cell text. Following the Excel notation, we call this feature **Rich-text formatting** (although is has nothing in common with the "rich-text" file format).
1260+
1261+For this purpose, unit *fpstypes* declares the type `TsRichTextParams` which is an array of `TsRichTextParam` records:
1262+
1263+``` pascal
1264+type
1265+ TsRichTextParam = record
1266+ FontIndex: Integer;
1267+ FirstIndex: Integer;
1268+ end;
1269+
1270+ TsRichTextParams = array of TsRichTextParam;
1271+```
1272+
1273+`FontIndex` refers to the index of the font in the workbook's FontList to be used for formatting of the characters beginning at the index `FirstIndex`. Being a string character index the `FirstIndex` is 1-based.
1274+
1275+There are two ways to add "rich-text" formatting to a cell text:
1276+
1277+- Embed corresponding HTML format codes into the cell text. This can be done using the method `WriteTextAsHTML` of the worksheet. In order to add the text "Area (m<sup>2</sup>)" to cell A1, pass the following HTML-coded string to this function
1278+
1279+``` pascal
1280+ MyWorksheet.WriteTextAsHTML(0, 0, 'Area (m<sup>2</sup>');
1281+```
1282+
1283+- Alternatively, the standard text writing method, `WriteText` can be called with an additional parameter specifiying the rich-text formatting parameters to be used directly:
1284+
1285+``` pascal
1286+var
1287+ richTextParams: TsRichTextParams;
1288+ fnt: TsFont;
1289+ cell: PCell;
1290+begin
1291+ SetLength(rtp, 2);
1292+ cell := MyWorksheet.GetFont(0, 0);
1293+ fnt := MyWorksheet.ReadCellFont(cell);
1294+ richTextParams[0].FirstIndex := 8; // The superscript groups begins with "2" which is the (1-based) character #8 of the cell text.
1295+ richTextParams[0].FontIndex := MyWorkbook.AddFont(fnt.FontName, fnt.Size, fnt.Style, fnt.Color, fpSuperscript);
1296+ richTextParams[1].FirstIndex := 9; // Normal font again beginning with character #9.
1297+ richTextParams[1].FontIndex := MyWorksheet.ReadCellFontIndex(0, 0);
1298+ MyWorksheet.WriteUTF8Text(cell, 'Area (m2)', richTextParams);
1299+end;
1300+```
1301+
1302+Use the worksheet method `DeleteRichTextParams` to remove rich-text formatting from a previously formatted cell.
1303+
1304+> **Note:** If the cell is supposed to have a font different from the worksheet's default font then this font must be written to the cell **before** writing the rich-text formatted text. Otherwise the font in the unformatted regions will not be up-to-date.
1305+
1306+#### Text rotation
1307+
1308+Usually text is displayed in the cells horizontally. However, it is also possible to rotate it by 90 degrees in clockwise or counterclockwise directions. In addition, there is also an option to stack horizontal characters vertically above each other.
1309+
1310+If you need this feature use the worksheet method `WriteTextRotation` and specify the text direction by an element of the enumeration type `TsTextRotation`:
1311+
1312+``` pascal
1313+type
1314+ TsTextRotation = (trHorizontal, rt90DegreeClockwiseRotation,
1315+ rt90DegreeCounterClockwiseRotation, rtStacked);
1316+
1317+ TsWorksheet = class
1318+ public
1319+ function WriteTextRotation(ARow, ACol: Cardinal; ARotation: TsTextRotation): PCell; overload;
1320+ procedure WriteTextRotation(ACell: PCell; ARotation: TsTextRotation); overload;
1321+
1322+ function ReadTextRotation(ACell: PCell): TsTextRotation;
1323+ // ...
1324+ end;
1325+
1326+ // example for counter-clockwise rotated text in cell A1:
1327+ WriteTextRotation(0, 0, rt90DegreeCounterClockwizeRotation);
1328+```
1329+
1330+> **Warning:** Finer degrees of rotation which may be supported by some spreadsheet file formats are ignored.
1331+
1332+#### Text alignment
1333+
1334+By default, cell texts are aligned to the left and bottom edges of the cell, except for numbers which are right-aligned. This behavior can be changed by using the worksheet methods `WriteHorAlignment` and `WriteVertAlignment`:
1335+
1336+``` pascal
1337+type
1338+ TsHorAlignment = (haDefault, haLeft, haCenter, haRight);
1339+ TsVertAlignment = (vaDefault, vaTop, vaCenter, vaBottom);
1340+
1341+ TsWorkbook = class
1342+ public
1343+ function WriteHorAlignment(ARow, ACol: Cardinal; AValue: TsHorAlignment): PCell; overload;
1344+ procedure WriteHorAlignment(ACell: PCell; AValue: TsHorAlignment); overload;
1345+ function ReadHorAlignment(ACell: PCell): TsHorAlignment;
1346+
1347+ function WriteVertAlignment(ARow, ACol: Cardinal; AValue: TsVertAlignment): PCell; overload;
1348+ procedure WriteVertAlignment(ACell: PCell; AValue: TsVertAlignment); overload;
1349+ function ReadVertAlignment(ACell: PCell): TsVertAlignment;
1350+ // ...
1351+ end;
1352+
1353+ // Example: Center the text in cell A1 both horizontally and vertically
1354+ MyWorkbook.WriteHorAlignment(0, 0, haCenter);
1355+ MyWorkbook.WriteVertAlignment(0, 0, vaCenter);
1356+```
1357+
1358+#### Word wrap
1359+
1360+Text which is longer than the width of a cell can wrap into several lines by calling the method `WriteWordwrap` of the spreadsheet:
1361+
1362+``` pascal
1363+type
1364+ TsWorksheet = class
1365+ public
1366+ function WriteWordwrap(ARow, ACol: Cardinal; AValue: Boolean): PCell; overload;
1367+ procedure WriteWordwrap(ACell: PCell; AValue: Boolean); overload;
1368+ function ReadWordwrap(ACell: PCell): Boolean;
1369+ //...
1370+ end;
1371+
1372+ // Example: activate wordwrap in cell A1
1373+ MyWorksheet.WriteWordwrap(0, 0, true);
1374+```
1375+
1376+#### Merged cells
1377+
1378+Like the Office applications, FPSpreadsheet supports also to feature of merging cells to a single large cell which is often used as a common header above simlar columns. Simply call `MergeCells` and pass a parameter to specify the cell range to be merged, either an Excel range string (such as `A1:D5`), or the first and last rows and columns:
1379+
1380+``` pascal
1381+ MyWorksheet.MergeCells('A1:D5');
1382+ // or: MyWorksheet.MergeCells(0, 0, 4, 3); // first row, first column, last row, last column
1383+```
1384+
1385+The content and format displayed for a merged range is taken from the upper left corner of the range, cell `A1` in above example. This cell is called the `MergeBase` in the library. Except for this corner cell, there must not be any other cells in the range. If there are their contents and format will be hidden.
1386+
1387+In order to break up a merged range back up into individual cells, use the command `Unmerge` and pass any cell that is within the merged range:
1388+
1389+``` pascal
1390+ MyWorksheet.UnmergeCells('B1');
1391+ // or: MyWorksheet.UnmergeCells(0, 1); // row, column of any cell within the range
1392+```
1393+
1394+Merged cells can be read from/written to all file formats except for `sfCSV`, `sfExcel2` and `sfExcel5` which do not support this feature natively.
1395+
1396+The information which cells are merged is stored in an internal list. Unlike in earlier versions it is no longer possible to access the `MergeBase` from the cell directly. Use the following functions to extract information on merged cells:
1397+
1398+``` pascal
1399+var
1400+ cell, base: PCell;
1401+ r1,c1,r2,c2: Cardinal;
1402+...
1403+ cell := MyWorksheet.FindCell('B1');
1404+ if MyWorksheet.IsMerged(cell) then
1405+ begin
1406+ WriteLn('Cell B1 is merged.');
1407+
1408+ MyWorksheet.FindMergedRange(cell, r1, c1, r2, c2);
1409+ WriteLn('The merged range is ' + GetCellRangeString(r1, c1, r2, c2));
1410+
1411+ base := MyWorksheet.FindMergeBase(cell);
1412+ WriteLn('The merge base is cell ' + GetCellString(base^.Row, base^.Col));
1413+ end;
1414+```
1415+
1416+#### Cell protection
1417+
1418+This is described in a separate section below.
1419+
1420+### Additional data
1421+
1422+#### Cell comments
1423+
1424+Comments can be attached to any cell by calling
1425+
1426+``` pascal
1427+ MyWorksheet.WriteComment(0, 0, 'This is a comment for cell A1');
1428+```
1429+
1430+They are stored in an internal list of the worksheet. Use the corresponding worksheet methods to access comments:
1431+
1432+- If you want to know whether a particular cell contains a comment call the worksheet method `HasComment(cell)`.
1433+- For retrieving a cell comment use the method `ReadComment(cell)`, or its overloaded companion `ReadComment(ARow, ACol)`.
1434+- The total number of comments can be retrieved from `worksheet.Comments.Count`.
1435+
1436+#### Hyperlinks
1437+
1438+Hyperlinks can be attached to cells in order to link cells to other documents or other cells in the same workbook. The general syntax for creating hyperlinks is
1439+
1440+``` pascal
1441+ procedure TWorksheet.WriteHyperlink(ARow, ACol: Cardinal; ATarget: String; ATooltip: String = '');
1442+```
1443+
1444+- The hyperlink target, passed as parameter `ATarget`, must be a fully qualified [URI (Uniform resource identifier)](http://en.wikipedia.org/wiki/Uniform_Resource_Identifier) consisting of a protocol phrase (e.g., [`http://`](http://), [`file:///`](file:///), `mailto:`, etc.) followed by specific information such as web URL, filename, or e-mail address and an optional bookmark identification separated by the character `'#'`. An exception are internal hyperlinks which enable to jump to a cell in the current workbook; they consist of the optional worksheet name and the cell address separated by the character `'!'`.
1445+- The optional `Tooltip` parameter is evaluated by Excel to display it in a hint window if the mouse if above the hyperlink.
1446+
1447+> **Note:** Hyperlinks can be added to empty cells or to cells with content. In the latter case, the displayed content is not changed by the hyperlink; in the former case the cell is converted to a label cell showing the hyperlink target. Be aware that OpenOffice/LibreOffice only does accept hyperlinks with non-text cells.
1448+
1449+**Examples:**
1450+
1451+``` pascal
1452+ // Open the web site www.google.com
1453+ MyWorksheet.WriteText(0, 0, 'Open google');
1454+ MyWorksheet.WriteHyperlink(0, 0, 'http://www.google.com');
1455+
1456+ // Open the local file with the absolute path "C:\readme.txt" (assuming Windows)
1457+ MyWorksheet.WriteHyperlink(1, 0, 'file:///c:\readme.txt');
1458+
1459+ // Open the mail client to send a mail
1460+ MyWorksheet.WriteText('Send mail');
1461+ MyWorksheet.WriteHyperlink(3, 0, 'mailto:somebody@gmail.com?subject=Test');
1462+
1463+ // Jump to a particular cell
1464+ MyWorksheet.WriteText(5, 0, 'Jump to cell A10 on sheet2');
1465+ MyWorksheet.WriteHyperlink(5, 0, '#Sheet2!A10');
1466+
1467+ // Jump to cell A10 on the current sheet and display a popup hint
1468+ MyWorksheet.WriteHyperlink(5, 0, '#A10', 'Go to cell A10');
1469+```
1470+
1471+> **Note:** FPSpreadsheet does not "follow" the links, it only provides a mechanism to get access to the link data. TsWorksheetGrid from the *laz_fpspreadsheet_visual* package, however, fires the event `OnClickHyperlink` if a cell with an external hyperlink is clicked for fractions of a second. In the corresponding event handler, you can, for example, load a target spreadsheet, or open a web browser to display the linked web site. If the link is an internal link to another cell within the same workbook then the grid jumps to the related cell.
1472+
1473+#### Images
1474+
1475+FPSpreadsheet supports embedding of images in worksheets. Use one of the worksheet methods `WriteImage()` to add an image to the worksheet:
1476+
1477+``` pascal
1478+ MyWorksheet.WriteImage(row, col, filename, offsetX, offsetY, scaleX, scaleY);
1479+ MyWorksheet.WriteImage(row, col, stream, offsetX, offsetY, scaleX, scaleY);
1480+ MyWorksheet.WriteImage(row, col, imageindex, offsetX, offsetY, scaleX, scaleY);
1481+```
1482+
1483+The upper/left corner of the image is placed at the upper/left corner of the cell in the specified row and column. The floating point parameters `offsetX`, `offsetY`, `scaleX` and `scaleY` are optional: they define an offset of this image anchor point from the cell corner and a magnification factor. The path to the image file is given as parameter `filename`. Alternatively, overloaded versions can be used which accept a stream in place of the file name or an image index in the workbook's EmbeddedObj list - use `MyWorkbook.FindEmbeddedObj(filename)` to get this index for a previously loaded image file.
1484+
1485+Note that FPSpreadsheet needs to know the image type for successfull picture import. Currently, the types *png*, *jpg*, *tiff*, *bmp*, *gif*, *svg*, *wmf*, *emf*, and *pcx* are supported (Excel2007 cannot read imported *svg* and *pcx* images). Other formats can be registered by writing a function which determines the image size and pixel density, and by registering the new format using the procedure `RegisterImageType` - see unit *fpsImages* for examples:
1486+
1487+``` pascal
1488+type
1489+ TsImageType = integer;
1490+ TGetImageSizeFunc = function (AStream: TStream; out AWidth, AHeight: DWord; out dpiX, dpiY: Double): Boolean;
1491+
1492+function RegisterImageType(AMimeType, AExtension: String; AGetImageSize: TGetImageSizeFunc): TsImageType;
1493+```
1494+
1495+Due to differences in row height and column width calculation between FPSpreadsheet and Office applications it is not possible to position images correctly. If exact image positions are important you should follow these rules:
1496+
1497+- Predefine the widths of all columns at least up to the one containing the right edge of the image.
1498+- Predefine the heights of all rows at least up to the one containing the lower edge of the image.
1499+- If the workbook is to be saved in OpenDocument format add the image after changing column widths and row heights because ods anchors the image to the sheet, not to the cell (like Excel and FPSpreadsheet).
1500+- If the exact size of the image is important make sure that it fits into a single cell.
1501+
1502+### Sorting
1503+
1504+Cells in a worksheet can be sorted for a variety of criteria by calling the `Sort` method of the worksheet. This method takes a `TsSortParams` record and the edges of the cell rectangle to be sorted as parameters; in an overloaded version, the cell rectangle can also be specified by means of an Excel-type range string (e.g. `'A1:G10'`):
1505+
1506+``` pascal
1507+type
1508+ TsWorksheet = class
1509+ // ...
1510+ procedure Sort(const ASortParams: TsSortParams;
1511+ ARowFrom, AColFrom, ARowTo, AColTo: Cardinal); overload;
1512+ procedure Sort(ASortParams: TsSortParams; ARange: String); overload;
1513+ // ...
1514+ end;
1515+```
1516+
1517+The sorting criteria are defined by a record of type `TsSortParams`:
1518+
1519+``` pascal
1520+type
1521+ TsSortParams = record
1522+ SortByCols: Boolean;
1523+ Priority: TsSortPriority; // spNumAlpha ("Numbers first"), or spAlphaNum ("Text first")
1524+ Keys: TsSortKeys;
1525+ end;
1526+
1527+ TsSortKey = record
1528+ ColRowIndex: Integer;
1529+ Options: TsSortOptions; // set of [spDescending, spCaseInsensitive]
1530+ end;
1531+```
1532+
1533+- The boolean value `SortByCols` determines wether sorting occurs along columns (`true`) or rows (`false`). The `ColRowIndex` specified in the sorting keys, accordingly, corresponds to a column or row index, respectively (see below).
1534+- `Priority` determines in mixed content cell ranges whether an ascending sort puts numerical values in front of text values or not. Empty cells are always moved to the end of the sorted column or row. In Excel, the priority is "numbers first" (`spNumAlpha`).
1535+- The array `Keys` specifies multiple sorting parameters. They consist of the index of the column or row to be sorted (`ColRowIndex`) and a set of `Options` for sorting direction (`spoDescending`) and character case (`spCaseInsensitive`). If `Options` is empty, cell comparison is case-sensitive, and cells are arranged in ascending order. If two cells are found to be "equal" on the basis of the first key (`sortParams.Keys[0]`) comparison proceeds with the next conditions in the `Keys` array until a difference is found or all conditions are used up.
1536+
1537+`InitSortParams` is a handy utility to initialize the sorting parameters:
1538+
1539+``` pascal
1540+function InitSortParams(ASortByCols: Boolean = true; ANumSortKeys: Integer = 1;
1541+ ASortPriority: TsSortPriority = spNumAlpha): TsSortParams;
1542+```
1543+
1544+The next code fragment shows a typical sorting call:
1545+
1546+``` pascal
1547+var
1548+ sortParams: TsSortParams;
1549+begin
1550+ sortParams := InitSortParams(true, 2); // sorting along columns, 2 sorting keys
1551+
1552+ // primary sorting key: column 3, ascending, case-insensitive
1553+ sortParams.Keys[0].ColRowIndex := 3;
1554+ sortParams.Keys[0].Options := [ssoCaseInsensitive];
1555+
1556+ // secondary sorting key: colum 1, descending
1557+ sortParams.Keys[1].ColRowIndex := 1;
1558+ sortParams.Keys[1].Options := [ssoDescending];
1559+
1560+ // The sorted block extends between cells A1 (row=0, col=0) and F10 (row=9, col=5)
1561+ MyWorksheet.Sort(sortParams, 0, 0, 9, 5);
1562+ // or: MyWorksheet.Sort(sortParams, 'A1:F10');
1563+end;
1564+```
1565+
1566+### Searching and replacing
1567+
1568+Unit *fpsSearch* implements a **search engine** which can be used to look for specific cell content within a workbook, or to replace the found cell content by some other string.
1569+
1570+**Example:**
1571+
1572+``` pascal
1573+uses
1574+ fpsTypes, fpSpreadsheet, fpsUtils, fpsSearch, fpsAllFormats;
1575+var
1576+ MyWorkbook: TsWorkbook;
1577+ foundWorksheet: TsWorksheet;
1578+ foundRow, foundCol: Cardinal;
1579+ MySearchParams: TsSearchParams;
1580+begin
1581+ MyWorkbook := TsWorkbook.Create;
1582+ try
1583+ MyWorkbook.ReadFromFile(AFileName);
1584+
1585+ // Specify search criteria
1586+ MySearchParams.SearchText := 'Hallo';
1587+ MySearchParams.Options := [soEntireDocument];
1588+ MySearchParams.Within := swWorkbook;
1589+
1590+ // or: MySearchParaams := InitSearchParams('Hallo', [soEntireDocument], swWorkbook);
1591+
1592+ // Create search engine and execute search
1593+ with TsSearchEngine.Create(MyWorkbook) do begin
1594+ if FindFirst(MySearchParams, foundWorksheet, foundRow, foundCol) then begin
1595+ WriteLn('First "', MySearchparams.SearchText, '" found in cell ', GetCellString(foundRow, foundCol), ' of worksheet ', foundWorksheet.Name);
1596+ while FindNext(MySeachParams, foundWorksheet, foundRow, foundCol) do
1597+ WriteLn('Next "', MySearchParams.SearchText, '" found in cell ', GetCellString(foundRow, foundCol), ' of worksheet ', foundWorksheet.Name);
1598+ end;
1599+ Free;
1600+ end;
1601+ finally
1602+ MyWorkbook.Free;
1603+ end;
1604+end;
1605+```
1606+
1607+The search engine provides two methods for **searching**: `FindFirst` and `FindNext`. They are very similar, they only differ in where the search begins. In case of `FindFirst`, the starting cell is determined from the `Options` described below. In case of `FindNext` the search begins at the cell adjacent to the previously found cell. Both methods return the worksheet and row and column indexes of the cell in which the search text is found. If the search is not successful then the function result is `FALSE`, and the `foundWorksheet` is nil. It is clear that the `foundWorksheet` cannot be used for anything else while the search is running.
1608+
1609+The record `TsSearchParams` specifies the criteria used for searching:
1610+
1611+``` pascal
1612+type
1613+ TsSearchParams = record
1614+ SearchText: String;
1615+ Options: TsSearchOptions;
1616+ Within: TsSearchWithin;
1617+ end;
1618+```
1619+
1620+Besides the text to be searched (`SearchText`) it provides a set of options to narrow the search:
1621+
1622+- `soCompareEntireCell`: Compares the `SearchText` with the entire cell content. If not contained in the `Options` then the cell text is compared only partially.
1623+- `soMatchCase`: Perform a case-sensitive search
1624+- `soRegularExpr`: The `SearchText` is considered as a regular expression
1625+- `soAlongRows`: The search engine proceeds first along the rows. If not contained in the `Options` then the search proceeds along the columns.
1626+- `soBackward`: The search begins at the end of the document, or runs backward from the active cell. If not contained in the `Options` then the search starts at the beginning of the document, or runs forward from the active cell.
1627+- `soWrapDocument`: If a search has reached the end of the document the search is resumed at its beginning (or vice versa, if `soBackward` is used).
1628+- `soEntireDocument`: Search begins at the first cell (or last cell if `soBackward` is used). If not contained in the `Options` then the search begins at the active cell of the worksheet. Ignored by `FindNext`.
1629+
1630+The record field `Within` identifies the part of the spreadsheet to be searched:
1631+
1632+- `swWorkbook`: The entire workbook is searched. If the search phrase is not found on the first worksheet (or last worksheet if `soBackward` is used) then the search continues with the next (previous) sheet.
1633+- `swWorksheet`: The search is limited to the currently active worksheet
1634+- `swColumn`: Search is restricted to the column of the active cell
1635+- `swRow`: Search is restricted to the row of the active cell.
1636+
1637+The search params record can be initialized by calling `InitSearchParams` (in unit *fpsutils*) with the record elements as optional parameters. Use the methods `Workbook.ActiveWorksheet` and `Worksheet.SelectCell(ARow, ACol)` to define the active worksheet and the position of the active cell, respectively, if needed by the search.
1638+
1639+In addition to searching the search engine can also be used for **replacing** the found text by another string. Call the functions `ReplaceFirst` or `ReplaceNext` for this purpose. They act like their `FindXXXX` counterparts, therefore, they require a `TsSearchParams` record to specify the search criteria. But in addition to searching, these functions also perform the text replacement according to the specification in a `TsReplaceParams` record:
1640+
1641+``` pascal
1642+type
1643+ TsReplaceParams = record
1644+ ReplaceText: String;
1645+ Options: TsReplaceOptions;
1646+ end;
1647+```
1648+
1649+The `ReplaceText` identifies the string which will replace the found text pattern. The `Options` define a set of criteria how the replacement is done:
1650+
1651+- `roReplaceEntirecell`: Replaces the entire cell text by the `ReplaceText`. If not contained in the `Options` then only the part matching the `SearchText` is replaced.
1652+- `roReplaceAll`: Performs the replacement in all found cells (i.e., simply call `ReplaceFirst` to replace all automatically).
1653+- `roConfirm`: Calls an event handler for the `OnConfirmReplacement` event in which the user must specify whether the replacement is to be performed or not. Note that this event handler is mandatory if `roConfirm` is set.
1654+
1655+Use the function `InitReplaceParams` (in unit *fpsutils*) to initialize the replace parameters record with the provided (but optional) values.
1656+
1657+### Column and row operations
1658+
1659+The worksheet provides these methods for inserting, deleting, hiding or unhiding columns and rows:
1660+
1661+``` pascal
1662+type
1663+ TsWorksheet = class
1664+ ...
1665+ procedure DeleteCol(ACol: Cardinal);
1666+ procedure DeleteRow(ARow: Cardinal);
1667+
1668+ procedure InsertCol(ACol: Cardinal);
1669+ procedure InsertRow(ARow: Cardinal);
1670+
1671+ procedure RemoveCol(ACol: Cardinal);
1672+ procedure RemoveRow(ARow: Cardinal);
1673+
1674+ procedure RemoveAllCols;
1675+ procedure RemoveAllRows
1676+
1677+ procedure HideCol(ACol: Cardinal);
1678+ procedure HideRow(ARow: Cardinal);
1679+
1680+ procedure ShowCol(ACol: Cardinal);
1681+ procedure ShowRow(ARow: Cardinal);
1682+
1683+ function ColHidden(ACol: Cardinal): Boolean;
1684+ function RowHidden(ARow: Cardinal): Boolean;
1685+```
1686+
1687+- When a column or row is **deleted** by `DeleteCol` or `DeleteRow`, any data assigned to this column or row are removed, i., cells, comments, hyperlinks, TCol or TRow records. Data at the right of or below the deleted column/row move to the left or up.
1688+
1689+- `RemoveCol` and `RemoveRow`, in contract, **remove** only the column or row record, i.e. reset column width and row height to their default values. Cell, comment, and hyperlink data are not affected.
1690+
1691+- `RemoveAllCols` **removes all** column records, i.e. resets all column widths; `RemoveAllRows` does the same with the row records and row heights.
1692+
1693+- A column or row is **inserted** before the index specified as parameter of the `InsertXXX` method.
1694+
1695+### Page layout
1696+
1697+#### General
1698+
1699+So far, FPSpreadsheet does not support printing of worksheets, but the Office applications do, and they provide a section of information in their files for this purpose. In FPSpreadsheets this information is available in the `TsPageLayout` class which belongs to the `TsWorksheet` data structure. Its properties and methods combine the most important features from the Excel and OpenDocument worlds.
1700+
1701+``` pascal
1702+type
1703+ TsPageOrientation = (spoPortrait, spoLandscape);
1704+
1705+ TsPrintOption = (poPrintGridLines, poPrintHeaders, poPrintPagesByRows,
1706+ poMonochrome, poDraftQuality, poPrintCellComments, poDefaultOrientation,
1707+ poUseStartPageNumber, poCommentsAtEnd, poHorCentered, poVertCentered,
1708+ poDifferentOddEven, poDifferentFirst, poFitPages);
1709+
1710+ TsPrintOptions = set of TsPrintOption;
1711+
1712+ TsHeaderFooterSectionIndex = (hfsLeft, hfsCenter, hfsRight);
1713+
1714+ TsCellRange = record
1715+ Row1, Col1, Row2, Col2: Cardinal;
1716+ end;
1717+
1718+ TsPageLayout = class
1719+ ...
1720+ public
1721+ ...
1722+ { Methods }
1723+ // embedded header/footer images
1724+ procedure AddHeaderImage(AHeaderIndex: Integer;
1725+ ASection: TsHeaderFooterSectionIndex; const AFilename: String);
1726+ procedure AddFooterImage(AFooterIndex: Integer;
1727+ ASection: TsHeaderFooterSectionIndex; const AFilename: String);
1728+ procedure GetImageSections(out AHeaderTags, AFooterTags: String);
1729+ function HasHeaderFooterImages: Boolean;
1730+
1731+ // Repeated rows and columns
1732+ function HasRepeatedCols: Boolean;
1733+ function HasRepeatedRows: Boolean;
1734+ procedure SetRepeatedCols(AFirstCol, ALastCol: Cardinal);
1735+ procedure SetRepeatedRows(AFirstRow, ALastRow: Cardinal);
1736+
1737+ // print ranges
1738+ function AddPrintRange(ARow1, ACol1, ARow2, ACol2: Cardinal): Integer; overload;
1739+ function AddPrintRange(const ARange: TsCellRange): Integer; overload;
1740+ function GetPrintRange(AIndex: Integer): TsCellRange;
1741+ function NumPrintRanges: Integer;
1742+ procedure RemovePrintRange(AIndex: Integer);
1743+
1744+ { Properties }
1745+ property Orientation: TsPageOrientation read FOrientation write FOrientation;
1746+ property PageWidth: Double read FPageWidth write FPageWidth;
1747+ property PageHeight: Double read FPageHeight write FPageHeight;
1748+ property LeftMargin: Double read FLeftMargin write FLeftMargin;
1749+ property RightMargin: Double read FRightMargin write FRightMargin;
1750+ property TopMargin: Double read FTopMargin write FTopMargin;
1751+ property BottomMargin: Double read FBottomMargin write FBottomMargin;
1752+ property HeaderMargin: Double read FHeaderMargin write FHeaderMargin;
1753+ property FooterMargin: Double read FFooterMargin write FFooterMargin;
1754+ property StartPageNumber: Integer read FStartPageNumber write SetStartPageNumber;
1755+ property ScalingFactor: Integer read FScalingFactor write SetScalingFactor;
1756+ property FitHeightToPages: Integer read FFitHeightToPages write SetFitHeightToPages;
1757+ property FitWidthToPages: Integer read FFitWidthToPages write SetFitWidthToPages;
1758+ property Copies: Integer read FCopies write FCopies;
1759+ property Options: TsPrintOptions read FOptions write FOptions;
1760+ property Headers[AIndex: Integer]: String read GetHeaders write SetHeaders;
1761+ property Footers[AIndex: Integer]: String read GetFooters write SetFooters;
1762+ property RepeatedCols: TsRowColRange read FRepeatedCols;
1763+ property RepeatedRows: TsRowColRange read FRepeatedRows;
1764+ property PrintRange[AIndex: Integer]: TsCellRange read GetPrintRange;
1765+ property FooterImages[ASection: TsHeaderFooterSectionIndex]: TsHeaderFooterImage read GetFooterImages;
1766+ property HeaderImages[ASection: TsHeaderFooterSectionIndex]: TsHeaderFooterImage read GetHeaderImages;
1767+ end;
1768+
1769+ TsWorksheet = class
1770+ ...
1771+ public
1772+ property PageLayout: TsPageLayout;
1773+ ...
1774+ end;
1775+```
1776+
1777+> **Note:** The fact that the `PageLayout` belongs to the worksheet indicates that there can be several page layouts in the same workbook, one for each worksheet.
1778+
1779+- **Orientation** defines the orientation of the printed paper, either portrait or landscape.
1780+
1781+- **Page width** and **page height** refer to the standard orientation of the paper, usually portrait orientation.
1782+
1783+- **Left**, **top**, **right** and **bottom margins** are self-explanatory and are given in millimeters.
1784+
1785+- **HeaderMargin** is understood - like in Excel - as the distance between the paper top edge and the top of the header, and **TopMargin** correspondingly is the distance between the top paper edge and the top of the first table row, i.e. if the header contains several line breaks it can reach into the the table part of the print-out. This is different from OpenDocument files where the header can grow accordingly.
1786+
1787+- **StartPageNumber** should be altered if the print-out should not begin with page 1. This setting requires to add the option `poUseStartPageNumber` to the PageLayout's `Options` - but this is normally done automatically.
1788+
1789+- The **ScalingFactor** is given in percent and can be used to reduce the number of printed pages. Modifying this property clear the option `poFitToPages` from the PageLayout's `Options`.
1790+
1791+- Alternatively to ScalingFactor, you can also use **FitHeightToPages** or **FitWidthToPages**. The option `poFitToPages` must be active in order to override the `ScalingFactor`setting. `FitHeightToPages` specifies the number of pages onto which the entire height of the printed worksheet should fit. Accordingly, `FitWidthToPages` can be used to define the number of pages on which the entire width of the worksheet has to fit. The value `0` has the special meaning of "use as many pages as needed". In this way, the setting "Fit all columns on one page" of Excel, for example, can be achieved by this code:
1792+
1793+``` pascal
1794+ MyWorksheet.PageLayout.Options := MyWorksheet.PageLayout.Options + [poFitPages];
1795+ MyWorksheet.PageLayout.FitWidthToPages := 1; // all columns on one page width
1796+ MyWorksheet.PageLayout.FitHeightToPages := 0; // use as many pages as needed
1797+```
1798+
1799+- **Header rows and columns repeated on every printed page** can be defined by the `RepeatedCols` and `RepeatedRows` records; their elements `FirstIndex` and `LastIndex` refer to the indexes of the first and last column or row, respectively, to be repeated. Use the methods `SetRepeatedCols` and `SetRepeatedRows` to define these numbers. Note that the second parameter for the last index can be omitted to use only a single header row or column.
1800+
1801+- **Print ranges** or **print areas** (using Excel terminology) can be used to restrict printing only to a range of cells. Use the methods `AddPrintRange` to define a cell range for printing: specify the indexes of the left column, top row, right column and bottom row of the range to be printed. A worksheet can contain several print ranges.
1802+
1803+- **Copies** specifies how often the worksheet will be printed.
1804+
1805+- The **Options** define further printing properties, their names are self-explaining. They were defined according to Excel files, some of them do not exist in ODS files and are ignored there.
1806+
1807+#### Headers and footers
1808+
1809+**Header and footer texts** can be composed of left-aligned, centered and right-aligned strings. Add the symbol `&L` to indicate that the following string is to be printed as the left-aligned part; use `&C` accordingly for the centered and `&R` for the right-aligned parts. There are other symbols which will be replaced by their counterparts during printing:
1810+
1811+- `&L`: begins the **left-aligned section** of a header or a footer text definition
1812+- `&C`: begins the **centered section** of a header or a footer text definition
1813+- `&R`: begins the **right-aligned section** of a header or a footer text definition
1814+- `&P`: **page number**
1815+- `&N`: **page count**
1816+- `&D`: current **date** of printing
1817+- `&T`: current **time** of printing
1818+- `&A`: **worksheet name**
1819+- `&F`: **file name** without path
1820+- `&P`: **file path** without file name
1821+- `&G`: embedded **image** - use the methods `AddHeaderImage` or `AddFooterImage` to specify the image file; this also appends the `&G` to the other codes of the current header/footer section. Note that not all image types known by the Office application may be accepted. Currently the image can be *jpeg*, *png*, *gif*, *bmp*, *tiff*, *pcx*, *svg*, *wmf* or *emf*.
1822+- `&B`: **bold** on/off
1823+- `&I`: **italic** on/off
1824+- `&U`: **underlining** on/off
1825+- `&E`: **double-underlining** on/off
1826+- `&S`: **strike-out** on/off
1827+- `&H`: **shadow** on/off
1828+- `&O`: **outline** on/off
1829+- `&X`: **superscript** on/off
1830+- `&Y`: **subscript** on/off
1831+- `&"font"`: begin using of the **font** with the specified name, e.g. `&"Arial"`
1832+- `&number`: begin using of the specified **font size** (in points), e.g. `&16`
1833+- `&Krrggbb`: switch to the **font color** specified to the binary value of the specified color, e.g. use `&KFF0000` for red.
1834+
1835+The arrays `Headers[]`/`Footers[]` provide space for usage of three different headers or footers:
1836+
1837+- `Headers[0]` refers to the header used on the **first page** only, similarly for `Footers[0]`. Instead of index `0` you can use the constant `HEADER_FOOTER_INDEX_FIRST`. Leave this string empty if there is no special first-page header/footer.
1838+- `Headers[1]` refers to the header on pages with **odd page numbers**, similarly for `Footers[1]`. Instead of index `1` you may want to use the constant `HEADER_FOOTER_INDEX_ODD`.
1839+- `Headers[2]` refers to the header on lages with **even page nubmers**, similarly for `Footers[2]`. Instead of index `2` you may want to use the constant `HEADER_FOOTER_INDEX_EVEN`.
1840+
1841+Leave the strings at index 0 and 2 empty if the print-out should always have the same header/footer. You can use the constant `HEADER_FOOTER_INDEX_ALL` for better clarity. Example:
1842+
1843+``` pascal
1844+ MyWorksheet.PageLayout.Headers[HEADER_FOOTER_INDEX_ALL] := '&C&D &T'; // centered "date time" on all pages as header
1845+ MyWorksheet.PageLayout.Footers[HEADER_FOOTER_INDEX_ODD] := '&RPage &P of &N'; // right-aligned "Page .. of ..." on odd pages as footer
1846+ MyWorksheet.PageLayout.Footers[HEADER_FOOTER_INDEX_EVEN] := '&LPage &P of &N'; // dto, but left-aligned on even pages
1847+```
1848+
1849+### Protection
1850+
1851+In the Office applications, workbooks can be protected from unintentional changes by the user. fpspreadsheet is able to read and write the data structures related to protection, but does not enforce them. This means, for example, that cells can be modified by the user although the worksheet is specified as being locked.
1852+
1853+Protection is handled at three levels: workbook protection, worksheet protection and cell protection.
1854+
1855+#### Workbook protection
1856+
1857+`TsWorkbook` contains a set of workbook or document protection options:
1858+
1859+- `bpLockRevision`: specifies that the workbook is locked for revisions
1860+- `bpLockStructure`: if this option is set then worksheets in the workbook cannot be moved, deleted, hidden, unhidden, or renamed, and new worksheets cannot be inserted.
1861+- `bpLockWindows`: indicates that the workbook windows in the Office application are locked. Windows are the same size and position each time the workbook is opened by the Office application.
1862+
1863+In relation to workbook protection is the worksheet option `soPanesProtection` which prevents the panes of a worksheet from being modified if the workbook is protected.
1864+
1865+Depending on the file format, only some of these options might be supported. In these cases, the non-supported options are commonly accepted default values.
1866+
1867+#### Worksheet protection
1868+
1869+`TsWorksheet` houses a similar set of protection options. Whenever an option is included in the set `Protection` of the workbook the corresponding action is not allowed and locked:
1870+
1871+- `spCells`: the cells in the sheet are protected. It depends on the level of cell protection whether a particular cell can be changed or not. By default, no cell can be changed.
1872+- `spDeleteColumns`: deleting of columns is not be allowed
1873+- `spDeleteRows`: it is not possible to delete rows
1874+- `spFormatCells`: formatting of cells is not allowed
1875+- `spFormatColumns`: columns cannot be formatted.
1876+- `spFormatRows`: rows cannot be formatted
1877+- `spInsertColumns`: it is not allowed to insert columns
1878+- `spInsertRows`: rows cannot be inserted
1879+- `spInsertHyperlinks`: it is not possible to insert new hyperlinks
1880+- `spSort`: the worksheet is not allowed to be sorted.
1881+- `spSelectLockedCells`: Cells which are locked cannot be selected any more.
1882+- `spSelectUnlockedCells`: Even cells which are unlocked cannot be selected. Together with `spSelectLockedCells` this means that the selection in the worksheet is frozen.
1883+
1884+These levels of protection become active if the option `soProtected` is added to the worksheet's `Options`, or by calling the worksheet method `Protect(true)`.
1885+
1886+#### Cell protection
1887+
1888+Cell protection becomes active when the worksheet protection is enabled. It is controlled by a set of `TsCellProtection` elements which belong to the cell format record:
1889+
1890+- `cpLockCell`: This option determines whether cell content can be modified by the user. Since it is on by default cells of a protected worksheet normally cannot be edited. In order to unlock some cells for user input the option `cpLockCell` must be removed from the protection of these cells.
1891+- `cpHideFormulas`: prevents formulas from being shown in the Office application.
1892+
1893+Cell protection can be changed by calling the worksheet method `WriteCellProtection`. Conversely, `ReadCellProtection` can be used to retrieve the protection state of a particular cell:
1894+
1895+``` pascal
1896+// query and modifiy the protection state of cell A1 (row=0, col=0)
1897+var
1898+ cell: PCell;
1899+ cellprot: TsCellProtections;
1900+...
1901+ // Find the cell
1902+ cell := worksheet.FindCell(0, 0);
1903+ // query cell protection
1904+ cellprot := worksheet.ReadCellProtection(cell);
1905+ // Unlock the cell for editing, don't change the visibility of formulas
1906+ worksheet.WriteCellProtection(cell, cellprot - [cpLockCell]);
1907+ // Hide formula of the cell and unlock the cell.
1908+ worksheet.WriteCellProtection(cell, [cpHideFormulas]);
1909+```
1910+
1911+#### Passwords
1912+
1913+Workbook and worksheet protection can be secured by passwords. Note that these passwords do not encrypt the file (except for workbook protection in Excel 2007). In the Office applications the user must enter this password to turn off protection or to change protection items. The encrypted password is stored in the `CryptoInfo` record of the wordbook and the worksheets, respectively:
1914+
1915+``` pascal
1916+type
1917+ TsCryptoInfo = record
1918+ PasswordHash: String;
1919+ Algorithm: TsCryptoAlgorithm; // caExcel, caSHA1, caSHA256, etc.
1920+ SaltValue: String;
1921+ SpinCount: Integer;
1922+ end;
1923+```
1924+
1925+> **Warning:** FPSpreadsheet does not perform any hashing calculations, the `CryptoInfo` record is just passed through from reading to writing. This causes problems when different file formats are involved in reading and writing. It is attempted to detect **incompatible combinations**. In these cases, the **password protection is removed**, and an error is logged by the workbook.
1926+
1927+### Loading and saving
1928+
1929+#### Adding new file formats
1930+
1931+FPSpreadsheet is open to any spreadsheet file format. In addition to the built-in file formats which are specified by one of the `sfXXXX` declarations, it is possible to provide dedicated reader and writer units to get access to special file formats.
1932+
1933+- Write a unit implementing a reader and a writer for the new file format. They must inherit from the basic `TsCustomSpreadReader` and `TsCustomWriter`, respectively, - both are implemented in unit *fpsReaderWriter* -, or from one of the more advanced ones belonging to the built-in file formats.
1934+- Register the new reader/writer by calling the function `RegisterSpreadFileFormat` in the `initialization` section of this unit (implemented in unit *fpsRegFileFormats*):
1935+
1936+``` pascal
1937+function RegisterSpreadFormat(AFormat: TsSpreadsheetFormat; AReaderClass: TsSpreadReaderClass; AWriterClass: TsSpreadWriterClass;
1938+ AFormatName, ATechnicalName: String; const AFileExtensions: array of String): TsSpreadFormatID;
1939+```
1940+
1941+- `AFormat` must have the value `sfUser` to register an external file format.
1942+- `AReaderClass` is the class of the reader (or nil, if reading functionality is not implemented).
1943+- `AWriterClass` is the class of the writer (or nil, if writing functionality is not implemented).
1944+- `AFormatName` defines the name of the format as used for example in the filter list of file-open dialogs.
1945+- `ATechnicalName` defines a shorter format name.
1946+- `AFileExtensions` is an array of file extensions used in the files. The first array element denotes the default extension. The extensions must begin with a period as in `.xls`.
1947+- The registration function returns a numerical value (`TsSpreadFormatID`) which can be used as format identifier in the workbook reading and writing functions which exist in overloaded version accepting a numerical value for the format specifier. In contract to the built-in formats the FormatID is negative.
1948+- Finally, in your application, add the new unit to the `uses` clause. This will call the registrations function when the unit is loaded and make the new file format available to FPSpreadsheet.
1949+
1950+#### Stream selection
1951+
1952+Workbooks are loaded and saved by means of the `ReadFromFile` and `WriteToFile` methods, respectively (or by their stream counterparts, `ReadFromStream` and `WriteToStream`).
1953+
1954+By default, the data files are accessed by means of **memory streams** which yields the fastest access to the files. In case of very large files (e.g. tens of thousands of rows), however, the system may run out of memory. There are two methods to defer the memory overflow by some extent.
1955+
1956+- Add the element `boBufStream` to the workbook's `Options`. In this case, a **"buffered" stream** is used for accessing the data. This kind of stream holds a memory buffer of a given size and swaps data to file if the buffer becomes too small.
1957+- Add the element `boFileStream` to the workbook's `Options`. This option avoids memory streams altogether and creates temporary **files** if needed. This is, however, the slowest method of data access.
1958+- If both options are set then `boBufStream` is ignored.
1959+- In practice, however, the effect of the selected streams is not very large if memory is to be saved.
1960+
1961+#### Virtual mode
1962+
1963+Beyond the transient memory usage during reading/writing the main memory consumptions originates in the internal structure of FPSpreadsheet which holds all data in memory. To overcome this limitation, a "virtual mode" has been introduced. In this mode, data are received from a data source (such as a database table) and are passed through to the writer without being collected in the worksheet. It is clear that data loaded in virtual mode cannot be displayed in the visual controls. Virtual mode is good for conversion between different data formats.
1964+
1965+These are the steps required to use this mode:
1966+
1967+- Activate virtual mode by adding the option `boVirtualMode` to the `Options` of the workbook.
1968+- Tell the spreadsheet writer how many rows and columns are to be written. The corresponding worksheet properties are `VirtualRowCount` and `VirtualColCount`.
1969+- Write an event handler for the event `OnWriteCellData` of the worksheet. This handler gets the index of row and column of the cell currently being saved. You have to return the value which will be saved in this cell. You can also specify a template cell that physically exists in the workbook from which the formatting style is copied to the destination cell. Please be aware that when exporting a database, you are responsible for advancing the dataset pointer to the next database record when writing of a row is complete.
1970+- Call the `WriteToFile` method of the workbook.
1971+
1972+Virtual mode also works for reading spreadsheet files.
1973+
1974+The folder *example/other* contains a worked out sample project demonstrating virtual mode using random data. More realistic database examples are in *example/db_import_export* and in the chapter on converting a large database table using virtual mode.
1975+
1976+### Dataset export
1977+
1978+FPC contains a set of units that allow you to export datasets to various formats (XML, SQL statements, DBF files,...). There is a master package that allows you to choose an export format at design time or run time (Lazarus package lazdbexport).
1979+
1980+FPSpreadsheet has `TFPSExport` which plugs into this system. It allows you to export the contents of a dataset to a new spreadsheet (*.xls*, *.xlsx*, *.ods*, wikitable format) file into a table on the first sheet by default. In addition, if `MultipleSheets` is set to `TRUE` it is possible to combine several sheets into individual worksheets in the same file. You can optionally include the field names as header cells on the first row using the `HeaderRow` properties in the export settings. The export component tries to find the number format of the cells according to the dataset field types.
1981+
1982+For more complicated exports, you need to manually code a solution (see examples below) but for simple data transfer/dynamic exports at user request, this unit will probably be sufficient.
1983+
1984+A simple example of how this works:
1985+
1986+``` pascal
1987+uses
1988+...
1989+fpsexport
1990+...
1991+var
1992+ Exp: TFPSExport;
1993+ ExpSettings: TFPSExportFormatSettings;
1994+ TheDate: TDateTime;
1995+begin
1996+ FDataset.First; //assume we have a dataset called FDataset
1997+ Exp := TFPSExport.Create(nil);
1998+ ExpSettings := TFPSExportFormatSettings.Create(true);
1999+ try
2000+ ExpSettings.ExportFormat := efXLS; // choose file format
2001+ ExpSettings.HeaderRow := true; // include header row with field names
2002+ Exp.FormatSettings := ExpSettings; // apply settings to export object
2003+ Exp.Dataset:=FDataset; // specify source
2004+ Exp.FileName := 'c:\temp\datadump.xls';
2005+ Exp.Execute; // run the export
2006+ finally
2007+ Exp.Free;
2008+ ExpSettings.Free;
2009+ end;
2010+```
2011+
2012+#### Export to DBF
2013+
2014+You can save the information from Excel to dbf rather easily. Here is the example from forum. Please note that this example is supposed to work with Win1251 encoding by default. To get more information please refer to this thread [1](http://forum.lazarus.freepascal.org/index.php/topic,41636.0.html)
2015+
2016+``` pascal
2017+procedure TForm1.ExportToDBF(AWorksheet: TsWorksheet; AFileName: String);
2018+var
2019+ i: Integer;
2020+ f: TField;
2021+ r, c: Cardinal;
2022+ cell: PCell;
2023+begin
2024+ DbfGlobals.DefaultCreateCodePage := 1251; //default encoding of the dbf
2025+ DbfGlobals.DefaultOpenCodePage := 1251; //default encoding of the dbf
2026+ if Dbf1.Active then Dbf1.Close;
2027+ if FileExists(AFileName) then DeleteFile(AFileName);
2028+
2029+ Dbf1.FilePathFull := ExtractFilePath(AFileName);
2030+ Dbf1.TableName := ExtractFileName(AFileName);
2031+ Dbf1.TableLevel := 25; // DBase IV: 4 - most widely used; or 25 = FoxPro supports nfCurrency
2032+ Dbf1.LanguageID := $C9; //russian language by default
2033+ Dbf1.FieldDefs.Clear;
2034+ //below are the fields in excel
2035+ Dbf1.FieldDefs.Add('fam', ftString);
2036+ //add other fields you want to save
2037+
2038+ Dbf1.CreateTable;
2039+ Dbf1.Open;
2040+
2041+ for f in Dbf1.Fields do
2042+ f.OnGetText := @DbfGetTextHandler;
2043+
2044+ // Skip row 0 which contains the headers
2045+ for r := 1 to AWorksheet.GetLastRowIndex do begin
2046+ Dbf1.Append;
2047+ for c := 0 to Dbf1.FieldDefs.Count-1 do begin
2048+ f := Dbf1.Fields[c];
2049+ cell := AWorksheet.FindCell(r, c);
2050+ if cell = nil then
2051+ f.Value := NULL
2052+ else
2053+ case cell^.ContentType of
2054+ cctUTF8String: f.AsString := UTF8ToCP1251(cell^.UTF8StringValue);
2055+ cctNumber: f.AsFloat := cell^.NumberValue;
2056+ cctDateTime: f.AsDateTime := cell^.DateTimeValue;
2057+ else f.AsString := UTF8ToCP1251(AWorksheet.ReadAsText(cell));
2058+ end;
2059+ end;
2060+ Dbf1.Post;
2061+ end;
2062+end;
2063+
2064+//This procedure is called so the text in the cells could be correctly dispayed on WorkSheetGrid on the form, otherwise '?' symbols showing
2065+procedure TForm1.DbfGetTextHandler(Sender: TField; var AText: string; DisplayText: Boolean);
2066+begin
2067+ if DisplayText then
2068+ AText := CP1251ToUTF8(Sender.AsString);
2069+end;
2070+```
2071+
2072+## Visual controls for FPSpreadsheet
2073+
2074+The package **laz_fpspreadsheet_visual** implements a series of controls which simiplify creation of visual GUI applications:
2075+
2076+- **TsWorkwookSource** links the controls to a workbook and notifies the controls of changes in the workbook.
2077+- **[[TsWorksheetGrid]]** implements a grid control with editing and formatting capabilities; it can be applied in a similar way to TStringGrid.
2078+- **TsWorkbookTabControl** provides a tab sheet for each worksheet of the workbook. It is the ideal container for a [[TsWorksheetGrid]].
2079+- **TsWorksheetIndicator**: a combobox which lists all worksheets of the workbook.
2080+- **TsCellEdit** corresponds to the editing line in Excel or Open/LibreOffice. Direct editing in the grid, however, is possible as well.
2081+- **TsCellIndicator** displays the name of the currently selected cell; it can be used for navigation purposes by entering a cell address string.
2082+- **TsCellCombobox** offers to pick cell properties for a selection of formatting attributes: font name, font size, font color, background color.
2083+- **TsSpreadsheetInspector** is a tool mainly for debugging; it displays various properties of workbook, worksheet, cell value and cell formatting, similar to the ObjectInspector of Lazarus. It is read-only, though.
2084+- Various standard actions are provided in the unit **fpsActions**. Applied to menu or toolbar, they simplify typical formatting and editing tasks without having to write a line of code.
2085+- **TsWorkbookChartSource** interfaces a workbook with the [[TAChart]] library. It defines the cell ranges from which a Chart series can get its data. There is also an older component, [[TsWorksheetChartSource]], which requires all cells to be from the same worksheet. For this reason, it has not been fully integrated into the environment of FPSpreadsheet controls and will be removed from the library in the future.
2086+
2087+See the [[FPSpreadsheet tutorial: Writing a mini spreadsheet application]] for more information and a tutorial, and see demo projects for examples of the application of these components.
2088+
2089+## Examples
2090+
2091+Please see [[FPSpreadsheet: Examples]] for a variety of code examples.
2092+
2093+## Download
2094+
2095+### Subversion
2096+
2097+You can download FPSpreadsheet using the subversion software and the following command line:
2098+
2099+``` bash
2100+svn checkout https://svn.code.sf.net/p/lazarus-ccr/svn/components/fpspreadsheet fpspreadsheet
2101+```
2102+
2103+#### SVN change log
2104+
2105+- Implementation of conditional formats for ods, xlsx and Excel xml.
2106+- Implementation of meta data for ods, xlsx and Excel xml.
2107+
2108+#### Incompatible changes
2109+
2110+- Removed the deprecated worksheet properties DefaultRowHeight and DefaultColWidth. Use the corresponding Read/Write routines instead (ReadDefaultColWidth(units), WriteDefaultColWidth(units)).
2111+
2112+### Stable releases
2113+
2114+You can find all releases of FPSpreadsheet on [sourceforge](https://sourceforge.net/projects/lazarus-ccr/files/FPSpreadsheet/).
2115+
2116+#### Version 1.12
2117+
2118+###### Change log (with respect to v1.10x)
2119+
2120+- **Hide** (and unhide) rows and columns.
2121+- Enforce **Page breaks** before rows and columns during printing by the Office applications.
2122+- Full support (reading and writing) of the **ExcelXML** xml format (Excel 2003 and XP).
2123+- Support of the color of worksheet tabs (Worksheet.TabColor) in xls biff8, xlsx and ods formats. The property is ignored by the visual WorkbookTabControl, though.
2124+- Add TsWorksheetIndicator to visual controls.
2125+
2126+#### Version 1.10.1
2127+
2128+This is the latest stable release.
2129+
2130+###### Change log (with respect to v1.8x)
2131+
2132+- **Workbook, worksheet and cell protection** (read/write in BIFF2/BIFF5/BIFF8/OOXML/ODS, write in ExcelXML).
2133+- New package **laz_fpspreadsheet_crypto** to decipher the encryption for worksheet-protection in xls files. Requires DCPcrypt.
2134+- TsWorksheetGrid can **display embedded images**.
2135+- **Drag and drop** in TsWorksheetGrid
2136+- New, **highDPI-aware** component palette icons.
2137+- New workbook optiond **boAbortReadingOnFormulaError** and **boIgnoreFormulas**.
2138+- Formulas with **references to other sheets**, i.e. `'=Sheet1!A1+Sheet2!A2'`
2139+
2140+###### Incompatible changes
2141+
2142+- The field **FormulaValue** has been removed from the cell record. The cell formula now can be retrieved by calling `Worksheet.ReadFormula(cell)`.
2143+
2144+#### Version 1.8
2145+
2146+###### Change log (with respect to v1.6x)
2147+
2148+- **"Rich-text" formatting** of label cells, i.e. assignment different fonts to groups of characters within the cell text. For this purpose, HTML codes (such as `<B>...</B>`) can be embedded in the cell text to identify the parts with different font (--\> `TsWorksheet.WriteTextAsHTML`).
2149+- **Searching** for cells with specified content in worksheet or workbook.
2150+- Support for reading and writing of **HTML format**
2151+- Support for writing of the **ExcelXML format** (Excel XP and 2003)
2152+- Ability to use **user-provided file reader/writer classes** to extend FPSpreadsheet to new file formats.
2153+- Readers and writers now support all the **line styles** of Excel8 and OOXML.
2154+- xls, xlsx and ods readers/writers now support the **active worksheet** and **selected cell**.
2155+- Ability to write to/read from the system's **clipboard** for copy & paste using the visual controls.
2156+- Support for **print ranges** and **repeated header rows and columns** in the Office applications.
2157+- Support for **embedded images** (currently only writing to xlsx and ods, no reading).
2158+- Improved compatibility of **TsWorksheetGrid** with TStringGrid (`Cells[Col,Row]` property). Standalone application as an advanced StringGrid replacement.
2159+- Support for **Right-to-left mode** in TsWorksheetGrid. In addition to the system-wide RTL mode, there are also parameters `BiDiMode` in the Worksheet and cells allowing to controls text direction at worksheet and cell level individually, like in Excel or LibreOffice Calc.
2160+- Support of several **units** for specification of column widths and row heights.
2161+- The library now supports **localization** using po files. Translations are welcome.
2162+- **Zoom factor** read and written by the worksheet, and applied by the TsWorksheetGrid.
2163+- Support of **column and row formats**
2164+- Support of **hidden** worksheets
2165+
2166+###### Incompatible changes
2167+
2168+- VirtualMode was changed in order to be able to treat worksheets of the same workbook differently. `VirtualRowCount` and `VirtualColCount` are now properties of the worksheet, and similarly, the event handler `OnWriteCellData`. In older versions, these properties had belonged to the workbook.
2169+- The worksheet methods `ReadAsUTF8Text` and `WriteUTF8Text` have been renamed to `ReadAsText` and `WriteText`, respectively. The old ones are still available and marked as deprecated; they will be removed in later versions.
2170+- The public properties of `TsWorksheetGrid` using a `TRect` as parameter were modified to use the Left, Top, Right, Bottom values separately.
2171+- The `PageLayout` is a class now, no longer a record. As a consequence, some array properties cannot be set directly any more, use the corresponding methods instead.
2172+- Most of the predefined color constants were marked as deprecated; only the basic EGA colors will remain.
2173+- Unit fpsNumFormatParser is integrated in fpsNumFormat. Old code which "uses" fpsNumFormatParser must "use" fpsNumFormat now.
2174+- The source files of the laz_fpspreadsheet, laz_fpspreadsheet_visual and laz_fpspreadsheetexport_visual packages have been moved to separate folders in order to resolve some occasional compilation issues. Projects which do not use the packages but the path to the sources must adapt the paths.
2175+
2176+#### Version 1.6
2177+
2178+###### Change log (with respect to v1.4.x)
2179+
2180+- TsWorkbookChartSource is a new component which facilitates creation of charts from non-contiguous spreadsheet data in various worksheets. It interfaces to a workbook via tha WorkbookSource component. In the long run, it will replace the older TsWorksheetChartSource which required contiguous x/y data blocks in the same worksheet.
2181+- Major reconstruction of the cell record resulting in strong reduction of memory consumption per cell (from about 160 bytes per cell down to about 50)
2182+- Implementation of a record helper for the TCell which simplifies cell formatting (no need to set a bit in UsedFormattingFields any more, automatic notification of visual controls)
2183+- Comments in cells
2184+- Background fill patterns
2185+- Hyperlinks
2186+- Enumerators for worksheet's internal AVLTrees for faster iteration using a for-in loop.
2187+- Formatting of numbers as fractions.
2188+- Improved number format parser for better recognition of Excel-like number formats.
2189+- Page layout (page margins, headers, footer, used for only when printing in the Office applications - no direct print support in fpspreadsheet!)
2190+- Improved color management: no more palettes, but direct rgb colors. More pre-defined colors.
2191+- A snapshot of the wiki documentation is added to the library as chm help file.
2192+
2193+###### Incompatible changes
2194+
2195+- All type declarations and constants are moved from fpspreadsheet.pas to the new unit **fpstypes.pas**. Therefore, most probably, this unit has to be added to the uses clause.
2196+- Because fpspreadsheet supports now **background** fill patterns the cell property `BackgroundColor` has been replaced by `Background`. Similarly, the `UsedFormattingFields` flag `uffBackgroundColor` is called `uffBackground` now.
2197+- Another `UsedFormattingFields` flag has been dropped: **`uffBold`**. It is from the early days of fpspreadsheet and has become obsolete since the introduction of full font support. For achieving a bold type-face, now call `MyWorksheet.WriteFont(row, col, BOLD_FONTINDEX)`, or `Myworksheet.WriteFontStyle(row, col, [fssBold])`.
2198+- **Iteration through cells** using the worksheet methods `GetFirstCell` and `GetNextCell` has been removed - it failed if another iteration of this kind was called within the loop. Use the new for-in syntax instead.
2199+- Support for **shared formulas** has been reduced. The field `SharedFormulaBase` has been deleted from the TCell record, and methods related to shared formulas have been removed from TsWorksheet. Files containing shared formulas can still be read, the shared formulas are converted to multiple normal formulas.
2200+- The **color palettes** of previous versions have been abandoned. `TsColor` is now a `DWord` representing the rgb components of a color (just like TColor does in the *graphics* unit), it is not an index into a color palette any more. The values of pre-defined colors, therefore, have changed, their names, however, are still existing. The workbook functions for palette access have become obsolete and were removed.
2201+
2202+#### Version 1.4
2203+
2204+###### Change log (with respect to v1.2.x)
2205+
2206+- Full support for **string formulas**; calculation of RPN and string formulas for all built-in formulas either directly or by means of registration mechanism. Calculation occurs when a workbook is saved (activate workbook option `boCalcBeforeSaving`) or when cell content changes (active workbook option `boAutoCalc`).
2207+- **Shared formulas** (reading for sfExcel5, sfExcel8, sfOOXML; writing for sfExcel2, sfExcel5, sfExcel8).
2208+- Significant **speed-up** of writing of large spreadsheets for the xml-based formats (ods and xlsx), speed up for biff2; **speedtest demo** program
2209+- **VirtualMode** allowing to read and write very large spreadsheet files without loading entire document representation into memory. Formatting of cells in VirtualMode.
2210+- Demo program for database export using virtual mode and TFPSExport.
2211+- Added db export unit allowing programmatic exporting datasets using **TFPSExport**. Similar export units are e.g. [[fpdbfexport]], [[fpXMLXSDExport]].
2212+- Reader for **xlsx** files, now fully supporting the same features as the other readers.
2213+- Reader/writer for **CSV files** based on [[CsvDocument]].
2214+- **Wikitables writer** supports now most of the fpspreadsheet formatting options (background color, font style, font color, text alignment, cell borders/line styles/line colors, merged cells, column widths, row heights); new "wikitablemaker" demo
2215+- **Insertion and deletion of rows and columns** into a worksheet containing data.
2216+- Implementation of **sorting** of a worksheet.
2217+- Support of **diagonal "border" lines**
2218+- **Logging of non-fatal error messages** during reading/writing (TsWorksheet.ErrorMsg)
2219+- **Merged** cells
2220+- **Registration** of currency strings for automatic conversion of strings to **currency values**
2221+- A set of **visual controls** (TsWorkbookSource, TsWorkbookTabControl, TsSpreadsheetInspector, TsCellEdit, TsCellIndicator, TsCellCombobox, in addition to the already-existing TsWorksheetGrid) and pre-defined standard actions to facilitate [[FPSpreadsheet tutorial: Writing a mini spreadsheet application|creation of GUI applications]].
2222+- **Overflow cells** in TsWorksheetGrid: label cells with text longer than the cell width extend into the neighboring cell(s).
2223+
2224+###### Incompatible changes
2225+
2226+- The option `soCalcBeforeSaving` now belongs to the workbook, no longer to the worksheet, and has been renamed to `boCalcBeforeSaving` (it controls automatic calculation of formulas when a workbook is saved).
2227+- The workbook property `ReadFormulas` is replaced by the option flag `boReadFormulas`. This means that you have to add this flag to the workbook's `Options` in order to activate reading of formulas.
2228+- With full support of string formulas some features related to RPN formulas were removed:
2229+ - The field `RPNFormulaResult` of TCell was dropped, as well as the element `cctRPNFormula` in the `TsContentType` set.
2230+ - Sheet function identifiers were removed from the `TsFormulaElement` set, which was truncated after `fekParen`.
2231+ - To identify a sheet function, its name must be passed to the function `RPNFunc` (instead of using the now removed `fekXXXX` token). In the array notation of the RPN formula, a sheet function is identified by the new token `fekFunc`.
2232+ - The calling convention for registering user-defined functions was modified. It now also requires the Excel ID of the function (see "OpenOffice Documentation of Microsoft Excel Files", section 3.11, or unit *xlsconst* containing all token up to ID 200 and some above).
2233+ - Code related to RPN formulas was moved to a separate unit, `fpsRPN`. Add this unit to the uses clause if you need RPN features.
2234+
2235+#### Wiki documentation of old releases
2236+
2237+This wiki page is work in progress and updated whenever a new feature is added; therefore, its state corresponds to the svn trunk version of the package. If you work with an older stable version please use these "historic" wiki versions:
2238+
2239+- Version 1.12: \[<http://wiki.lazarus.freepascal.org/index.php?title=FPSpreadsheet&oldid=118771> <https://wiki.lazarus.freepascal.org/index.php?title=FPSpreadsheet&oldid=136886>}
2240+- Version 1.10.1: [<http://wiki.lazarus.freepascal.org/index.php?title=FPSpreadsheet&oldid=118771>](http://wiki.lazarus.freepascal.org/index.php?title=FPSpreadsheet&oldid=118771)
2241+- Version 1.10: [wiki.lazarus.freepascal.org/index.php?title=FPSpreadsheet&oldid=118441](http://wiki.lazarus.freepascal.org/index.php?title=FPSpreadsheet&oldid=118441)
2242+- Version 1.8: [wiki.lazarus.freepascal.org/index.php?title=FPSpreadsheet&oldid=107616](http://wiki.lazarus.freepascal.org/index.php?title=FPSpreadsheet&oldid=107616)
2243+- Version 1.6.2: [wiki.lazarus.freepascal.org/index.php?title=FPSpreadsheet&oldid=100723](http://wiki.lazarus.freepascal.org/index.php?title=FPSpreadsheet&oldid=100723)
2244+- Version 1.6: [wiki.lazarus.freepascal.org/index.php?title=FPSpreadsheet&oldid=91469](http://wiki.lazarus.freepascal.org/index.php?title=FPSpreadsheet&oldid=91469)
2245+- Version 1.4: [wiki.lazarus.freepascal.org/index.php?title=FPSpreadsheet&oldid=85299](http://wiki.lazarus.freepascal.org/index.php?title=FPSpreadsheet&oldid=85299)
2246+- Version 1.2 and 1.2.1: [wiki.lazarus.freepascal.org/index.php?title=FPSpreadsheet&oldid=81375](http://wiki.lazarus.freepascal.org/index.php?title=FPSpreadsheet&oldid=81375)
2247+
2248+## Installation
2249+
2250+- If you only need non-GUI components: in Lazarus: Package/Open Package File, select **laz_fpspreadsheet.lpk**, click Compile. Now the package is known to Lazarus (and should e.g. show up in Package/Package Links). Now you can add a dependency on `laz_fpspreadsheet` in your project options and `fpspreadsheet` to the uses clause of the project units that need to use it.
2251+- If you also want GUI components ([[TsWorksheetGrid]] and [[TsWorksheetChartSource]]): Package/Open Package File, select **laz_fpspreadsheet_visual.lpk**, click Compile, then click Use, Install and follow the prompts to rebuild Lazarus with the new package. Drop needed grid/chart components on your forms as usual.
2252+- If you want to have a GUI component for dataset export: Package/Open Package File, select **laz_fpspreadsheetexport_visual.lpk**, click Compile, then click, Use, Install and follow the prompts to rebuild Lazarus with the new package. Drop needed export components from the **Data Export** tab on your forms as usual.
2253+- FPSpreadsheet is developed with the latest stable fpc version (currently fpc 3.0.2). We only occasionally check older versions.
2254+- The basic spreadsheet functionality works with Lazarus versions back to version 1.0. Some visual controls or demo programs, however, require newer versions. Please update your Lazarus if you have an older version and experience problems.
2255+
2256+### Compiler options
2257+
2258+Here is a list of **conditional defines** which can be activated in order to tweak some operating modes of the packages and/or make it compilable with older Lazarus/FPC versions:
2259+
2260+- `FPS_DONT_USE_CLOCALE`: In Unix systems, the unit `clocale` is automatically added to the uses clause of *fpspreadsheet.pas*. This unit sets up localization settings needed for locale-dependent number and date/time formats. However, this adds a dependence on the C library to the package [2](http://lazarus-ccr.sourceforge.net/docs/rtl/clocale/index.html). If this is not wanted, define `FPS_DONT_USE_CLOCALE`.
2261+- `FPS_VARISBOOL`: fpspreadsheet requires the function VarIsBool which was introduced by fpc 2.6.4. If an older FPC versions is used define `FPS_VARISBOOL`. Keep undefined for the current FPC version.
2262+- `FPS_LAZUTF8`: fpspreadsheet requires some functions from the unit LazUTF8 which were introduced by Lazarus 1.2. If an older Lazarus version is used define `FPS_LAZUTF8`. Keep undefined for the current Lazarus version.
2263+
2264+All these defines are collected in the include file *fps.inc*.
2265+
2266+## Support and Bug Reporting
2267+
2268+The recommended place to discuss FPSpreadsheet and obtain support is asking in the [Lazarus Forum](http://forum.lazarus.freepascal.org/index.php?board=49.0).
2269+
2270+Bug reports should be sent to the [Lazarus/Free Pascal Bug Tracker](http://bugs.freepascal.org/); please specify the "Lazarus-CCR" project.
2271+
2272+## Current Progress
2273+
2274+### Progress by supported cell content
2275+
2276+<table>
2277+<thead>
2278+<tr>
2279+<th>Format</th>
2280+<th>Multiple<br />
2281+sheets</th>
2282+<th>Unicode</th>
2283+<th>Reader<br />
2284+support</th>
2285+<th>Writer<br />
2286+support</th>
2287+<th>Text</th>
2288+<th>Number</th>
2289+<th>String<br />
2290+Formula</th>
2291+<th>RPN<br />
2292+Formula</th>
2293+<th>3D cell<br />
2294+references</th>
2295+<th>Date/Time</th>
2296+<th>Comments</th>
2297+<th>Hyperlinks</th>
2298+<th>Images +++</th>
2299+<th>Protection</th>
2300+<th>Conditional<br />
2301+formats</th>
2302+</tr>
2303+</thead>
2304+<tbody>
2305+<tr>
2306+<td>CSV files</td>
2307+<td style="text-align: center;">No</td>
2308+<td style="text-align: center;">Yes +</td>
2309+<td class="working">Working ++</td>
2310+<td class="working">Working ++</td>
2311+<td class="working">Working ++</td>
2312+<td class="working">Working ++</td>
2313+<td style="text-align: center;">N/A</td>
2314+<td style="text-align: center;">N/A</td>
2315+<td style="text-align: center;">N/A</td>
2316+<td class="working">Working ++</td>
2317+<td style="text-align: center;">N/A</td>
2318+<td style="text-align: center;">N/A</td>
2319+<td style="text-align: center;">N/A</td>
2320+<td style="text-align: center;">N/A</td>
2321+<td style="text-align: center;">N/A</td>
2322+</tr>
2323+<tr>
2324+<td>Excel 2.x</td>
2325+<td style="text-align: center;">No</td>
2326+<td style="text-align: center;">No *</td>
2327+<td class="working">Working **</td>
2328+<td class="working">Working</td>
2329+<td class="working">Working</td>
2330+<td class="working">Working</td>
2331+<td class="working">Working</td>
2332+<td class="working">Working ***</td>
2333+<td style="text-align: center;">N/A</td>
2334+<td class="working">Working ****</td>
2335+<td class="working">Working</td>
2336+<td style="text-align: center;">N/A</td>
2337+<td style="text-align: center;">N/A</td>
2338+<td class="working">Working</td>
2339+<td style="text-align: center;">N/A</td>
2340+</tr>
2341+<tr>
2342+<td>Excel 5.0 (Excel 5.0 and 95)</td>
2343+<td style="text-align: center;">Yes</td>
2344+<td style="text-align: center;">No *</td>
2345+<td class="working">Working **</td>
2346+<td class="working">Working</td>
2347+<td class="working">Working</td>
2348+<td class="working">Working</td>
2349+<td class="working">Working</td>
2350+<td class="working">Working ***</td>
2351+<td class="working">Working</td>
2352+<td class="working">Working ****</td>
2353+<td class="working">Working</td>
2354+<td style="text-align: center;">N/A</td>
2355+<td style="text-align: center;">N/A</td>
2356+<td class="working">Working</td>
2357+<td style="text-align: center;">N/A</td>
2358+</tr>
2359+<tr>
2360+<td>Excel 8.0 (Excel 97- 2003)</td>
2361+<td style="text-align: center;">Yes</td>
2362+<td style="text-align: center;">Yes</td>
2363+<td class="working">Working **</td>
2364+<td class="working">Working</td>
2365+<td class="working">Working</td>
2366+<td class="working">Working</td>
2367+<td class="working">Working</td>
2368+<td class="working">Working ***</td>
2369+<td class="working">Working</td>
2370+<td class="working">Working ****</td>
2371+<td class="partial">Reading only</td>
2372+<td class="working">Working</td>
2373+<td class="not working">Not working</td>
2374+<td class="working">Working</td>
2375+<td class="not working">Not working</td>
2376+</tr>
2377+<tr>
2378+<td>Excel 2003/XML</td>
2379+<td style="text-align: center;">Yes</td>
2380+<td style="text-align: center;">Yes</td>
2381+<td class="working">Working **</td>
2382+<td class="working">Working</td>
2383+<td class="working">Working</td>
2384+<td class="working">Working</td>
2385+<td class="working">Working ***</td>
2386+<td class="working">Working</td>
2387+<td class="working">Working</td>
2388+<td class="working">Working ****</td>
2389+<td class="working">Working</td>
2390+<td class="working">Working</td>
2391+<td style="text-align: center;">N/A</td>
2392+<td class="working">Working</td>
2393+<td class="working">Working</td>
2394+</tr>
2395+<tr>
2396+<td>Excel OOXML</td>
2397+<td style="text-align: center;">Yes</td>
2398+<td style="text-align: center;">Yes</td>
2399+<td class="working">Working **</td>
2400+<td class="working">Working</td>
2401+<td class="working">Working</td>
2402+<td class="working">Working</td>
2403+<td class="working">Working ***</td>
2404+<td class="working">Working</td>
2405+<td class="working">Working</td>
2406+<td class="working">Working ****</td>
2407+<td class="working">Working</td>
2408+<td class="working">Working</td>
2409+<td class="partial">Writing only</td>
2410+<td class="working">Working</td>
2411+<td class="working">Working ++++</td>
2412+</tr>
2413+<tr>
2414+<td>OpenDocument</td>
2415+<td style="text-align: center;">Yes</td>
2416+<td style="text-align: center;">Yes</td>
2417+<td class="working">Working **</td>
2418+<td class="working">Working</td>
2419+<td class="working">Working</td>
2420+<td class="working">Working</td>
2421+<td class="working">Working ***</td>
2422+<td class="working">Working</td>
2423+<td class="working">Working</td>
2424+<td class="working">Working ****</td>
2425+<td class="working">Working</td>
2426+<td class="working">Working</td>
2427+<td class="working">Working</td>
2428+<td class="working">Working</td>
2429+<td class="working">Working</td>
2430+</tr>
2431+<tr>
2432+<td>HTML</td>
2433+<td style="text-align: center;">No</td>
2434+<td style="text-align: center;">Yes</td>
2435+<td class="working">Working ++</td>
2436+<td class="working">Working ++</td>
2437+<td class="working">Working ++</td>
2438+<td class="working">Working ++</td>
2439+<td style="text-align: center;">N/A</td>
2440+<td style="text-align: center;">N/A</td>
2441+<td style="text-align: center;">N/A</td>
2442+<td class="working">Working ++</td>
2443+<td style="text-align: center;">N/A</td>
2444+<td class="working">Working</td>
2445+<td class="not working">Not working</td>
2446+<td style="text-align: center;">N/A</td>
2447+<td style="text-align: center;">N/A</td>
2448+</tr>
2449+<tr>
2450+<td>Wikitable files (Mediawiki)</td>
2451+<td style="text-align: center;">No</td>
2452+<td style="text-align: center;">Yes</td>
2453+<td style="text-align: center;">planned</td>
2454+<td class="working">Working ++</td>
2455+<td class="working">Working ++</td>
2456+<td class="working">Working ++</td>
2457+<td style="text-align: center;">N/A</td>
2458+<td style="text-align: center;">N/A</td>
2459+<td style="text-align: center;">N/A</td>
2460+<td class="working">Working ++</td>
2461+<td style="text-align: center;">N/A</td>
2462+<td style="text-align: center;">N/A</td>
2463+<td class="not working">Not working</td>
2464+<td style="text-align: center;">N/A</td>
2465+<td style="text-align: center;">N/A</td>
2466+</tr>
2467+</tbody>
2468+</table>
2469+
2470+(+) Depends on file.\
2471+(++) No "true" number format support because the file does not containg number formatting information. But the number format currently used in the spreadsheet understood.\
2472+(+++) Only very basic image support: no transformations, no cropping, no image manipulation.\
2473+(++++) Extended OOXML formatting options not supported.\
2474+(*) In formats which don't support Unicode the data is stored by default as ISO 8859-1 (Latin 1). You can change the encoding in TsWorkbook.Encoding. Note that FPSpreadsheet offers UTF-8 read and write routines, but the data might be converted to ISO when reading or writing to the disk. Be careful that characters which don't fit selected encoding will be lost in those operations. The remarks here are only valid for formats which don't support Unicode.\
2475+(**) Some cell could be returned blank due to missing or non ready implemented number and text formats.\
2476+(***) This is the format in which the formulas are written to file (determined by design of the file format).\
2477+(****) Writing of all formats is supported. Some rare custom formats, however, may not be recognized correctly. BIFF2 supports only built-in formats by design.
2478+
2479+### Progress of the formatting options
2480+
2481+The following formatting options are available:
2482+
2483+<table>
2484+<thead>
2485+<tr>
2486+<th>Format</th>
2487+<th>Text<br />
2488+alignment</th>
2489+<th>Text<br />
2490+rotation</th>
2491+<th>    Font    </th>
2492+<th>Rich<br />
2493+text</th>
2494+<th>  Border  </th>
2495+<th>Color<br />
2496+support</th>
2497+<th>Back<br />
2498+ground</th>
2499+<th>Word<br />
2500+wrap</th>
2501+<th>Col&amp;Row<br />
2502+size</th>
2503+<th>Number<br />
2504+format</th>
2505+<th>Merged<br />
2506+cells</th>
2507+<th>Page<br />
2508+layout</th>
2509+<th>Print<br />
2510+ranges</th>
2511+<th>Header/footer<br />
2512+images</th>
2513+<th>Column/row<br />
2514+format</th>
2515+<th>Hide<br />
2516+cols/rows</th>
2517+<th>Page<br />
2518+breaks</th>
2519+</tr>
2520+</thead>
2521+<tbody>
2522+<tr>
2523+<td>CSV files</td>
2524+<td style="text-align: center;">N/A</td>
2525+<td style="text-align: center;">N/A</td>
2526+<td style="text-align: center;">N/A</td>
2527+<td style="text-align: center;">N/A</td>
2528+<td style="text-align: center;">N/A</td>
2529+<td style="text-align: center;">N/A</td>
2530+<td style="text-align: center;">N/A</td>
2531+<td style="text-align: center;">N/A</td>
2532+<td style="text-align: center;">N/A</td>
2533+<td style="text-align: center;">N/A</td>
2534+<td style="text-align: center;">N/A</td>
2535+<td style="text-align: center;">N/A</td>
2536+<td style="text-align: center;">N/A</td>
2537+<td style="text-align: center;">N/A</td>
2538+<td style="text-align: center;">N/A</td>
2539+<td style="text-align: center;">N/A</td>
2540+<td style="text-align: center;">N/A</td>
2541+</tr>
2542+<tr>
2543+<td>Excel 2.x</td>
2544+<td class="working">Working *</td>
2545+<td style="text-align: center;">N/A</td>
2546+<td class="working">Working</td>
2547+<td style="text-align: center;">N/A</td>
2548+<td class="working">Working</td>
2549+<td class="working">Working</td>
2550+<td class="working">Working**</td>
2551+<td style="text-align: center;">N/A</td>
2552+<td class="working">Working</td>
2553+<td class="working">Working</td>
2554+<td style="text-align: center;">N/A</td>
2555+<td class="working">Working</td>
2556+<td style="text-align: center;">N/A</td>
2557+<td style="text-align: center;">N/A</td>
2558+<td class="working">Working</td>
2559+<td style="text-align: center;">N/A</td>
2560+<td class="working">Working</td>
2561+</tr>
2562+<tr>
2563+<td>Excel 5.0<br />
2564+(Excel 5.0 and 95)</td>
2565+<td class="working">Working</td>
2566+<td class="working">Working</td>
2567+<td class="working">Working</td>
2568+<td class="working">Working</td>
2569+<td class="working">Working</td>
2570+<td class="working">Working</td>
2571+<td class="working">Working</td>
2572+<td class="working">Working</td>
2573+<td class="working">Working</td>
2574+<td class="working">Working</td>
2575+<td style="text-align: center;">N/A</td>
2576+<td class="working">Working</td>
2577+<td class="working">Working</td>
2578+<td style="text-align: center;">N/A</td>
2579+<td class="working">Working</td>
2580+<td class="working">Working</td>
2581+<td class="working">Working</td>
2582+</tr>
2583+<tr>
2584+<td>Excel 8.0<br />
2585+(Excel 97 - XP)</td>
2586+<td class="working">Working</td>
2587+<td class="working">Working</td>
2588+<td class="working">Working</td>
2589+<td class="working">Working</td>
2590+<td class="working">Working</td>
2591+<td class="working">Working</td>
2592+<td class="working">Working</td>
2593+<td class="working">Working</td>
2594+<td class="working">Working</td>
2595+<td class="working">Working</td>
2596+<td class="working">Working</td>
2597+<td class="working">Working</td>
2598+<td class="working">Working</td>
2599+<td class="not working">Not working</td>
2600+<td class="working">Working</td>
2601+<td class="working">Working</td>
2602+<td class="working">Working</td>
2603+</tr>
2604+<tr>
2605+<td>Excel 2003/XML</td>
2606+<td class="working">Working</td>
2607+<td class="working">Working</td>
2608+<td class="working">Working</td>
2609+<td class="working">Working</td>
2610+<td class="working">Working</td>
2611+<td class="working">Working</td>
2612+<td class="working">Working</td>
2613+<td class="working">Working</td>
2614+<td class="working">Working</td>
2615+<td class="working">Working</td>
2616+<td class="working">Working</td>
2617+<td class="working">Working</td>
2618+<td class="working">Working</td>
2619+<td style="text-align: center;">N/A</td>
2620+<td class="working">Working</td>
2621+<td class="working">Wworking</td>
2622+<td class="working">Working</td>
2623+</tr>
2624+<tr>
2625+<td>Excel OOXML (xlsx)</td>
2626+<td class="working">Working</td>
2627+<td class="working">Working</td>
2628+<td class="working">Working</td>
2629+<td class="working">Working</td>
2630+<td class="working">Working</td>
2631+<td class="working">Working</td>
2632+<td class="working">Working</td>
2633+<td class="working">Working</td>
2634+<td class="working">Working</td>
2635+<td class="working">Working</td>
2636+<td class="working">Working</td>
2637+<td class="working">Working</td>
2638+<td class="working">Working</td>
2639+<td class="partial">Writing only</td>
2640+<td class="working">Working</td>
2641+<td class="working">Working</td>
2642+<td class="working">Working</td>
2643+</tr>
2644+<tr>
2645+<td>OpenDocument</td>
2646+<td class="working">Working</td>
2647+<td class="working">Working</td>
2648+<td class="working">Working</td>
2649+<td class="working">Working</td>
2650+<td class="working">Working</td>
2651+<td class="working">Working</td>
2652+<td class="working">Working***</td>
2653+<td class="working">Working</td>
2654+<td class="working">Working</td>
2655+<td class="working">Working</td>
2656+<td class="working">Working</td>
2657+<td class="working">Working</td>
2658+<td class="working">Working</td>
2659+<td class="working">Working</td>
2660+<td class="working">Working</td>
2661+<td class="working">Working</td>
2662+<td></td>
2663+</tr>
2664+<tr>
2665+<td>HTML (+)</td>
2666+<td class="working">Working</td>
2667+<td class="not working">bugs</td>
2668+<td class="working">Working</td>
2669+<td class="working">Working</td>
2670+<td class="not working">bugs</td>
2671+<td class="working">Working</td>
2672+<td class="working">Working ****</td>
2673+<td class="partial">Writing only</td>
2674+<td class="partial">Writing only</td>
2675+<td style="text-align: center;">N/A</td>
2676+<td class="working">Working</td>
2677+<td style="text-align: center;">N/A</td>
2678+<td style="text-align: center;">N/A</td>
2679+<td class="not working">Not working</td>
2680+<td class="partial">Writing only</td>
2681+<td class="not working">to be done</td>
2682+<td style="text-align: center;">N/A</td>
2683+</tr>
2684+<tr>
2685+<td>Wikitable (Mediawiki)</td>
2686+<td class="partial">Writing only</td>
2687+<td style="text-align: center;">N/A</td>
2688+<td class="partial">Writing only</td>
2689+<td class="not working">Not working</td>
2690+<td class="partial">Writing only</td>
2691+<td class="partial">Writing only</td>
2692+<td></td>
2693+<td class="partial">Writing only</td>
2694+<td class="partial">Writing only</td>
2695+<td style="text-align: center;">N/A</td>
2696+<td class="partial">Writing only</td>
2697+<td style="text-align: center;">N/A</td>
2698+<td style="text-align: center;">N/A</td>
2699+<td class="not working">Not working</td>
2700+<td class="partial">Writing only</td>
2701+<td class="not working">to be done</td>
2702+<td style="text-align: center;">N/A</td>
2703+</tr>
2704+<tr>
2705+<td></td>
2706+<td></td>
2707+<td></td>
2708+<td></td>
2709+<td></td>
2710+<td></td>
2711+<td></td>
2712+<td></td>
2713+<td></td>
2714+<td></td>
2715+<td></td>
2716+<td></td>
2717+<td></td>
2718+<td></td>
2719+<td></td>
2720+<td></td>
2721+<td></td>
2722+<td></td>
2723+</tr>
2724+</tbody>
2725+</table>
2726+
2727+(N/A) Feature is not available for this format intrinsically.\
2728+(*) BIFF2 supports only horizontal text alignment, vertical alignment is ignored.\
2729+(**) BIFF2 does not support a background color; a dotted black&white background is used instead.\
2730+(***) OpenDocument supports only uniform backgrounds; a fill color interpolated between foreground and background colors is written instead.\
2731+(****) Only uniform background color, no fill styles.\
2732+(+) HTML reader does not support styles. Since the writer does use styles these files are not read back correctly.
2733+
2734+### Progress of workbook/worksheet user-interface options
2735+
2736+Some additional options were added to interface the file contents with the `TsWorksheetGrid`:
2737+
2738+| Format | Hide grid lines | Hide headers | Frozen Panes | Active sheet/cell | Zooming | BiDi mode | Tab color |
2739+|----|----|----|----|----|----|----|----|
2740+| Excel 2.x | Working | Working | not working | N/A | N/A | N/A | N/A |
2741+| Excel 5.0 (Excel 5.0 and 95) | Working | Working | Working | Working | Working | N/A | N/A |
2742+| Excel 8.0 (Excel 97 - XP) | Working | Working | Working | Working | Working | Working | Working |
2743+| Excel2003/XML | Working | Working | Working | Working | Working \|\| class="working\|Working | N/A | |
2744+| Excel OOXML | Working | Working | Working | Working | Working | Working | Working |
2745+| OpenDocument | Working | Working | Working | Working | Working | Working | Working |
2746+| HTML | Writing only | Writing only | N/A | N/A | N/A | not working | N/A |
2747+
2748+### To do list
2749+
2750+Note: this list is provisional, maintained by developers and can change without notice. If you are interested in contributing, please feel free to get in touch and submit a patch - thanks!
2751+
2752+- Find out why BIFF2 files are corrupt when saved with frozen rows/cols activated.
2753+- <s>Add row and column formats</s>
2754+- Add reading support for wikitable (Mediawiki) files
2755+- xls reader crashes for some incorrectly written xls files (which Excel can read), see [<http://forum.lazarus.freepascal.org/index.php/topic,25624.0.html>](http://forum.lazarus.freepascal.org/index.php/topic,25624.0.html).
2756+- <s>Improve color support: due to palette support colors may change from file to file currently.</s>
2757+- Add embedded images.
2758+- Fix writing of cell comments to BIFF8 files.
2759+
2760+**Long-term:**
2761+
2762+- Provide a more common user interface to fpspreadsheet (setter/getter and properties instead of Read*/Write* methods, MyWorksheet.Cells\[ARow, ACol\]), make TCell a class, avoid the pointers PCell.
2763+- <s>Store formatting in a format list of the workbook, not in the cell, to reduce memory usage.</s>
2764+- Use BIFF8 file-wide string storage instead of storing strings in cells (should reduce memory usage in case of many duplicate strings)
2765+- Redo ooxml and ods readers based upon SAX/TXmlReader instead of DOM to reduce memory usage of large files.
2766+- <s>Add an fpspreadsheetexport unit and component on "Data Export" tab similar to [[fpdbfexport]] FPSpreadsheetexport demo preferably with all export formats component.</s> Find a way to register export format to all formats (look into how lazreport pdf export performs a similar procedure).
2767+
2768+## Changelog
2769+
2770+Changes in the development version that have not yet been released are already documented on this page.
2771+
2772+<div class="toccolours mw-collapsible mw-collapsed">
2773+
2774+- 2 June 2020:\
2775+ **Version 1.12** based on revision 7479
2776+- 13 August 2018:\
2777+ **Version 1.10.1** bug fix release, based on revision 6598.
2778+
2779+<div class="mw-collapsible-content">
2780+
2781+- 6 July 2018:\
2782+ **Version 1.10** release, based on svn revision 6547.
2783+- 16 June 2017:\
2784+ **Version 1.8.3**. Fixes compilation with Lazarus 1.8. New, highDPI-aware component palette icons
2785+- 11 April 2017:\
2786+ **Version 1.8.2**, based on svn revision 5832. Fixes writing distorted images due to incorrect row height calculation.
2787+- 2 March 2017:\
2788+ **Version 1.8**, based on svn revision 5781.
2789+- 13 April 2016:\
2790+ **Version 1.6.2** released, based on svn revision 4619. Fixes integer overflow in formulas ([Issue \#29999](https://bugs.freepascal.org/view.php?id=29999)).
2791+- 28 June 2015:\
2792+ **Version 1.6** released, based on svn release 4106. Improved memory consumption, comments, hyperlinks, background fill patterns, cell enumerator, fraction number format, page layout, modified color management, offline wiki version included.
2793+- 13 March 2015:\
2794+ **Version 1.4.3** released. Fixes formula calculation in worksheet grid.
2795+- 31 January 2015:\
2796+ **Version 1.4.2** released. Fixes incomplete reading of ods files with repeated cells ([Issue \#0027389](https://bugs.freepascal.org/view.php?id=0027389))
2797+- 26 January 2015:\
2798+ **Version 1.4.1** released. A bugfix release for 1.4 that fixes incorrect streaming of TsWorksheetGrid and reading errors of biff5 and biff8 readers.
2799+- 31 December 2014:\
2800+ **Version 1.4** released (based on subversion revision 3856 with full formula support, xlsx reader, csv reader and writer, wikitables writer, speed enhancement, virtual mode, db export component, row and column insertion/deletion, sorting, merged cells, visual controls in addition to (improved) fpspreadsheet grid.
2801+- 3 September 2014:\
2802+ **Version 1.2.1** released. This is a bugfix release for 1.2 that fixes a bug in spreadsheetGrid ([Issue \#26521](https://bugs.freepascal.org/view.php?id=26521))
2803+- 26 June 2014:\
2804+ **Version 1.2** released (based on subversion revision 3241) with fpsgrid improvements, date/time cell support for .xls, .ods, vastly improved cell formatting support, improved formula support, unit tests.
2805+- Jan 2013:\
2806+ **Version 1.1** released with all improvements up to revision 2621
2807+- Nov 2011:\
2808+ Released **version 1.0**, which includes OO XML generation support with bold formatting supported and also a lot of improvements from the last years
2809+- Jan 2009:\
2810+ Implemented a cross-platform support for OLE file. Now Excel 5.0 files can be created in any operating system. Adds read support for Excel 2.1
2811+- Feb 2008:\
2812+ **Initial commit** to lazarus-ccr with write support for Excel 2.1, Excel 5.0 (Windows only) and experimental OOXML and OpenDocument
2813+ </div>
2814+
2815+</div>
2816+
2817+## License
2818+
2819+LGPL with static linking exception. This is the same license as is used in the Lazarus Component Library.
2820+
2821+## References
2822+
2823+### Wiki links
2824+
2825+- [[Office Automation]]
2826+- [[CsvDocument]]
2827+- [[FPSpreadsheet: Examples]]
2828+- [[RPN Formulas in FPSpreadsheet|RPN formulas in FPSpreadsheet]]
2829+- [[FPSpreadsheet: List of formulas]]
2830+- [[FPSpreadsheet tutorial: Writing a mini spreadsheet application]]
2831+
2832+### External Links
2833+
2834+- [Microsoft OLE Document Format](http://sc.openoffice.org/compdocfileformat.pdf)
2835+- [Excel file format description](http://sc.openoffice.org/excelfileformat.pdf)
2836+- Excel xls and PowerPoint ppt file dumper written in Python - very handy to list all contents of BIFF files (e.g. ./xls-dump.py file.xls) - [<http://cgit.freedesktop.org/libreoffice/contrib/mso-dumper/>](http://cgit.freedesktop.org/libreoffice/contrib/mso-dumper/). A similar application is the "BIFFExplorer" which can be found in the *applications* folder of ccr.
2837+- Icons used in the demo programs:
2838+ - [silk icons](http://www.famfamfam.com/lab/icons/silk/)
2839+ - [fugue icons](http://p.yusukekamiyamane.com/)
2840+
2841+---
2842+*From the Free Pascal wiki, page "FPSpreadsheet/pl", as it stood on 2021-08-14 after a change by FTurtle, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history