/// <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

 

相关文章:

  • 2022-02-07
  • 2022-01-29
  • 2021-09-18
猜你喜欢
  • 2021-12-02
  • 2021-06-04
  • 2021-09-18
  • 2022-01-06
  • 2021-11-03
相关资源
相似解决方案