如何把QUERY的查询结果直接输出到文本文件或直接打印,急急急!!!!(100分)

  • 主题发起人 主题发起人 sunjj
  • 开始时间 开始时间
S

sunjj

Unregistered / Unconfirmed
GUEST, unregistred user!
如何把QUERY的查询结果直接输出到文本文件或直接打印,急急急!!!!
如何把QUERY的查询结果直接输出到文本文件或直接打印,急急急!!!!
 

AssignPrn(PrintFile)//发送到打印机

................

Query1.First;
while not query1.EOFdo

//query 记录

query1.Next;
end
 
to li zhaoyang:
Query1.First;
while not query1.EOFdo

//query 记录
这里应该怎么写???
query1.Next;

end



如果输出到文本文件高如何????
初学DELPHI让你见笑!!
 
Query1.close;

Query1.SQL.Clear;
Query1.SQL.Add('select caption,savepath from report');
Query1.Active :=True;
Query1.First ;

richedit1.lines.Clear ;


while not query1.EOFdo

begin

richedit1.lines.Add(query1.fieldbyname('caption').Asstring);
query1.next;
end;

query1.close;
RichEdit1.Print('...');
richedit1.lines.savetofile('111.txt');
 
这里应该怎么写???
writeln(query1.fieldbyname('fieldname').asstring);
 
不能一下输出吗??非得遍历query吗??应该有更简单的方法的!!!!
 
这样不够简单吗?
 
var TFile:TextFile;
....
ReWrite(TFile);//到文件
//下面同到打印机一样
Query1.First;
while not query1.EOFdo

begin

str:='字段值';
writeln(TFile,str);
query1.Next;
end;
 
发了一个示例.
 
好象必须要遍历

 
沈前卫再那里???
 
to str:
按你的方法在文本文件头出现:
{/rtf1/ansi/deff0/deftab720{/fonttbl{/f0/fnil MS Sans Serif;}{/f1/fnil/fcharset2 Symbol;}{/f2/fswiss/fprq2 System;}{/f3/fnil/fcharset134 MS Sans Serif;}}
{/colortbl/red0/green0/blue0;}
/deflang1033{/info{/horzdoc }{/*/fchars !),.:/'3b?/}]/'a1/'a2/'a1/'a3/'a1/'a4/'a1/'a5/'a1/'a6/'a1/'a7/'a1/'a8/'a1/'a9/'a1/'aa/'a1/'ab/'a1/'ac/'a1/'ad/'a1/'af/'a1/'b1/'a1/'b3/'a1/'b5/'a1/'b7/'a1/'b9/'a1/'bb/'a1/'bd/'a1/'bf/'a1/'c3/'a3/'a1/'a3/'a2/'a3/'a7/'a3/'a9/'a3/'ac/'a3/'ae/'a3/'ba/'a3/'bb/'a3/'bf/'a3/'dd/'a3/'e0}{/*/lchars ([/{/'a1/'ae/'a1/'b0/'a1/'b2/'a1/'b4/'a1/'b6/'a1/'b8/'a1/'ba/'a1/'bc/'a1/'be/'a3/'a8/'a3/'db/'a3/'fb/'a3/'ae/'a1/'a4}}
/pard/plain/f3/fs16 6952485
/par 6911919
/par 6911919
/par 6911919
/par 7720113
/par 3313157
/par 8673368
/par 68314422
/par 68314422
/par 4681136
/par 5925148
/par 1861
/par 4667260
的乱字符该如何???
我想要得是:
6911919
6911919
6911919
7720113
3313157
8673368
68314422
68314422
4681136
5925148
1861
4667260
 
to str:
按你的方法在文本文件头出现:
{/rtf1/ansi/deff0/deftab720{/fonttbl{/f0/fnil MS Sans Serif;}{/f1/fnil/fcharset2 Symbol;}{/f2/fswiss/fprq2 System;}{/f3/fnil/fcharset134 MS Sans Serif;}}
{/colortbl/red0/green0/blue0;}
/deflang1033{/info{/horzdoc }{/*/fchars !),.:/'3b?/}]/'a1/'a2/'a1/'a3/'a1/'a4/'a1/'a5/'a1/'a6/'a1/'a7/'a1/'a8/'a1/'a9/'a1/'aa/'a1/'ab/'a1/'ac/'a1/'ad/'a1/'af/'a1/'b1/'a1/'b3/'a1/'b5/'a1/'b7/'a1/'b9/'a1/'bb/'a1/'bd/'a1/'bf/'a1/'c3/'a3/'a1/'a3/'a2/'a3/'a7/'a3/'a9/'a3/'ac/'a3/'ae/'a3/'ba/'a3/'bb/'a3/'bf/'a3/'dd/'a3/'e0}{/*/lchars ([/{/'a1/'ae/'a1/'b0/'a1/'b2/'a1/'b4/'a1/'b6/'a1/'b8/'a1/'ba/'a1/'bc/'a1/'be/'a3/'a8/'a3/'db/'a3/'fb/'a3/'ae/'a1/'a4}}
/pard/plain/f3/fs16 6952485
/par 6911919
/par 6911919
/par 6911919
/par 7720113
/par 3313157
/par 8673368
/par 68314422
/par 68314422
/par 4681136
/par 5925148
/par 1861
/par 4667260
的乱字符该如何???
我想要得是:
6911919
6911919
6911919
7720113
3313157
8673368
68314422
68314422
4681136
5925148
1861
4667260
 
根据字段的设置输出到文本,If 要打印,自己再做处理!

procedure SaveDataSet(DataSet: TDataSet;
FileName: String);
var
sFormat: String;
aData: array of String;
aFmtWidth: array of Integer;
i: Integer;
sl: TStringList;
sToAdd: String;

procedure PrepareTitle(var s: String;
const l: Integer;
DisplayName: String;
bLeftAlign: Boolean = True);
const
sAlignment: array[Boolean] of String = ('-', '');
var
sf: String;
begin

sf := '%' + sAlignment[bLeftAlign] + IntToStr(l) + 's ';
s := s + Format(sf, [DisplayName]);
end;


procedure PrepareFormatStr(const l: Integer;
FieldName: String);
begin

SetLength(aFmtWidth, Length(aFmtWidth) + 1);
aFmtWidth[High(aFmtWidth)] := l;
SetLength(aData, Length(aData) + 1);
aData[High(aData)] := FieldName;
end;


function PrepareData(afs: array of Integer;
a: array of String): String;
var
j: Integer;
begin

Result := EmptyStr;
with DataSetdo

for j := Low(a) to High(a)do

PrepareTitle(Result, afs[j], FieldByName(a[j]).AsString, FieldByName(a[j]).Alignment = taLeftJustify);
end;


begin

sFormat := EmptyStr;
sl := TStringList.Create;
Screen.Cursor := crSQLWait;
try
with DataSet.Fieldsdo
begin

for i := 0 to Count - 1do
begin

PrepareTitle(sFormat, Fields.DisplayWidth, Fields.DisplayName, Fields.Alignment = taLeftJustify);
end;

sl.Add(sFormat);
sl.Add(' ');
sFormat := '';
for i := 0 to Count - 1do
begin

PrepareFormatStr(Fields.DisplayWidth, Fields.FieldName)
end
end;

with DataSetdo
begin

First;
while not Eofdo
begin

sToAdd := '';
sToAdd := PrepareData(aFmtWidth, aData);
sl.Add(sToAdd);
Next;
end;

end;

sl.SaveToFile(FileName);
finally
sl.Free;
Screen.Cursor := crDefault;
end
end;
 
不是乱码!
try this:

RichEdit1.PlainText := True;
RichEdit1.Lines.SaveToFile('F:/11.txt');
 
谢谢Big_Z
按照你的方法我已经解决了问题!!
再次感谢大家的不吝指教!!!!!
 
接受答案!!!
 
后退
顶部