首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

怎么快速从文本文件导入数据到excel

2012-02-24 
如何快速从文本文件导入数据到excel我的文本文件有100万条记录,每行一个数据,需要保存到excel文件的一个表

如何快速从文本文件导入数据到excel
我的文本文件有100万条记录,每行一个数据,需要保存到excel文件的一个表中,每列放50000个,我现在采用的方法是先将文本文件的数据读到tstringlist中,然后再把tstringlist的数据一个一个的存到excel的格子里面,这样的操作过程大概要20分钟,太慢了,请教能够提速的方法?

[解决办法]
你可以采用读文件方式来读取文本文件。
[解决办法]
方法1:用行模式读取文本文件,同时用流模式写入到excel文件中!
方法2:如果你的文本文件是使用类似一行一个记录,每个字段之间用,分割的话,那么你干脆就把你的文本文件的后缀名修改为.csv,然后就可以直接用excel打开了!
[解决办法]
Creates an instance of TFileStream.

Delphi syntax:

constructor Create(const FileName: string; Mode: Word); overload;
constructor Create(const FileName: string; Mode: Word; Rights: Cardinal); overload; 

Description

Call Create to instantiate a file stream for reading from or writing to the named file. Specify the name of the file and the way the file should be opened as parameters.

The Mode parameter indicates how the file is to be opened. The Mode parameter consists of an open mode and (possibly) a share mode or抏d together. The open mode must be one of the following values:

ValueMeaning

fmCreateCreate a file with the given name. If a file with the given name exists, open the file in write mode.
fmOpenReadOpen the file for reading only.
fmOpenWriteOpen the file for writing only. Writing to the file completely replaces the current contents.
fmOpenReadWriteOpen the file to modify the current contents rather than replace them.

The share mode must be one of the following values:

ValueMeaning

fmShareCompatSharing is compatible with the way FCBs are opened.
fmShareExclusiveOther applications can not open the file for any reason.
fmShareDenyWriteOther applications can open the file for reading but not for writing.
fmShareDenyReadOther applications can open the file for writing but not for reading.
fmShareDenyNoneNo attempt is made to prevent other applications from reading from or writing to the file.

The Rights parameter indicates the permission bits with which to create the file on Linux when Mode is fmCreate. Rights is ignored when used on the Windows platform.

If the file can not be opened, Create raises an exception.

热点排行