var F1: TextFile; str: string; begin AssignFile(F1, 'c:\a.txt'); Rewrite(F1); with table1 do begin First; while not Eof do begin str := ''; str := fieldbyname('ni').astrign+' '; str := str + fieldbyname('wo').asstring; writeln(f1, str); table1.next; end; CloseFile(F1); end; end;
如果是SQL Server 可以直接导出成文档。
建议导成一个 xml 文件。 容易交换数据。
to all 小妹还是出学,有很多东西不懂,所以请各位仁兄指导详细点, 谢谢啦!!:)
procedure TForm14.DataSetToASCII(const ADataSet: TDataSet; const ASCIIFile: TFileName; const Delimiter: Char; const QuoteStrings: Boolean);var tmpList: TStringList; i,LastIndex: LongInt; AsciiRecord: String; begin tmpList:= TStringList.Create; try with ADataSet do begin LastIndex:= Fields.Count - 1; First; while not EOF do begin AsciiRecord:= ''; for i := 0 to LastIndex do if Fields.Fields[i].Tag = 0 then begin
if QuoteStrings and (Fields.Fields[i].DataType in [ftString,ftMemo,ftFmtMemo,ftFixedChar,ftWideString]) then AsciiRecord:= AsciiRecord + QuotedStr(Fields.Fields[i].AsString) else AsciiRecord:= AsciiRecord + Fields.Fields[i].AsString;
if i < LastIndex then AsciiRecord:= AsciiRecord + Delimiter;
end;
tmpList.Append(AsciiRecord);
Next end end;
try tmpList.SaveToFile(ASCIIFile+'.txt') ; except ShowMessage('Could not save table to specified file: ' + ASCIIFile) end;
F1: TextFile;
str: string;
begin
AssignFile(F1, 'c:\a.txt');
Rewrite(F1);
with table1 do
begin
First;
while not Eof do
begin
str := '';
str := fieldbyname('ni').astrign+' ';
str := str + fieldbyname('wo').asstring;
writeln(f1, str);
table1.next;
end;
CloseFile(F1);
end;
end;
小妹还是出学,有很多东西不懂,所以请各位仁兄指导详细点,
谢谢啦!!:)
i,LastIndex: LongInt;
AsciiRecord: String;
begin
tmpList:= TStringList.Create;
try
with ADataSet do begin
LastIndex:= Fields.Count - 1;
First;
while not EOF do begin
AsciiRecord:= '';
for i := 0 to LastIndex do
if Fields.Fields[i].Tag = 0 then begin
if QuoteStrings and
(Fields.Fields[i].DataType in [ftString,ftMemo,ftFmtMemo,ftFixedChar,ftWideString]) then
AsciiRecord:= AsciiRecord + QuotedStr(Fields.Fields[i].AsString)
else
AsciiRecord:= AsciiRecord + Fields.Fields[i].AsString;
if i < LastIndex then
AsciiRecord:= AsciiRecord + Delimiter;
end;
tmpList.Append(AsciiRecord);
Next
end
end;
try
tmpList.SaveToFile(ASCIIFile+'.txt') ;
except
ShowMessage('Could not save table to specified file: ' + ASCIIFile)
end;
finally
tmpList.Free;
end;
end;
给你一个function,你试一下