weiximei hace 6 años
padre
commit
18c03d7222

+ 9
- 1
CODE/smart-community/property-api/pom.xml Ver fichero

@@ -159,7 +159,15 @@
159 159
             <scope>compile</scope>
160 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 172
 	<dependencyManagement>
165 173
 		<dependencies>

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

@@ -74,10 +74,18 @@ public class BaseController {
74 74
                 // TODO Auto-generated catch block
75 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 89
         } catch (Exception ex) {
82 90
             ex.printStackTrace();
83 91
         }

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

@@ -473,17 +473,13 @@ public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements IB
473 473
 
474 474
         InputStream inputStream = null;
475 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 484
         HSSFRow row = sheet.createRow(0);
489 485
         // 创建列
@@ -514,16 +510,16 @@ public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements IB
514 510
         cell = row.createCell(6);
515 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 524
         responseBean.addSuccess(workbook);
529 525
         return responseBean;