【问题标题】:Get Index of the Excel Sheet using asp.net使用 asp.net 获取 Excel 工作表的索引
【发布时间】:2009-06-18 12:27:42
【问题描述】:

我正在使用以下代码从 excel 中提取工作表名称:(见附件代码)

但是返回的数据是按工作表的名称排序的,这就是问题所在。我需要按索引提取第一张纸的名称。

我该怎么做?

String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
                                          "Data Source=" + fileSavePath + newFileName + ".xls; Extended Properties='Excel 8.0;HDR=NO;'";

OleDbConnection objConn = new OleDbConnection(sConnectionString);

objConn.Open();

// Get the data table containg the schema guid.
DataTable dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
 string sheetName = "Sheet1$";

if (dt != null) {
    try {
            String[] excelSheets = new String[dt.Rows.Count];

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

             sheetName = excelSheets[0];
        }
        catch {
                 sheetName = "Sheet1$";
          }
   }

【问题讨论】:

    标签: asp.net excel


    【解决方案1】:

    尝试扩展 Sheet Gear 第三方组件

    http://www.spreadsheetgear.com

    【讨论】:

      猜你喜欢
      • 2018-07-21
      • 2013-06-27
      • 1970-01-01
      • 1970-01-01
      • 2021-05-30
      • 2012-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多