C#可以获取Excel文件中Sheet的名字

C#可以获取Excel文件中Sheet的名字吗
C#可以获取Excel文件中Sheet的名字吗

我试过WPS的表格可以

可以
要代码么

百度都有

【深圳】Milen(99696619)  14:13:12
可以
需要吗
我有

connection.GetOleDbSchemaTable

通用

@【深圳】Milen 
获取sheet
这个的哦
可能我忘了

 public string GetExcelConn(string filepath)
    {
        string strConn = "";
        int key = getOfficeKey();
        if (key == 1)
        {
            strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + filepath + ";Extended Properties=Excel 8.0;";
        }
        else if (key == 2)
        {
            strConn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " + filepath + ";Extended Properties=Excel 12.0;";
        }
        else if (key == 3)
        {
            strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + filepath + ";Extended Properties=Excel 8.0;";
        }
        else
        {
            strConn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " + filepath + ";Extended Properties=Excel 12.0;";
        }
        return strConn;
    }


    public void GetExcelTableName(string filepath) 
    {
        tableNames.Items.Clear();
        string strConn = GetExcelConn(filepath);

        DataSet ds = new DataSet();
        string tableName=string.Empty;
        using (System.Data.OleDb.OleDbConnection connection = new System.Data.OleDb.OleDbConnection(strConn))
        {
            connection.Open();
            DataTable table = connection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null);

            foreach (DataRow item in table.Rows)
            {
              

                tableNames.Items.Add(item["Table_Name"].ToString());
            }

        }

        
         
    }


DataTable dt= conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null);
//就一行能获取全部Sheet

做excel导入的 下载 http://www.microsoft.com/zh-cn/download/details.aspx?id=13255
服务器只要安装这个就行了
connstr 就我刚才发的
 
oracle 提供了start with connect by 语法结构可以实现递归查询。
原文地址:https://www.cnblogs.com/CharlesGrant/p/3650864.html