EXCEL导出至服务器指定位置
新手刚接触.net,现在需要把GridView的内容存在excel后保存在服务器指定位置,在网上找到了ToExcel函数,实现了将GridView的内容复制到excel,可是是将excel保存到客户端,会有小框 【打开】【保存】【取消】,怎么能实现将excel保存在服务器指定位置?新手求指教。
private void ToExcel(Control ctl, string FileName)
{
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + "" + FileName);
ctl.Page.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
ctl.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
}
private void ToExcel(Control ctl, string FileName)
{
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + "" + FileName);
ctl.Page.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
ctl.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
}
...全文
相关推荐
SQL Server2008导出数据之Excel详细解析
本篇主要介绍如何详细地从SQL Server 2008导出数据至Excel。1. **准备工作**: 在开始导出前,你需要在计算机上创建一个空白的Excel表格。这将作为数据的目标位置。
SQL使用存储过程导入和导出Excel
“c:\\test.xls”表示Excel文件的位置,“sheet1$”是指Excel工作表的名称。2.
sqlserver导出excel(操作图解)
导出完成后,你可以在指定位置找到生成的Excel文件,其中包含了从SQL Server查询中提取的数据。
Vue通过Blob对象实现导出Excel功能示例代码
在这个例子中,通过axios向服务器发送请求,并设置`responseType`为`blob`,以期望服务器返回二进制流格式的数据,这对于导出Excel文件至关重要。
利用js导出Web页面内容到Word、Excel
**导出页面指定区域内容到Excel** ```javascript function AllAreaExcel() { var oXL = new ActiveXObject("Excel.Application


