var
xlsFile: String;
xlsApp, Sheet: OleVariant;
begin
Result := '';
try
xlsFile := 'c:file1.xls';
xlsApp := CreateOleObject('Excel.Application'); //需要引用 ComObj 单元
try
//打开xls文件
xlsApp.WorkBooks.Open(xlsFile);
Sheet := xlsApp.Sheets[1];
try
//光标归位到Excel档第一页第一格
if xlsApp.ActiveSheet.Index <> Sheet.Index then
Sheet.Select;
Sheet.Cells.Item[1,1].Select;
//显示第3行第5列的数据,可参考此句用循环与判定取出xls中所有数据
ShowMessage(VarToStr(Sheet.Cells.Item[3,5].Value));
end;
finally
Sheet := unassigned;
xlsApp.Quit;
xlsApp := Unassigned;
end;
except
ShowMessage('无法启动Excel程式,请检查!');
end;
end;[@more@]
xlsFile: String;
xlsApp, Sheet: OleVariant;
begin
Result := '';
try
xlsFile := 'c:file1.xls';
xlsApp := CreateOleObject('Excel.Application'); //需要引用 ComObj 单元
try
//打开xls文件
xlsApp.WorkBooks.Open(xlsFile);
Sheet := xlsApp.Sheets[1];
try
//光标归位到Excel档第一页第一格
if xlsApp.ActiveSheet.Index <> Sheet.Index then
Sheet.Select;
Sheet.Cells.Item[1,1].Select;
//显示第3行第5列的数据,可参考此句用循环与判定取出xls中所有数据
ShowMessage(VarToStr(Sheet.Cells.Item[3,5].Value));
end;
finally
Sheet := unassigned;
xlsApp.Quit;
xlsApp := Unassigned;
end;
except
ShowMessage('无法启动Excel程式,请检查!');
end;
end;[@more@]
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/20037923/viewspace-1015967/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/20037923/viewspace-1015967/