Excel OleDb C# – 如果工作表有特殊字符,则无法select范围

从excel中的工作簿中读取信息时,遇到了一个问题,该信息中包含工作表名称中的“#”。 我能够select整个工作表,但不能在工作表中的范围。

码:

using (OleDbConnection conn = new OleDbConnection()) { DataTable dt = new DataTable(); string Import_FileName = "C:/TestExcel/TestWorkbook.xlsm"; conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Import_FileName + ";" + "Extended Properties='Excel 12.0 Xml;HDR=YES;'"; using (OleDbCommand comm = new OleDbCommand()) { comm.CommandText = "Select * from [Sheet #1$A1:A22]"; comm.Connection = conn; using (OleDbDataAdapter da = new OleDbDataAdapter()) { da.SelectCommand = comm; da.Fill(dt); } } } 

下面的查询工作得很好。

 comm.CommandText = "Select * from [Sheet #1$]"; comm.CommandText = "Select * from [Sheet2$A1:A22]"; 

我得到以下exception说,它无法find有问题的表。

 The Microsoft Office Access database engine could not find the object 'Sheet .1$A1:A22'.