打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
How to import a csv file into a delphi app?
How to import a csv file into a delphi app?

Hi!

I need to import to my application in delphi 2006 using firebird 2.0 an address book I have exported with csv extension. How do I do that?



Thank You!
Eduardo Tavares
[link=http://www.eduardotavares.com.br]www.EduardoTavares.com.br[/link]


Plz accept if it helps.I always do.
"Daddy,what does Formatting C:... mean?"
---------------------------------------------
Borland Delphi 2006
  #2  
07-17-2007, 09:26 PM
Senior Member
 
Join Date: Apr 2006
Posts: 284
RE: How to import a csv file into a delphi app?

Ive used a stringlist which has a commatext method which will create a stringlist of the current values (Array) in the code below the Ttask create method loads a CSV string from the input file and creates objects as it loops through the file.

constructor tTask.Create(sTask_string: string);
var
MSL: tstringlist; //Temporary Stringlist for Task Class
dToday : tDate;
begin
if sTask_string = '--' then
begin
//Is reaching here in the Correct Situation
dToday := Dateof(Date);
sDescription := 'New Task';
dDate_Set := dToday;
dDate_Due := dToday + 1;
bIsComplete := false;
sNotes := 'Notes';
end else
begin
MSL := tStringList.Create;
MSL.CommaText:= sTask_string;
sDescription := MSL[0];
dDate_Set := strtoDate(MSL[1]);
dDate_Due := strtoDate(MSL[2]);
bIsComplete := strtobool(MSL[3]);
sNotes := MSL[4];
MSL.Free;
end;
end;

procedure TForm1.LoadFromFile();
var
f: textfile; //Input File
Openstr: string; //Temporary String to Hold Line Input from File
ThisTask : tTask; //Class to Hold Object before it is assigned to Listbox.
begin
OpenDialog1.DefaultExt := 'TSK';
OpenDialog1.Filter := 'Task File|*.TSK';
OpenDialog1.Execute;
if OpenDialog1.FileName = '' then
begin
showmessage('No File Selected');
end else
begin
ClearScreen();
ExtractFilePath(application.ExeName);
AssignFile(f,OpenDialog1.FileName);
Reset(f);
try
while not eof(f) do begin
Readln(f,OpenStr);
ThisTask := tTask.Create(OpenStr);
//In CVS used a Stringlist to Create file;
ListBox1.Items.AddObject(ThisTask.sDescription,tOb ject(ThisTask));
end;
finally
CloseFile(f);
end;
end;
ChangesMade := false;
Statusbar1.Panels[0].Text := OpenDialog1.FileName;
UpDateFileHistory(OpenDialog1.FileName);
MyFileName := OpenDialog1.FileName;
end;
  #3  
07-18-2007, 12:07 AM
Senior Member
 
Join Date: Jul 2001
Posts: 4,195
RE: How to import a csv file into a delphi app?

You may use SMImport suite:
http://www.scalabium.com/smi

With best regards, Mike Shkolnik
http://www.scalabium.com
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Python处理CSV、JSON和XML数据的简便方法
20个日常工作常用的Python脚本
DELPHI得到文件路径的方法 .
DELPHI如何将数据导出到指定格式的EXCEL模版
php 读取csv
Delphi编程:用流来读取TXT文件中的数据
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服