I am using ASP.NET to open an Excel 2003 document hosted on the server. The excel spreadsheet, produced by a system outside of my control, has 5 named worksheets. I access the data in each sheet as follows (line breaks added for readability):
string ExcelConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\sample.xls;
Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1;\";";
OleDbDataAdapter myData =
new OleDbDataAdapter("SELECT * FROM [mysheet]", ExcelConn);
myData.TableMappings.Add("Table", "mysheet");
myData.Fill(ExcelDS);
This works for 3 of the 5 sheets. The other two throw this error:
The Microsoft Jet database engine could not find the object 'mysheet'. Make sure the object exists and that you spell its name and the path name correctly.
I have quadruple-checked the sheet name by examining the text in the bottom tab and also by examining the end of the string that this produces in Excel:
=CELL("filename")
c:\[sample.xls]mysheet
The connection string is specified once and reused for all 5 sheets.
Is it possible that I need to reference the sheet with a string that doesn't match the name that is visible in Excel? Maybe hidden characters, spaces, etc.? Is there another way to find the true name of the sheet? Any other suggestions for retrieving this data?
Note: I cannot modify the Excel document (I would have used SSIS to import CSV if I could have it my way).
I'm using .NET 3.5 / II6.