简体   繁体   中英

Read range Excel Sheet using OleDB

I want to read from an excel file using OleDbDataReader

string con= "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ruta + ";" + "Extended Properties='Excel 12.0 Xml;HDR=YES;'";
using (OleDbConnection connection = new OleDbConnection(con))
{
    connection.Open();
    OleDbCommand command = new OleDbCommand("Select * FROM [Template$A1:JB2435]", connection);

But when I run this code, this error shows in runtime

The Microsoft Access database engine could not find the object 'Template$A1:JB2435'. Make sure the object exists and that you spell its name and the path name correctly

If i don't put the range the program works, but I want to select a range from that Excel sheet

I have found the problem. Apparently the Excel file has to be closed, if it's open it says that error...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM