以前做试验时, 写的几行读excel 的程序. 给你参考一下吧
ExcelApplication.Connect;
ExcelApplication.Workbooks.Open(Edit1.Text, EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam, 0);
//ExcelApplication.Visible[0] := True;
ExcelWorkbook.ConnectTo(ExcelApplication.Workbooks[1]);//ExcelWorkbook1与Eexcelapplication1建立连接
ExcelWorksheet.ConnectTo(ExcelWorkbook.Worksheets[1] as _Worksheet);//Excelworksheet1与Excelworkbook1建立连接
Memo1.Lines.Add('WorkBook Count = ' + IntToStr(ExcelApplication.Workbooks.Count));
AssignFile(fp, ExtractFilePath(ParamStr(0)) + '数据.Txt');
if FileExists(ExtractFilePath(ParamStr(0)) + '数据.Txt') then
Append(fp)
else
ReWrite(fp);
For i:=1 to ExcelApplication.Worksheets.Count do
begin
sheet := ExcelApplication.Worksheets.Item as _worksheet;
row := 1;
repeat
szLine := Format('2006-12-%s,%s,%s-%s', [
Sheet.Cells.Item[row, 1],
Sheet.Cells.Item[row, 2],
Sheet.Cells.Item[row, 3],
Sheet.Cells.Item[row, 4]]);
szLine := Trim(szLine);
if szLine = '2006-12-,,-' then
Break
else
WriteLn(fp, szLine);
row := row + 1;
until False;
end;
CloseFile(fp);
try
ExcelApplication.Quit;
ExcelWorksheet.Disconnect;
ExcelWorkbook.Disconnect;
ExcelApplication.Disconnect;
except
end;