weiximei 6 years ago
parent
commit
18c03d7222

+ 9
- 1
CODE/smart-community/property-api/pom.xml View File

159
             <scope>compile</scope>
159
             <scope>compile</scope>
160
         </dependency>
160
         </dependency>
161
 
161
 
162
-    </dependencies>
162
+		<!-- https://mvnrepository.com/artifact/com.alibaba/easyexcel -->
163
+		<dependency>
164
+			<groupId>com.alibaba</groupId>
165
+			<artifactId>easyexcel</artifactId>
166
+			<version>1.1.2-beat1</version>
167
+		</dependency>
168
+
169
+
170
+	</dependencies>
163
 
171
 
164
 	<dependencyManagement>
172
 	<dependencyManagement>
165
 		<dependencies>
173
 		<dependencies>

+ 12
- 4
CODE/smart-community/property-api/src/main/java/com/community/huiju/common/base/BaseController.java View File

74
                 // TODO Auto-generated catch block
74
                 // TODO Auto-generated catch block
75
                 e.printStackTrace();
75
                 e.printStackTrace();
76
             }
76
             }
77
-            response.setContentType("application/octet-stream;charset=ISO8859-1");
78
-            response.setHeader("Content-Disposition", "attachment;filename="+ fileName);
79
-            response.addHeader("Pargam", "no-cache");
80
-            response.addHeader("Cache-Control", "no-cache");
77
+//            response.setContentType("application/octet-stream;charset=ISO8859-1");
78
+//            response.setHeader("Content-Disposition", "attachment;filename="+ fileName);
79
+//            response.addHeader("Pargam", "no-cache");
80
+//            response.addHeader("Cache-Control", "no-cache");
81
+
82
+            response.setContentType("application/x-download");//下面三行是关键代码,处理乱码问题
83
+
84
+            response.setCharacterEncoding("utf-8");
85
+
86
+            //设置浏览器响应头对应的Content-disposition
87
+
88
+            response.setHeader("Content-disposition", "attachment;filename="+new String(fileName.getBytes("gbk"), "iso8859-1")+".xls");
81
         } catch (Exception ex) {
89
         } catch (Exception ex) {
82
             ex.printStackTrace();
90
             ex.printStackTrace();
83
         }
91
         }

+ 15
- 19
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/impl/BillServiceImpl.java View File

473
 
473
 
474
         InputStream inputStream = null;
474
         InputStream inputStream = null;
475
         HSSFWorkbook workbook = null;
475
         HSSFWorkbook workbook = null;
476
-        try {
477
-            inputStream = new FileInputStream("缴费单模板.xls");
478
-            workbook = new HSSFWorkbook(inputStream);
479
-        } catch (FileNotFoundException e) {
480
-            e.printStackTrace();
481
-        } catch (IOException e) {
482
-            e.printStackTrace();
483
-        }
476
+
477
+            //inputStream = this.getClass().getResourceAsStream("/缴费单模板.xls");
478
+            workbook = new HSSFWorkbook();
479
+
484
 
480
 
485
        
481
        
486
-        HSSFSheet sheet = workbook.createSheet("缴费单");
482
+        HSSFSheet sheet = workbook.getSheet("Sheet1");
487
         // 创建行
483
         // 创建行
488
         HSSFRow row = sheet.createRow(0);
484
         HSSFRow row = sheet.createRow(0);
489
         // 创建列
485
         // 创建列
514
         cell = row.createCell(6);
510
         cell = row.createCell(6);
515
         cell.setCellValue("金额(元)");
511
         cell.setCellValue("金额(元)");
516
 
512
 
517
-        String [] [] data = new String[][] {{"1区","0", "0", "0", "0", "示例忽删", "12.34", "<-示例"}};
518
-        int crrentRow = 5;
519
-        // 行数
520
-        for (int i = 0; i < data.length; i++) {
521
-            row = sheet.createRow(i + crrentRow);
522
-            for (int t = 0; t < data[i].length; t++) {
523
-                cell = row.createCell(t);
524
-                cell.setCellValue(data[i][t]);
525
-            }
526
-        }
513
+//        String [] [] data = new String[][] {{"1区","0", "0", "0", "0", "示例忽删", "12.34", "<-示例"}};
514
+//        int crrentRow = 5;
515
+//        // 行数
516
+//        for (int i = 0; i < data.length; i++) {
517
+//            row = sheet.createRow(i + crrentRow);
518
+//            for (int t = 0; t < data[i].length; t++) {
519
+//                cell = row.createCell(t);
520
+//                cell.setCellValue(data[i][t]);
521
+//            }
522
+//        }
527
 
523
 
528
         responseBean.addSuccess(workbook);
524
         responseBean.addSuccess(workbook);
529
         return responseBean;
525
         return responseBean;