使用 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 外部表不是预期的格式。
请指教!!
DataSet ds = new DataSet();
da.Fill(ds);当我打开 Excel 程序时,以上代码执行正常.但是在没有打开的情况下,错误将出现在 "da.Fill(ds);"中。错误:OleDbException 外部表不是预期的格式。
请指教!!
解决方案 »
- 有没有简单的方式实现在appSettings放一个集合?
- 如何将SQL SERVER数据库的表导入到excel中
- 解决给分100
- model的成员变量定义为实体类型后在datagridview上只显示实体的类名?
- 200分请教,NAT利用什么原理实现的端口映射?如何用C#实现?
- 页面之间传值
- 求教!winform下dataGrid绑定dataTable,在dataTable上添加一条row,让dataGrid指在这条row上
- 这个是错误提示是什么意思。。。。。。。。。。。。?送分!
- 关于站内短消息的操作问题
- C# 如何实现将文件夹分卷压缩
- Hashtable 按序遍历
- dataGridView的克隆
不过还是建议你先上传到服务器,然后读出来,循环构造写入数据库的sql!
然后试试
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");
}