[英]How to export data of WebDataGridview to an existing Excel sheet?
我有一个Webdatagridview,我想将它的数据(不包括标题,因为我的excel文件已经有标题)导出到我现有的Excel文件中。
如果使用的是Infragistics WebDataGrid,则可以使用WebExcelExporter并为采用工作簿或工作表实例的Export方法使用重载。
为了防止标题,在调用Export之前,将要导出的WebDataGrid的ShowHeader属性设置为false。 请注意,由于将响应更改为将excel文件发送到客户端,因此不需要将其重新设置为true,因此对于此请求发送到客户端的网格没有状态信息。
尝试:
protected void ExportToExcel()
{
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "attachment;filename=YourFiles.xls");
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter sr = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htw= new System.Web.UI.HtmlTextWriter(sr);
gvFiles.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.