教你个最简单的方法: var tmp_lst:TStringList; tp_str:String; i,j:Integer; begin tmp_lst:=TStringList.Create; DataSet.First; for i:=0 to DataSet.RecordCount do begin tp_str:=''; for j:=0 to DataSet.FieldCount do begin tp_str:=tp_str+DataSet.Fields[0].AsString+#9; end; tmp_lst.Add(tp_str); end; end;
var tmp_lst:TStringList; tp_str:String; i,j:Integer; begin tmp_lst:=TStringList.Create; DataSet.First; for i:=0 to DataSet.RecordCount do begin tp_str:=''; for j:=0 to DataSet.FieldCount do begin tp_str:=tp_str+DataSet.Fields[0].AsString+#9; end; tmp_lst.Add(tp_str); end; tmp_lst.SaveToFile('C:\A.XLS');
to chenxi_aji(阿吉):最近出差了,没看到你的帖子,单元格的值可用下面的方面来赋值. excelworksheet1.Cells.Item[行,列]:=数值;
ExcelApplication1.Connect;
ExcelApplication1.Visible[0]:=true;
ExcelApplication1.Workbooks.Add('',0);
excelworkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
excelworksheet1.ConnectTo(excelworkbook1.Worksheets[1] as _worksheet);
因为里面的数据不是从数据库里直接导出来,需要一些计算和转换。
var
tmp_lst:TStringList;
tp_str:String;
i,j:Integer;
begin
tmp_lst:=TStringList.Create;
DataSet.First;
for i:=0 to DataSet.RecordCount do
begin
tp_str:='';
for j:=0 to DataSet.FieldCount do
begin
tp_str:=tp_str+DataSet.Fields[0].AsString+#9;
end;
tmp_lst.Add(tp_str);
end;
end;
tmp_lst:TStringList;
tp_str:String;
i,j:Integer;
begin
tmp_lst:=TStringList.Create;
DataSet.First;
for i:=0 to DataSet.RecordCount do
begin
tp_str:='';
for j:=0 to DataSet.FieldCount do
begin
tp_str:=tp_str+DataSet.Fields[0].AsString+#9;
end;
tmp_lst.Add(tp_str);
end;
tmp_lst.SaveToFile('C:\A.XLS');
excelworksheet1.Cells.Item[行,列]:=数值;