protected void excel_Click(object sender, EventArgs e)
{
export("application/ms-excel", "导出.xls");
}
public void export(string fileType, string fileName)
{
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8).ToString());
Response.ContentType = fileType;
//解决乱码问题
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
this.SmartGridView1.RenderControl(hw);
//解决单元格数据类型不同的显示问题
string style = @"<style> .td { mso-number-format:\@; } </style> ";
Response.Write(style);
Response.Write(tw.ToString());
Response.End();
}
//必须列出该方法
public override void VerifyRenderingInServerForm(Control control)
{
}