【问题标题】:Get sheets names from excel ASP.Net从 excel ASP.Net 获取工作表名称
【发布时间】:2016-12-19 19:43:17
【问题描述】:

我正在获取按下一个代码按字母顺序排序的工作表名称。

        OleDbConnection connection = new OleDbConnection(string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}; Extended Properties=\"Excel 8.0;HDR=No;\"", filePath));
        OleDbCommand command = new OleDbCommand();
        DataTable tableOfData = null;
        command.Connection = connection;
        try
        {
            connection.Open();
            tableOfData = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
            string tablename = tableOfData.Rows[0]["TABLE_NAME"].ToString();
            tableOfData = new DataTable();
            command.CommandText = "Select * FROM [" + tablename + "]";
            tableOfData.Load(command.ExecuteReader());
        }
        catch (Exception ex)
        {
        }

我只想按照原始顺序阅读它们。有什么想法吗?

【问题讨论】:

  • 有什么问题?你遇到了什么错误?
  • 代码返回第一张按字母顺序排列的不是实际的第一张。

标签: asp.net c excel oledb


【解决方案1】:

经过多次搜索,我发现“OLEDB”不支持按原始顺序阅读工作表(仅按字母顺序阅读工作表名称),但有很多方法支持从 excel 文件中按原始顺序阅读工作表名称。

帮助链接:Reading sheets in original order from excel file,
OLEDB does not preserve the sheet order as they were in Excel.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多