C# 使用 OLEDB 在没有办公室的情况下获取 excel 个工作表

C# get excel worksheets without office unsing OLEDB

我阅读了一些关于此主题的其他线程,但它仍然不起作用,我不知道为什么。

存在异常:'Microsoft.ACE.OLEDB.12.0'- 提供程序未在本地计算机上注册。我已经为 Office 2007 和 2010 安装了数据库引擎。

你有什么想法吗?

OS: Win 7 教授 64 位

static void Main(string[] args)
        {
            OleDbConnection connection = null;
            DataTable Sheets = null;

            String file = args[0];
            String filePath = Path.GetDirectoryName(args[0]);
            String connPath = "";

            if(Path.GetExtension(file).Equals(".xls"))
                connPath = "Provider=Microsoft.Jet.OleDb.4.0; Data Source=" + file + ";Extended Properties=Excel 8.0";
            else
                connPath = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + file + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=1\"";

            try
            {
                connection = new OleDbConnection(connPath);
                connection.Open();

            Sheets = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

...

找到了。您需要为 x86 CPU 编译项目。而 CPU 将不起作用。

谢谢