当工作表名称为" Sheet1"时,我的代码将读取excel文件。我想知道是否有办法阅读任何工作表名称?例如:(TaxForm或EmployeeList)
private DataTable readExcelFile(string path)
{
string excelConn = @"Provider=Microsoft.Jet.Oledb.4.0; Data Source=" + path + "; Extended Properties=Excel 8.0;";
System.Data.OleDb.OleDbConnection oleConn = new System.Data.OleDb.OleDbConnection(excelConn);
DataTable xlsDs = new DataTable();
try
{
if (!string.IsNullOrEmpty(path))
{
string strSQL = "SELECT * from [Sheet1$]";
System.Data.OleDb.OleDbDataAdapter oleDa = new System.Data.OleDb.OleDbDataAdapter(strSQL, oleConn);
oleDa.Fill(xlsDs);
}
}