C# 遍历 EXCEL表名,出现sheet1$和sheet1$_,但是我的表里并没有sheet1_
代码如下: OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
DataTable schemaTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new Object[] { null, null, null, "TABLE" });
var sheet = new string[schemaTable.Rows.Count];
//List the table name from each row in the schema table.
conn.Close();
for (int i = 0; i < schemaTable.Rows.Count; i++)
{
sheet[i] = schemaTable.Rows[i].ItemArray[2].ToString();
} DropDownList1.DataSource = sheet
DropDownList1.DataBind();;//绑定到dropdownlist下
代码如下: OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
DataTable schemaTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new Object[] { null, null, null, "TABLE" });
var sheet = new string[schemaTable.Rows.Count];
//List the table name from each row in the schema table.
conn.Close();
for (int i = 0; i < schemaTable.Rows.Count; i++)
{
sheet[i] = schemaTable.Rows[i].ItemArray[2].ToString();
} DropDownList1.DataSource = sheet
DropDownList1.DataBind();;//绑定到dropdownlist下
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货