【问题标题】:Error reading excel using asp.net使用asp.net读取excel时出错
【发布时间】:2012-05-29 19:15:51
【问题描述】:

根据我的要求,我成功地从 Asp.net OLEDB 打开和读取 Excel(2003 年和 07 年)数据。

但它只有在我们的 PC 中保持打开 Excel 表时才有效,否则它会给出“外部表格格式错误”。究竟是什么问题?。谁能告诉我。 访问权限有什么问题吗?

我确定它与连接字符串无关。我的代码

protected void Page_Load(object sender, EventArgs e)
        {
            string path = @"C:\Users\abcd\Desktop\raj.xls";
            connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + absoluteDir + ";Extended Properties=\"Excel 8.0;HDR=YES;\"";

            OleDbConnection oledbConn = new OleDbConnection(connStr);
            try
            {

                oledbConn.Open();
                OleDbCommand cmd = new OleDbCommand("SELECT * FROM [Sheet1$]", oledbConn);
                OleDbDataAdapter oleda = new OleDbDataAdapter();
                oleda.SelectCommand = cmd;
                DataSet ds = new DataSet();
                oleda.Fill(ds);
                GridView1.DataSource = ds.Tables[0].DefaultView;
                GridView1.DataBind();
            }
            catch (Exception err)
            {

            }
            finally
            {
                // Close connection
                oledbConn.Close();
            } 
        }

提前致谢

【问题讨论】:

    标签: asp.net asp.net-mvc excel oledb


    【解决方案1】:

    问题在于访问问题。这意味着工作表受密码保护。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多