protected void btnOutput_Click(object sender, EventArgs e)
{
OutPut("attachment;filename=OutPut.xls", "application/ms-excel");
this.Response.Write("<Script>alert(请查询!)</script>");
不支持中文,会乱玛
//string style = @"<style> .text { mso-number-format:/@; } </script> ";
//Response.ClearContent();
//Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls");
//Response.ContentType = "application/excel";
//StringWriter sw = new StringWriter();
//HtmlTextWriter htw = new HtmlTextWriter(sw);
//GridView1.RenderControl(htw);
Style is added dynamically;
//Response.Write(style);
//Response.Write(sw.ToString());
//Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
private void OutPut(string fileType, string strType)
{
支持中文
Response.Buffer = true;
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application nd.ms-excel";
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.AddHeader("Content-Disposition", "attachment;filename=Plan.xls");
Response.Write("<meta http-equiv=Content-Type content=text/html;charset=GB2312>");
EnableViewState = false;
StringWriter swOut = new StringWriter();
HtmlTextWriter hTw = new HtmlTextWriter(swOut);
GridView1.RenderControl(hTw);
Response.Write(swOut.ToString());
Response.End();
}