在VB.Net中读取一个大的.xls文件 [英] Read a large .xls file in VB.Net

查看:55
本文介绍了在VB.Net中读取一个大的.xls文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要读取包含8列的.xls文件,列号为1320905829的第1列是密钥,它与此密钥有相关记录。就像我有一个

大的excel文件,它是16MB,其中有近226000条记录。为了避免任何内存泄漏,在VB.net中处理大型.xls文件的最佳方法是什么。是否有任何人有任何示例代码来处理此建议或任何建议。

有没有人认为将excel文件读入数据表是最好的开始方式。随着文件的增长,处理这种情况的最佳方法是什么。有时候文件

也可能超过16MB。这取决于。

主要目的是稍后将密钥id与.txt文件中的相关记录进行比较。

Hi,
I need to read .xls file which has 8 columns and column 1 which has id number like 1320905829 is the key and it has related records to this key. Like that I have a
big excel file which is 16MB and almost 226000 records in it. To avoid any memory leaks what is the best way to handle reading a large .xls file in VB.net. Does any one has any sample code to deal this or any suggestions.
Does anyone think reading the excel file into datatables is the best way to start. As the file grows what is the best way to handle this situation. some times the file
can be more than 16MB too. It depends.
The main purpose is to compare the key id with related records in a .txt file later on.

推荐答案

a)到目前为止你没有说过'你需要立刻将整个文件读入内存'

b)它是一个真正的xls文件 - 或者是'csv'类型的数据,在一个名为的文件中xls所以人们可以在资源管理器中点击它并在Excel中打开它(这有很大的不同)



我会

1)总结你的'.txt'文件中的相关记录,可能会将密钥ID等存储在字典中

2)然后我会打开一个StreamReader并从你的excel文件中逐行读取,如果它实际上是' csv',处理/检查字典



这意味着'xls'文件可以增长到它需要的大小,它总是从磁盘缓冲



你提到的那些尺寸 - 16MB / 22600的记录真的不大,顺便说一下,除非你使用的是8bit-CP U运行CP / M等 - 今天的64Bit机器有更多的内存
a) Nothing you've said so far says 'you need to read the entire file into memory at once'
b) is it really an xls file - or is it 'csv' type data, in a file named xls so people can click on it in Explorer and have it open in Excel (there's a big difference)

I would
1) summarise the related records in your '.txt' file, possibly storing the key id's etc in a Dictionary
2) Then I would open a StreamReader and read from your excel file, line by line if its actually 'csv', processing/checking against the Dictionary

that means the 'xls' file can grow as large as it needs to, its always buffered from disk

Those sizes you mention - 16MB/22600 records arent really that big, btw, unless you're on an 8bit-CPU running CP/M or such - todays 64Bit machines have way more memory


这篇关于在VB.Net中读取一个大的.xls文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆