用XMLREADWRITE控件吧,比较好用而且速度很快,而且还支持常用的图表。自带的DEMO代码如下:
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, XLSReadWriteII2, ApplyFormat, CellFormats2, BIFFRecsII2,
XLSFonts2;
type
TfrmMain = class(TForm)
Button1: TButton;
Label1: TLabel;
edFilename: TEdit;
Button2: TButton;
dlgSave: TSaveDialog;
Button3: TButton;
XLS: TXLSReadWriteII2;
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
procedure AddFormats;
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
implementation
{$R *.dfm}
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;
procedure TfrmMain.Button1Click(Sender: TObject);
begin
AddFormats;
XLS.Filename := edFilename.Text;
XLS.Write;
end;
procedure TfrmMain.AddFormats;
var
Fnt: TFont;
begin
// Format a single cell
XLS.Sheets[0].AsString[0,1] := 'Cell 1';
XLS.Sheets[0].Cell[0,1].FillPatternForeColor := xcYellow;
XLS.Sheets[0].Cell[0,1].FontStyle := [xfsBold,xfsItalic];
// Format a range of cells using the ApplyFormat object
XLS.Sheets[0].ApplyFormat.Box(2,1,8,5,cbsMedium,xcLightOrange,xcRed);
XLS.Sheets[0].ApplyFormat.Color(2,7,8,10,xcPaleSky);
Fnt := TFont.Create;
try
XLS.Sheets[0].AsString[2,12] := 'Hello, world';
XLS.Sheets[0].AsFloat[2,13] := 12345;
Fnt.Name := 'Courier New';
Fnt.Size := 14;
Fnt.Style := [fsBold];
XLS.Sheets[0].ApplyFormat.Font(2,12,8,14,Fnt);
finally
Fnt.Free;
end;
end;
end.