如何将datagridview中的数据快速导出到excel中?
各位大家好,我是通过一个单元格一个单元格输出的,但是在运行的时候系统会优先导出操作,导致用户无法进行其他操作,请问有什么好的办法?
------解决方案--------------------用一下打印控件 里面有一个导出数据
------解决方案--------------------
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataSet ds = new SHS.BLL.shengOnline().GetAllList();
gvUser.DataSource = ds;
gvUser.DataBind();
}
}
public override void VerifyRenderingInServerForm(Control control) //重载方法
{
//base.VerifyRenderingInServerForm(control);
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.xls");
//gaoyang [10/21/2006] 经测试如果设置为 GetEncoding("GB2312"),导出的文件将会出现乱码。
Response.ContentEncoding = System.Text.Encoding.UTF7;
//设置输出文件类型为excel文件
Response.ContentType = "application/ms-excel";
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.gvUser.RenderControl(oHtmlTextWriter);
Response.Output.Write(oStringWriter.ToString());
Response.Flush();
Response.End();
}
<font color="red">-------------------------------------------</font>
这是 将GridView中的导出到Excel,你可以进行更改