context.Response.ContentType = "application/x-excel";
string fileName = HttpUtility.UrlEncode("动态数据.xls");
context.Response.AddHeader("Content-Disposition", "attachment:filename=" + fileName);
//增加输出文件的类型
context.Response.AddHeader("Content-Type", "application/ms-excel ");
HSSFWorkbook hkb = new HSSFWorkbook();
HSSFSheet hs = hkb.CreateSheet();
HSSFRow row = hs.CreateRow(0);
HSSFCell cell1 = row.CreateCell(0, HSSFCell.CELL_TYPE_STRING);
cell1.SetCellValue("hello");
row.CreateCell(1, HSSFCell.CELL_TYPE_NUMERIC).SetCellValue(3.14);
hkb.Write(context.Response.OutputStream); |