用NPOI导出Excel

用NPOI导出Excel

用NPOI导出Excel
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/x-excel";
            //context.Response.ContentType = "application/octet-stream";

            string fileName = HttpUtility.UrlEncode("动态数据库.xls");
            context.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);

            HSSFWorkbook workbook = new HSSFWorkbook();
            HSSFSheet sheet = (HSSFSheet) workbook.CreateSheet();
            HSSFRow row = (HSSFRow)sheet.CreateRow(0);

            HSSFCell cell1 = (HSSFCell)row.CreateCell(0, HSSFCell.ENCODING_COMPRESSED_UNICODE);
            cell1.SetCellValue("Hello");

            HSSFCell cell2 = (HSSFCell)row.CreateCell(1, HSSFCell.ENCODING_COMPRESSED_UNICODE);
            cell2.SetCellValue(3.14);

            workbook.Write(context.Response.OutputStream);
        }
View Code

用NPOI导出Excel

上一篇:轿车违章罚款攻略


下一篇:对control file的学习笔记