其他分享
首页 > 其他分享> > delphi7如何读取excel文件

delphi7如何读取excel文件

作者:互联网

delphi7如何读取excel文件


用ole读excel:会读了后,你自己处理一下要读的数据就行了
var
I, J: Integer;
MaxRow, MaxCol: Integer;
List, Strs: TStringList;
ExcelApp, Sheet: Variant;
OldTime: TDateTime;
begin
List := TStringList.Create;
Strs := TStringList.Create;
// 创建一个excel的ole对象
ExcelApp := CreateOleObject( "Excel.Application ");
try
// 打开一个excel文件
ExcelApp.WorkBooks.Open(Edit1.Text);
List.BeginUpdate;
try
// 设置工作区
ExcelApp.WorkSheets[1].Activate;
Sheet := ExcelApp.WorkSheets[1];
// 有数据的区域的行数和列数
MaxRow := Sheet.UsedRange.Rows.count - 1;
MaxCol := Sheet.UsedRange.Columns.count;
for I := 2 to MaxRow do
begin
Strs.Clear;
for J := 1 to MaxCol do
begin
// 获得excel的数据第i行,第j列单元格内的数据
Strs.Add(Sheet.Cells[i, j].Value);
end;
List.Add(Strs.CommaText);
end;

标签:ExcelApp,Sheet,读取,Strs,List,excel,begin,delphi7
来源: https://blog.csdn.net/xcbzsy/article/details/121990572