public String[] GetExcelSheetNames()
{
System.Data.DataTable dt = null; try
{
if (_oleConn ==null) Open();
// Get the data table containing the schema
dt = _oleConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,
new object[] { null, null, null, "TABLE" } );
if(dt == null)
{
return null;
} String[] excelSheets = new String[dt.Rows.Count];
int i = 0; // Add the sheet name to the string array.
foreach(DataRow row in dt.Rows)
{
string strSheetTableName = row["TABLE_NAME"].ToString();
excelSheets[i] = strSheetTableName.Substring(0,strSheetTableName.Length-1);
i++;
}
return excelSheets;
}
}
结果如下:Cover
Cover$Print_Are
'IN-CALCULATION$
'IN-CALCULATION$'Print_Are
Input
'L1-SUMMARY$
'L1-SUMMARY$'Print_Are
'L1-SUMMARY$'Print_Title
'L2-SUMMARY$
'L2-SUMMARY$'Print_Are
'L2-SUMMARY$'Print_Title
但实际上只有五个sheet: Cover、IN-CALCULATION、Input、L1-SUMMARY、L2-SUMMARY
那其它的是什么呢?真怪,请指教!
{
System.Data.DataTable dt = null; try
{
if (_oleConn ==null) Open();
// Get the data table containing the schema
dt = _oleConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,
new object[] { null, null, null, "TABLE" } );
if(dt == null)
{
return null;
} String[] excelSheets = new String[dt.Rows.Count];
int i = 0; // Add the sheet name to the string array.
foreach(DataRow row in dt.Rows)
{
string strSheetTableName = row["TABLE_NAME"].ToString();
excelSheets[i] = strSheetTableName.Substring(0,strSheetTableName.Length-1);
i++;
}
return excelSheets;
}
}
结果如下:Cover
Cover$Print_Are
'IN-CALCULATION$
'IN-CALCULATION$'Print_Are
Input
'L1-SUMMARY$
'L1-SUMMARY$'Print_Are
'L1-SUMMARY$'Print_Title
'L2-SUMMARY$
'L2-SUMMARY$'Print_Are
'L2-SUMMARY$'Print_Title
但实际上只有五个sheet: Cover、IN-CALCULATION、Input、L1-SUMMARY、L2-SUMMARY
那其它的是什么呢?真怪,请指教!
我也遇到这种问题了的
不知道有些Excel文件为什么会出现这样的情况,我用Sql server倒入Excel数据的时候时候也看到了这种情况的,也出现这些问题。不知道是不是微软的bug。