我给你写一个导入到.xls的程序如下,已经调试过没有问题:
var
I: Integer;
Str: String;
StrList: TStringList;
isSave:boolean;
title:string;
begin
try
if savedialog1.Execute then
begin
isSave:=true;
if FileExists(savedialog1.FileName) then
if idno=messagebox(handle,'文件已經存在,是否繼續保存?','提示',mb_iconstop+mb_yesno) then
begin
issave:=false;
end;
if issave then
begin
StrList := TStringList.Create;
with DBGrid1 do
begin
title:='';
for i:=0 to Columns.Count-1 do
begin
title:=title+Columns.Title.Caption+#9;
end;
StrList.Add(title);
end;
with ADOQuery1 do
begin
First;
while not Eof do
begin
Str := '';
for I := 0 to FieldCount-1 do
Str := Str + Fields.AsString + #9;
StrList.Add(Str);
Next;
end;
StrList.SaveToFile(savedialog1.FileName);
messagebox(handle,'數據保存成功.','提示',MB_OK+MB_ICONINFORMATION);
end;
end;
end;
finally
Freeandnil(StrList);
end;
end;
end.