try WorkBook:=eclApp.workbooks.Add; for i:=0 to DBGrid1.Columns.Count-1 do begin //这里可以更改列名,用if ... then进行判断和指定列名 eclApp.Cells(1,i+1):=DBGrid1.Columns[i].FieldName; end;
DBGrid1.DataSource.DataSet.First; j:=2; while not DBGrid1.DataSource.DataSet.Eof do begin for i:=0 to DBGrid1.DataSource.DataSet.FieldCount-1 do begin eclApp.Cells(j,i+1):=DBGrid1.DataSource.DataSet.Fields[i].Value; end; DBGrid1.DataSource.DataSet.Next; inc(j); end;