读取Excel工作表名称 [英] Read Excel Sheet name

查看:111
本文介绍了读取Excel工作表名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从Excel工作表中读取工作表名称


how to read sheet name from Excel sheet


dtExcelSchema = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,null);

         for (int i = 0; i < dtExcelSchema.Rows.Count; i++)
         {
             drpsheet.DataSource=dtExcelSchema.Rows[i]["Table_Name"].ToString().Replace("$","");
         }

         //TableName.Rows[0]["ColumnName"].ToString();
         drpsheet.DataBind();

推荐答案

", "); } // TableName.Rows [0] ["ColumnName"].ToString(); drpsheet.DataBind();
",""); } //TableName.Rows[0]["ColumnName"].ToString(); drpsheet.DataBind();


我记得前一段时间的一篇旧文章,那个家伙使用字符串数组获取所有工作表.
不是百分百确定,但是我会说这样.
Havent经过测试的代码,但工作表名称应添加到数组中.

int i = 0;
String [] xSheets =新的String [dtExcelSchema.rows.count];

foreach(dt.rows中的DataRow行)
{
xSheets [i] = row ["tablename"].ToString();
i ++;
}
I remember an old post a while ago where the guy used a string array to get all sheets.
Not hundred percent sure but off the bat i would say something like this.
Havent tested code but sheet names should be added to the array.

int i = 0;
String[] xSheets = new String[dtExcelSchema.rows.count];

foreach(DataRow row in dt.Rows)
{
xSheets[i] = row["tablename"].ToString();
i++;
}




请参阅以下代码.可能会对您有帮助.
Hi,

See the following code. It might be help you.
String connString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
          "Data Source=" + excelFile + ";Extended Properties=Excel 8.0;";
        objConn = new OleDbConnection(connString);
        objConn.Open();
        
        dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

        if(dt == null)
        {
           return null;
        }

        String[] excelSheets = new String[dt.Rows.Count];
        int i = 0;
        
        foreach(DataRow row in dt.Rows)
        {
           excelSheets[i] = row["TABLE_NAME"].ToString();
           i++;
        }



致谢,
Viprat



Thnaks,
Viprat


这篇关于读取Excel工作表名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆