delphi中XLSReadWrite控件的使用(3)---基本应用

 这是自带的一个例子,看懂这一点东西,基本的操作应该没问题了....

 
  
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 *)
(* 显示字符串 *)
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 number cell (3 decimals and thousand separator)
(* 格式化字符串,显示小数点后三位,千位和百位之间加个空格
*)
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 ' ;
(* 单元格赋值 *)
(* Set the font size of the cells in the area.
(* 改变区域内的字体大小
*)
XLS.Sheet[
0 ].Range.Items[ 1 , 0 , 3 , 3 ].FontSize : = 14 ;
(* Set the color of the cells. *)
(* 设置区域的颜色 *)
XLS.Sheet[
0 ].Range.ItemsRef[ ' B1:D4 ' ].FillPatternForeColor : = xcYellow;
(* Set a outline border. *)
(* 设置外框线的外形、颜色 *)
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. *)
(* 区域复制 *)
XLS.Sheet[
0 ].Range.ItemsRef[ ' B1:D4 ' ].Copy( 8 , 10 );
(* Move the cells. *)
(* 区域移动 *)
XLS.Sheet[
0 ].Range.ItemsRef[ ' B1:D4 ' ].Move( 8 , 2 );
end ;

procedure TfrmMain.Button1Click(Sender: TObject);
begin
AddFormats;
XLS.Filename :
= edFilename.Text;
(* 保存文件 *)
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 .

转载于:https://www.cnblogs.com/dabiao/archive/2011/07/08/2100613.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值