我有 ac# 应用程序已移至 64 位机器。此应用程序读入 Excel 文件以获取一些数据输入。我想将此项目构建为 64 位。有什么办法可以让我的程序读入这个文件?我很难相信没有办法使用 Excel 文件作为 64 位应用程序的输入。我已经安装了 Office 2010 64 位以及 2010 Office System Driver Beta:数据连接组件,但没有成功。我确定我只是错过了一些非常简单的东西。
谢谢!!账单
我有 ac# 应用程序已移至 64 位机器。此应用程序读入 Excel 文件以获取一些数据输入。我想将此项目构建为 64 位。有什么办法可以让我的程序读入这个文件?我很难相信没有办法使用 Excel 文件作为 64 位应用程序的输入。我已经安装了 Office 2010 64 位以及 2010 Office System Driver Beta:数据连接组件,但没有成功。我确定我只是错过了一些非常简单的东西。
谢谢!!账单
Windows x64 不支持 Jet OLEDB 驱动程序。相反,您可以使用 Office 互操作库。添加对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。