1.pdf
response.setHeader("Content-type","application/pdf");
response.setHeader("Content-Disposition", pname);
2.word
uname = "attachment; filename=" + uname + ".doc";
response.setHeader("Content-type","application/msword; charset=GBK");
response.setHeader("Content-Disposition", uname);
3.execel
response.setHeader("Content-type","application/xls");
uname = "attachment; filename=" + uname + ".xls";
response.setHeader("Content-Disposition", uname);
response.setHeader("Content-Type", "application/vnd.ms-excel; charset=GBK");
out.println("内容");
c#
这是我用代码写的导出Excel表格代码,希望对你有帮助。 protected void Button2_Click(object sender, EventArgs e) { string FileName = "balance take notes" + DateTime.Now.ToShortDateString(); string style = @"<style> .text { mso-number-format:\@; } </script> "; Response.ClearContent(); Response.AddHeader("content-disposition", "attachment; filename=" + FileName + ".xls"); Response.ContentType = "application/excel"; Response.Charset = "GBK"; Response.ContentEncoding = System.Text.Encoding.GetEncoding("GBK"); StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); this.GridView1.AllowPaging = false; //屏蔽分页 this.GridView1.DataBind(); this.GridView1.RenderControl(htw); this.GridView1.Dispose(); Response.Write(style); Response.Write(sw.ToString()); Response.End(); } //重写 public override void VerifyRenderingInServerForm(Control control) { }