jz.kai 5 yıl önce
ebeveyn
işleme
4658d99350

+ 10 - 17
web/src/main/java/com/jpsoft/smart/modules/base/controller/PersonInfoController.java

@@ -664,32 +664,25 @@ public class PersonInfoController {
             HSSFWorkbook workbook = new HSSFWorkbook();
 
             //创建工作簿
-            HSSFSheet sheet = workbook.createSheet("商品信息汇总");
+            HSSFSheet sheet = workbook.createSheet();
 
             //创建标题
-            //指定标题所在的行
             HSSFRow row = sheet.createRow(0);
-            //指定标题所在的列
             HSSFCell cell = row.createCell(0);
-            //设定单元格样式
-            HSSFCellStyle cellStyle = workbook.createCellStyle();
-
-            HSSFFont font = workbook.createFont();
-            font.setFontName("黑体");
-            font.setFontHeightInPoints((short) 14);
-            cellStyle.setFont(font);
-
-            cellStyle.setFillBackgroundColor((short)56);
-
             cell.setCellValue("商品信息汇总");
-            cell.setCellStyle(cellStyle);
 
 
             //将exal输出到哪个文件夹中
-            FileOutputStream fileOutputStream = new FileOutputStream(new File("C:\\Users\\D.K\\Desktop\\test.xls"));
-            workbook.write(fileOutputStream);
-            fileOutputStream.close();
+            //FileOutputStream fileOutputStream = new FileOutputStream(new File("C:\\Users\\D.K\\Desktop\\test.xls"));
+            ByteArrayOutputStream out = new ByteArrayOutputStream();
+            workbook.write(out);
             workbook.close();
+
+            String fileName = new String("导出数据".getBytes("UTF-8"), "iso-8859-1");
+            response.setContentType("application/x-msdownload");
+            response.setHeader("Content-Disposition", "attachment;fileName=" + fileName + ".xls");
+            response.getOutputStream().write(out.toByteArray());
+            response.getOutputStream().flush();
         }
         catch(Exception ex){
             logger.error(ex.getMessage(),ex);