var i,n: Integer; xlsApp: Variant; begin if adsMaster.Eof then begin ShowMessage('没有数据!'); exit; end; xlsApp := CreateOleObject('Excel.Application'); xlsapp.WorkBooks.add; xlsApp.Visible := false; xlsApp.WorkSheets[1].Activate; adsMaster.First; i :=1; //填Excel标题行 for n:=1 to adsMaster.FieldCount do xlsApp.Cells[i,n].Value := adsMaster.Fields[n-1].DisplayLabel; While not adsMaster.Eof do begin inc(i);//因在循环前使用了一次填标题行,所以在前面做增量 for n:=1 to adsMaster.FieldCount do begin if adsMaster.Fields[n-1].FieldName = 'WO' then xlsApp.Cells[i,n].Value := '''' + adsMaster.Fields[n-1].AsString else xlsApp.Cells[i,n].Value := adsMaster.Fields[n-1].AsString; end; adsMaster.Next; end; xlsApp.Visible := true; 上面是我找的资料但是看不明白是什么意思。。能帮我解释下吗 ?
var i,n: Integer; xlsApp: Variant; begin //判断adsMaster数据集是否为空 if adsMaster.Eof then begin ShowMessage('没有数据!'); exit; end; //创建excel原生对象 xlsApp := CreateOleObject('Excel.Application'); xlsapp.WorkBooks.add; xlsApp.Visible := false; //激活sheet1 xlsApp.WorkSheets[1].Activate; //adsMaster指向第一条 adsMaster.First; i :=1; //填Excel标题行,Cells是单元格集合 for n:=1 to adsMaster.FieldCount do xlsApp.Cells[i,n].Value := adsMaster.Fields[n-1].DisplayLabel; //循环adsMaster While not adsMaster.Eof do begin inc(i);//因在循环前使用了一次填标题行,所以在前面做增量 for n:=1 to adsMaster.FieldCount do begin if adsMaster.Fields[n-1].FieldName = 'WO' then xlsApp.Cells[i,n].Value := '''' + adsMaster.Fields[n-1].AsString else xlsApp.Cells[i,n].Value := adsMaster.Fields[n-1].AsString; end; adsMaster.Next; end; //显示excel xlsApp.Visible := true; end.
i,n: Integer;
xlsApp: Variant;
begin
if adsMaster.Eof then begin
ShowMessage('没有数据!');
exit;
end;
xlsApp := CreateOleObject('Excel.Application');
xlsapp.WorkBooks.add;
xlsApp.Visible := false;
xlsApp.WorkSheets[1].Activate;
adsMaster.First;
i :=1;
//填Excel标题行
for n:=1 to adsMaster.FieldCount do xlsApp.Cells[i,n].Value := adsMaster.Fields[n-1].DisplayLabel;
While not adsMaster.Eof do begin
inc(i);//因在循环前使用了一次填标题行,所以在前面做增量
for n:=1 to adsMaster.FieldCount do begin
if adsMaster.Fields[n-1].FieldName = 'WO' then xlsApp.Cells[i,n].Value := '''' + adsMaster.Fields[n-1].AsString
else xlsApp.Cells[i,n].Value := adsMaster.Fields[n-1].AsString;
end;
adsMaster.Next;
end;
xlsApp.Visible := true;
上面是我找的资料但是看不明白是什么意思。。能帮我解释下吗 ?
var
i,n: Integer;
xlsApp: Variant;
begin
//判断adsMaster数据集是否为空
if adsMaster.Eof then begin
ShowMessage('没有数据!');
exit;
end;
//创建excel原生对象
xlsApp := CreateOleObject('Excel.Application');
xlsapp.WorkBooks.add;
xlsApp.Visible := false;
//激活sheet1
xlsApp.WorkSheets[1].Activate;
//adsMaster指向第一条
adsMaster.First;
i :=1;
//填Excel标题行,Cells是单元格集合
for n:=1 to adsMaster.FieldCount do xlsApp.Cells[i,n].Value := adsMaster.Fields[n-1].DisplayLabel;
//循环adsMaster
While not adsMaster.Eof do begin
inc(i);//因在循环前使用了一次填标题行,所以在前面做增量
for n:=1 to adsMaster.FieldCount do begin
if adsMaster.Fields[n-1].FieldName = 'WO' then xlsApp.Cells[i,n].Value := '''' + adsMaster.Fields[n-1].AsString
else xlsApp.Cells[i,n].Value := adsMaster.Fields[n-1].AsString;
end;
adsMaster.Next;
end;
//显示excel
xlsApp.Visible := true;
end.
xlsApp := CreateOleObject('Excel.Application');
这里就出错了