终极目标

——永远的博客

导航

如何在.net中判断excel的sheet是否存在

Posted on 2012-10-28 23:17  Eric  阅读(698)  评论(0编辑  收藏  举报

来源: http://www.notetoday.cn/opennote/View?noteId=50

oledbconn1.ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0;data source="+openFileDialog1.FileName+";Extended Properties=Excel 8.0;Persist Security Info=False";

oledbconn1.Open(); 

DataTable dt = oledbconn1.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new objec] {null, null, null, "TABLE"}); 

If(dt !=null && dt.Rows >0)
{
  DataRow[] dr = dt.Select("TABLE_NAME = '"+sheet名+"'");
if(dr == null || dr.Lenght = 0)
{
不包含
}
}