在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;

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

被折叠的 条评论
为什么被折叠?



