使用Ehlib的DbGridEh+TXLSWrite;
var xlsW:TXLSWrite;
r,c:integer
begin
r:=0;
With DBGridEh,xlsWdo
While not DataSource.Datasetdo
begin
for i:=0 to VisibleColumns.Count-1do
begin
Case VisibleColumns.Field.DataType of
ftInteger,ftLargeInt,ftWord:
WriteNumber(i,r,-1,VisibleColumns.Field.AsInteger);
ftCurrency, ftFloat:
WriteNumber(i,CurRow,4,VisibleColumns.Field.AsFloat);
ftString,ftMemo:
WriteString(i,r,-1,VisibleColumns.Field.AsString);
end;
DataSource.Dataset.next;
inc(r)
end
end;
写了个大概,具体还有每个单元格的格式,边框都可以设置,我觉得挺不错的。