Win7 64位如何读取Excel文件?

发布于 2024-08-29 13:35:36 字数 234 浏览 8 评论 0原文

我有一个 c# 应用程序,我已将其移至 64 位计算机。此应用程序读入 Excel 文件以获取某些数据输入。我想将此项目构建为 64 位。有什么办法让我的程序读取这个文件吗?我很难相信没有办法使用 Excel 文件作为 64 位应用程序的输入。我已经安装了 Office 2010 64 位以及 2010 Office System Driver Beta:数据连接组件,但没有成功。我确信我只是错过了一些非常简单的东西。

谢谢!! 账单

I have a c# application that I have moved to a 64bit machine. This application reads in an Excel file for some data input. I would like to build this project as 64bit. Is there any way to have my program read in this file? I find it hard to believe that there is no way to use and Excel file as input into a 64bit app. I have installed Office 2010 64 bit as well as the 2010 Office System Driver Beta: Data Connectivity Components with no luck. I'm sure that I'm just missing something really simple.

thanks!!
Bill

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

心清如水 2024-09-05 13:35:36

Windows x64 不支持 Jet OLEDB 驱动程序。相反,您可以使用 Office Interop 库。添加对 Microsoft.Office.Interop.Excel 程序集的引用并尝试以下代码:

using System;
using System.Runtime.InteropServices;
using Microsoft.Office.Interop.Excel;

class Program
{
    static void Main()
    {
        var file = @"C:\work\test.xlsx";
        var excel = new ApplicationClass();
        var workbook = excel.Workbooks.Open(file);
        var worksheet = (_Worksheet)workbook.Worksheets.Item[1];

        // read the value of the first row, first column
        var value = ((Range)worksheet.Cells[1, 1]).Value;
        Console.WriteLine(value);

        workbook.Close(false, file, null);
        Marshal.ReleaseComObject(workbook);
    }
}

请注意,您需要安装 Excel。

The Jet OLEDB driver is not supported on Windows x64. Instead you could use the Office Interop library. Add reference to the Microsoft.Office.Interop.Excel assembly and try the following code:

using System;
using System.Runtime.InteropServices;
using Microsoft.Office.Interop.Excel;

class Program
{
    static void Main()
    {
        var file = @"C:\work\test.xlsx";
        var excel = new ApplicationClass();
        var workbook = excel.Workbooks.Open(file);
        var worksheet = (_Worksheet)workbook.Worksheets.Item[1];

        // read the value of the first row, first column
        var value = ((Range)worksheet.Cells[1, 1]).Value;
        Console.WriteLine(value);

        workbook.Close(false, file, null);
        Marshal.ReleaseComObject(workbook);
    }
}

Note that you will need to have Excel installed.

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