使用 ado.net 导 Excel 表格数据时,Excel 程序是否需要打开??OleDbDataAdapter da = new OleDbDataAdapter("select * from [报表$]", @"Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;data source=D:\表.xls");
            DataSet ds = new DataSet();
            da.Fill(ds);当我打开 Excel 程序时,以上代码执行正常.但是在没有打开的情况下,错误将出现在 "da.Fill(ds);"中。错误:OleDbException 外部表不是预期的格式。
请指教!!

解决方案 »

  1.   

    ADO.Net操作Excel数据文件时,Excel都可以不安装在电脑上。所以不需要运行Excel。
      

  2.   

    你是否是从Sheet1导?名字如果不是Sheet1的话可能会有问题!
    不过还是建议你先上传到服务器,然后读出来,循环构造写入数据库的sql!
      

  3.   

    在能打开后关掉Excel 再Update下
    然后试试
      

  4.   

    不需要.
     private void Export(string FileType, string FileName)
            {//導出Excel 
                Response.Charset = "UTF-8";
                Response.ContentEncoding = System.Text.Encoding.UTF7;
                Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
                Response.ContentType = FileType;
                this.EnableViewState = false;
                StringWriter tw = new StringWriter();
                HtmlTextWriter hw = new HtmlTextWriter(tw);
                GridView1.RenderControl(hw);
                Response.Write(tw.ToString());
                Response.End();
            }
            public override void VerifyRenderingInServerForm(Control control)
            {        }        protected void bt_ExportSLX_Click(object sender, EventArgs e)
            {
                Export("application/ms-excel", "ExportXLS.xls");
            }