如何在 C# 中读取制表符分隔的 Excel 文件中的列?

发布于 2024-10-09 04:19:21 字数 936 浏览 0 评论 0原文

我下面有一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

明明#如月 2024-10-16 04:19:22

我已经将 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)

看轻我的陪伴 2024-10-16 04:19:22

我发现 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/.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文