Delphi中使用XlsReadWriteII

本文介绍了如何使用XlsReadWriteII库替代Delphi中的CreateOleObject方式来读写Excel文件,提供了读写文件的代码示例,并详细解释了如何自定义格式。通过使用该库,可以轻松地进行格式定制和数据操作。

在Delphi中读取Excel文件,使用CreateOleObject的方式挺讨厌的,一直搞不定,输出了文件之后,总会在系统中打开一个Excel,就算Quit也不行,一个程序中使用的多了,还不定搞出什么事情来。狠狠心找个其它的东西来代替,于是发现了XlsReadWriteII。

使用之后发现这个东西真不错,简单好用。不管是读还是写均轻松搞定。下面是Demo中的代码。

写文件代码,包括对格式的定制:

XLS.Filename := 'FormatSample.xls';

XLS.Clear;
// Add format #0
with XLS.Formats.Add do begin
  FontIndex := XLS.Fonts.AddIndex;
  XLS.Fonts[FontIndex].Name := 'Courier new';
  XLS.Fonts[FontIndex].Size := 14;
  XLS.Fonts[FontIndex].Color := xcRed;
end;

// Add format #1
with XLS.Formats.Add do begin
  FontIndex := XLS.Fonts.AddIndex;
  XLS.Fonts[FontIndex].AssignTFont(Font);
end;

// Add format #2
with XLS.Formats.Add do begin
  FillPatternForeColor := xcLilac;
end;

// Add format #3
with XLS.Formats.Add do begin
  BorderTopColor := xcBlue;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值