简体   繁体   中英

How to read a column in a tab-delimited Excel file in C#?

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

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)

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/ .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM