问题以解决,解决方法如下: procedure TForm1.BitBtn1Click(Sender: TObject); var MSExcel: Variant; i, j,VL_I: Integer; filename: string; F: TextFile; begin if OpenDialog1.Execute then begin filename := OpenDialog1.FileName; { Read the first line out of the file } end; //从Excel文件里读取信息 MSExcel := CreateOLEObject('Excel.Application'); MSExcel.WorkBooks.Open(filename); //从有数据的行逐行读入数据<br> for i := 1 to ClientDataSet1.RecordCount do begin for j := 1 to ClientDataSet1.FieldCount - 1 do MSExcel.Cells[i, j].value := ClientDataSet1.Fields[j-1].AsString; end; MSExcel.Visible :=true;end;
procedure TForm1.BitBtn1Click(Sender: TObject);
var MSExcel: Variant;
i, j,VL_I: Integer;
filename: string;
F: TextFile;
begin
if OpenDialog1.Execute then
begin
filename := OpenDialog1.FileName; { Read the first line out of the file }
end;
//从Excel文件里读取信息
MSExcel := CreateOLEObject('Excel.Application');
MSExcel.WorkBooks.Open(filename); //从有数据的行逐行读入数据<br>
for i := 1 to ClientDataSet1.RecordCount do
begin
for j := 1 to ClientDataSet1.FieldCount - 1 do
MSExcel.Cells[i, j].value := ClientDataSet1.Fields[j-1].AsString;
end;
MSExcel.Visible :=true;end;