2013-05-03 4 views
0
private void readXLSData() 
    { 
     OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\nsharifzadeh\\Desktop\\Book1.xls;Extended Properties=""Excel 8.0;HDR=YES;"""); 
     con.Open(); 
     OleDbDataAdapter da = new OleDbDataAdapter("select * from [Sheet1$]", con); 
     DataSet ds = new DataSet(); 
     da.Fill(ds); 
    } 

나는 디버거를 사용하고,이 말을 다음 da.Fill(ds) 그것은 폭탄에 모든 방법을 작동하는 것 같군 :OleDbConnection 클래스 (또는 다른 것)를 사용하여 XLS 파일을 읽는 방법?

*The Microsoft Jet database engine could not find the object 'Sheet1$'. Make sure the object exists and that you spell its name and the path name correctly.*

내가 시트의 이름은 Sheet1의 맹세! 내가 여기서 잘못하고있는 것이 있습니까 ??

도움 주셔서 감사합니다. 당신이 시도 할 수

+0

문제가되지해야합니까? (탭에) 하단에, 그것은 워크 시트입니까, 아니면 이름을 변경 했습니까? – Derek

답변

1

것은 때때로 시트 이름은 Sheeet1 $ '

OleDbDataAdapter da = new OleDbDataAdapter("select * from ['Sheet1$']", con); 

경우 그 나던 작업'처럼 ... 주위 ''이 필요합니다. 당신의 연결에 이것을 시도하십시오. 이제

DataTable schemaTable = con.GetSchema("TABLES"); 
foreach (DataRow dataRow in con.Rows) 
{ 
    //tablename = rowData[2] check those contents to see the sheet names in the excel spreadsheet. 
} 

나는 엑셀 12.0 Microsoft.ACE.OLEDB.12.0와 협력했지만,이 워크 시트의 이름이야 무엇