[英]How to read a column in a tab-delimited Excel file in C#?
I have some data of an excel file below. 我下面有一些Excel文件的数据。 At first, I figured that reading from the file could be done using the Excel Library then using an OLEDB connection. 最初,我认为可以使用Excel库然后使用OLEDB连接来完成文件的读取。 I managed to get the DocumentNo column data with the OLEDB approach. 我设法通过OLEDB方法获得DocumentNo列数据。 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." 但是,当关闭excel文件时,我无法执行该操作,因为它给出了一个错误,即“外部表不是预期的格式”。 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
I've used FileHelpers for projects similiar to this with good success. 我已经将FileHelpers用于与此类似的项目,并获得了成功。
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. 根据上面的示例数据,您将需要在行类上使用“ [IgnoreFirst(7)]”属性,因为那里有一些标头信息。 (7 is a guess) (7是一个猜测)
I've found NPOI, an open source port of a java library for Excel automation to be lightweight, fast and reliable. 我发现NPOI是轻量,快速和可靠的,它是用于Excel自动化的java库的开源端口。 It can be found here http://npoi.codeplex.com/ . 可以在这里找到http://npoi.codeplex.com/ 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.