没办法了,只有再提啊,(20分)

  • 主题发起人 woyeah2000
  • 开始时间
W

woyeah2000

Unregistered / Unconfirmed
GUEST, unregistred user!
如何从ACCESS数据库的记录转成一个文本文件,要求如:|1|234|567|890要带有管道符的,
但不能有空格,急啊
 
大不了自己用个循环来转。把空格 trim 掉,
如果中间空也不要 stringReplace
 
unit Unit1;

interface

uses db, classes, dialogs,sysutils;

{过程 DataSetToASCII - 从TDataSet 类型的变量 ADataSet 中输出记录
到一个指定的 ASCII 文本文件. 各字段被名为 Delimiter 的分隔字符分隔。
只有 Tag 属性为 0 (缺省值)的字段被输出.各条记录间用换行符分开。
如果参数 QuoteStrings 为 True 则字段类型为
ftString,ftMemo,ftFmtMemo,ftFixedChar 和 ftWideString 的字段将被引号引起再输出}

procedure DataSetToASCII(const ADataSet: TDataSet; const ASCIIFile: TFileName; const Delimiter: Char; const QuoteStrings: Boolean);


implementation

procedure 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.Tag = 0 then begin

if QuoteStrings and
(Fields.Fields.DataType in [ftString,ftMemo,ftFmtMemo,ftFixedChar,ftWideString]) then
AsciiRecord:= AsciiRecord + QuotedStr(Fields.Fields.AsString)
else
AsciiRecord:= AsciiRecord + Fields.Fields.AsString;

if i < LastIndex then
AsciiRecord:= AsciiRecord + Delimiter;

end;

tmpList.Append(AsciiRecord);

Next
end
end;

try
tmpList.SaveToFile(ASCIIFile)
except
ShowMessage('Could not save table to specified file: ' + ASCIIFile)
end;

finally
tmpList.Free;
end;
end;


end.
 
设置导处数据源 为 (*.txt,*.csv)
设置分割符为“|”
 
如何设?

TO JSXJD,我更没看明白,不好意思,我真是笨啊
 
接受答案了.
 

Similar threads

D
回复
0
查看
761
DelphiTeacher的专栏
D
D
回复
0
查看
739
DelphiTeacher的专栏
D
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
714
DelphiTeacher的专栏
D
S
回复
0
查看
958
SUNSTONE的Delphi笔记
S
顶部