如何在 C# 中读取制表符分隔的 Excel 文件中的列?
我下面有一个Excel文件的一些数据。起初,我认为可以使用 Excel 库然后使用 OLEDB 连接来读取文件。我设法使用 OLEDB 方法获取 DocumentNo 列数据。但是,当Excel文件关闭时,我无法执行该操作,因为它给出了“外部表不是预期格式”的错误。即使文件已关闭,我如何读取该文件?
10/4/2010 Paid Documents for Document Tracking - Customer 1
Paid Documents for Document Tracking - Customer
CoCd Customer Trans.type SG Clearing Clrng doc. Assignment Year DocumentNo Pstng Date Doc. Date Entry Dte Crcy
PLDT 5000007 4 4 1/15/2010 25003413 5000007 2010 408000139 1/7/2010 1/5/2010 1/12/2010 PHP
PLDT 5000007 4 4 1/15/2010 25003634 5000007 2010 408000068 1/5/2010 12/22/2009 1/10/2010 PHP
I have some data of an excel file below. At first, I figured that reading from the file could be done using the Excel Library then using an OLEDB connection. I managed to get the DocumentNo column data with the OLEDB approach. However, when the excel file is closed, I am unable to do the operation because it gives an error that "External table is not in the expected format." How can I read from the file even if it is closed?
10/4/2010 Paid Documents for Document Tracking - Customer 1
Paid Documents for Document Tracking - Customer
CoCd Customer Trans.type SG Clearing Clrng doc. Assignment Year DocumentNo Pstng Date Doc. Date Entry Dte Crcy
PLDT 5000007 4 4 1/15/2010 25003413 5000007 2010 408000139 1/7/2010 1/5/2010 1/12/2010 PHP
PLDT 5000007 4 4 1/15/2010 25003634 5000007 2010 408000068 1/5/2010 12/22/2009 1/10/2010 PHP
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经将 FileHelpers 用于与此类似的项目,并取得了良好的成功。
看看他们的“快速启动分隔”教程。
根据上面的示例数据,您需要在行类上使用“[IgnoreFirst(7)]”属性,因为您在那里有一些标题信息。 (7是猜测)
I've used FileHelpers for projects similiar to this with good success.
Have a look at their "quick start delimited" tutorial.
Based on your sample data above you'll need to use the "[IgnoreFirst(7)]" attribute on your row class because you've got some header information up there. (7 is a guess)
我发现 NPOI,一个用于 Excel 自动化的 Java 库的开源端口,它轻量、快速且可靠。可以在这里找到:http://npoi.codeplex.com/。
I've found NPOI, an open source port of a java library for Excel automation to be lightweight, fast and reliable. It can be found here http://npoi.codeplex.com/.