This is a built-in example. To understand this, the basic operation should be okay ....
Unit Main;
Interface
Uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, XLSReadWriteII4, XLSFonts4, CellFormats4, BIFFRecsII4;
Type
TfrmMain = class (TForm)
Label1: TLabel;
Button1: TButton;
EdFilename: TEdit;
Button2: TButton;
Button3: TButton;
DlgSave: TSaveDialog;
XLS: TXLSReadWriteII4;
Procedure Button1Click (Sender: TObject );
Procedure Button2Click (Sender: TObject );
Procedure Button3Click (Sender: TObject );
Private
Procedure AddFormats;
Public
{Public declarations}
End;
Var
FrmMain: TfrmMain;
Implementation
{$ R *. dfm}
Procedure TfrmMain. AddFormats;
Begin
(* Format a single cell *)
(* Display string *)
XLS. Sheets [0]. AsString [0, 1]: = 'cell 1 ';
(* String color *)
XLS. Sheets [0]. Cell [0, 1]. FillPatternForeColor: = xcYellow;
(* Font *)
XLS. Sheets [0]. Cell [0, 1]. FontStyle: = [xfsBold, xfsItalic];
(* Format a number cell (3 decimals and thousand separator)
(* Format the string and display the last three digits of the decimal point. A space is added between the number of digits and the number of digits *)
XLS. Sheets [0]. AsFloat [0, 0]: = 12335985394.895634;
XLS. Sheets [0]. Cell [0, 0]. NumberFormat: = '### 0.000 ';
(* Write a string cell .*)
XLS. Sheet [0]. AsStringRef ['c2']: = 'hello ';
(* Cell assignment *)
(* Set the font size of the cells in the area.
(* Change the font size in the area *)
XLS. Sheet [0]. Range. Items [,]. FontSize: = 14;
(* Set the color of the cells .*)
(* Set the region color *)
XLS. Sheet [0]. Range. ItemsRef ['b1: D4 ']. FillPatternForeColor: = xcYellow;
(* Set a outline border .*)
(* Set the shape and color of the outer frame line *)
XLS. Sheet [0]. Range. ItemsRef ['b1: D4 ']. BorderOutlineStyle: = cbsThick;
(* Set color of the outline border .*)
XLS. Sheet [0]. Range. ItemsRef ['b1: D4 ']. BorderOutlineColor: = xcRed;
(* Make a copy of the cells .*)
(* Region replication *)
XLS. Sheet [0]. Range. ItemsRef ['b1: D4 ']. Copy (8, 10 );
(* Move the cells .*)
(* Move the region *)
XLS. Sheet [0]. Range. ItemsRef ['b1: D4 ']. Move (8, 2 );
End;
Procedure TfrmMain. Button1Click (Sender: TObject );
Begin
AddFormats;
XLS. filename: = edfilename. text;
(* Save file *)
XLS. Write;
End;
Procedure tfrmmain. button2click (Sender: tobject );
Begin
Dlgsave. filename: = edfilename. text;
If dlgsave. Execute then
Edfilename. Text: = dlgsave. filename;
End;
Procedure tfrmmain. button3click (Sender: tobject );
Begin
Close;
End;
End.