我目前正在处理从 excel 到 c# 的导入,但这是第一次这样做,我以为在解决了许多其他问题后连接正常,但我现在收到上述错误。
代码构建得非常好,我找不到任何其他问题,有人有什么想法吗?
using System;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace test_excel
{
class Program
{
static void Main(string[] args)
{
// @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1;';"
string con =
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source='C:\Users\Joshua.cameron\Documents\BullenGrosvenorTest\EstatesITExportSpec.xlsx';Extended Properties='Excel 12.0 Xml;HDR=YES;IMEX=1;';";
// @"Extended Properties='Excel 12.0 Xml;HDR=YES;IMEX=1'";
using (OleDbConnection connection = new OleDbConnection(con))
{
connection.Open();
OleDbCommand command = new OleDbCommand("select * from [Rental Sheet$]", connection);
using (OleDbDataReader dr = command.ExecuteReader())
{
while (dr.Read())
{
var row1ColA = dr[0];
Console.WriteLine(row1ColA);
}
}
}
}
}
}