C#操作Excel(搜集)

it2024-11-18  9

      /// <summary>    /// 使用oledb连接Excel    /// </summary>    /// <param name="_fileUrl"></param>    /// <param name="pageName"></param>    /// <returns></returns>    public DataSet ExcelConn(string _fileUrl, string pageName)    {        string filePath = _fileUrl;        OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="            + filePath + ";Extended Properties=\"Excel 8.0;IMEX=1\"");        conn.Open();        OleDbCommand cmd = new OleDbCommand("SELECT   *   FROM   [" + pageName + "$]", conn);        OleDbDataAdapter da = new OleDbDataAdapter(cmd);        DataSet ds = new DataSet();        da.Fill(ds);

        conn.Close();        return ds;    }

 

实例:导入Excel.rar

 

转载于:https://www.cnblogs.com/wuhenke/archive/2010/04/08/1707710.html

相关资源:C# Excel导出无需安装Excel
最新回复(0)