怎么将DBGRID中的数据导出成TXT文件?

joe_q 2001-05-24 05:19:00
不知该怎么办?
...全文
100 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
sanjianxia 2001-05-24
  • 打赏
  • 举报
回复
西门吹雪,历害。
xzgyb 2001-05-24
  • 打赏
  • 举报
回复
如用TBatchMove也可以,destination的ttable的tabletype设为ttAscii,在用batCopy
模式生成一新表,即为txt文件
wangxd1976 2001-05-24
  • 打赏
  • 举报
回复
//把输出结果转换成文本文件
function ChangetoText(TextForm:Tform;Query1:TQuery;title:string;summary:string): Boolean;
var
I: integer;
FName,OutString: string;
OutFile: TextFile;
note: Tbookmark;
savedialog1: Tsavedialog;
begin
//创建对话框的容器
try
savedialog1 := Tsavedialog.Create(TextForm);
//Assign a filename to the variable
savedialog1.Filter := 'Text files (*.txt)|*.TXT';
if savedialog1.Execute then
FName := savedialog1.FileName+'.txt';
if FName <> '' then
begin
note := Query1.GetBookmark;
Query1.DisableControls;

//Identify the filename and type as OutFile
AssignFile(OutFile,fname);

//create and open a new file identify as OutFile
Rewrite(OutFile);

//插入标题
OutString := title+#13;
Writeln(OutFile,OutString);
OutString := '';

//Get text from the Query1
for I:=0 to Query1.FieldCount-1 do
begin
if query1.Fields[i].Visible = True then
begin
OutString:=OutString+Query1.Fields[i].displaylabel;
if I < Query1.FieldCount-1 then
OutString := OutString + ','
else outstring := Outstring;
end;
end;
Writeln(OutFile,OutString);
OutString := '';

While not Query1.EOF do
begin
for I:=0 to Query1.FieldCount-1 do
begin
if query1.Fields[i].Visible = True then
begin
OutString:=OutString+'"'+Query1.Fields[i].AsString+'"';
if I < Query1.FieldCount-1 then
OutString := OutString + ','
else outstring := Outstring ;
end;
end;
//Write out the text in OutString to file
Writeln(OutFile,OutString);
Query1.Next;
OutString := '';
end;

//插入总结
Writeln(OutFile,summary);
//Update and close the file
CloseFile(OutFile);
Query1.EnableControls;
Query1.GotoBookmark(note);
Query1.FreeBookmark(note);
savedialog1.Destroy;
result := True;
end;
except
CloseFile(OutFile);
Query1.EnableControls;
Savedialog1.free;
Showmessage('过程错误,请退出后重新运行!');
Result := False;
end;
end;

5,930

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧