为了制作一些报告,我需要解析一些 excel 文件。当我尝试从工作表中选择记录时,出现下一个错误:名称 '1 的括号无效。页$'。
这是我的代码:
OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [1. page$]", connectionString);
例如,我知道如果我将工作表重命名为“页面”,它将起作用,但由于我没有命名这些工作表,我需要知道如何修复此查询以使其正常工作。我应该怎么办?
我遇到了同样的问题,.
用 a替换了#
它,它可以工作。谢谢!
It looks like your sheet name [1. page$] is invalid. This is OK for an Excel sheet name, but not OK in the query. You should not have the "." in your sheet name.
You can't get around the "." problem. It's just not valid when you are running the query.
SpreadsheetGear for .NET will let you work with Excel files without the limitations imposed by OleDb.
You can see C# and VB samples here and try it yourself by downloading the free trial here.
Disclaimer: I own SpreadsheetGear LLC