怎么在delphi中读取Excel数据 转

2025-05-13 21:06:12
推荐回答(1个)
回答1:

首先创建 Excel 对象,使用ComObj :
Var
ExcelApp : Variant ;
ExcelApp := CreateOleObject ( '' Excel.Application '' ) ;

1 ) 显示当前窗口:
ExcelApp.Visible := True ;

2 ) 更改 Excel 标题栏:
ExcelApp.Caption := '' 应用程序调用 Microsoft Excel '' ;

3 ) 添加新工作簿:
ExcelApp.WorkBooks.Add ;

4 ) 打开已存在的工作簿:
ExcelApp.WorkBooks.Open ( '' C : \Excel\Demo.xls '' ) ;

5 ) 设置第2个工作表为活动工作表:
ExcelApp.WorkSheets [ 2 ] .Activate ;

ExcelApp.WorksSheets [ '' Sheet2 '' ] .Activate ;

6 ) 给单元格赋值:
ExcelApp.Cells [ 1 , 4 ] .Value := '' 第一行第四列 '' ;