|
|
@@ -2309,4 +2309,89 @@ public class NewExcelUtil<T> {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ public Result TestExportExcel(List<T> list, String sheetName, String uploadPath) {
|
|
|
+ if (list == null) {
|
|
|
+ list = new ArrayList<T>();
|
|
|
+ }
|
|
|
+ this.list = list;
|
|
|
+ this.sheetName = sheetName;
|
|
|
+ createExcelField();
|
|
|
+ createWorkbook();
|
|
|
+ this.downloadPath=uploadPath;
|
|
|
+ {
|
|
|
+ OutputStream out = null;
|
|
|
+ String filename="";
|
|
|
+ try {
|
|
|
+ // 取出一共有多少个sheet.
|
|
|
+ int sheetNo = (list.size() / sheetSize);
|
|
|
+ for (int index = 0; index <= sheetNo; index++) {
|
|
|
+ createSheet(sheetNo, index);
|
|
|
+ int line=0;
|
|
|
+ // 产生一行
|
|
|
+ Row title = sheet.createRow(line);
|
|
|
+ Cell cell = title.createCell(0);
|
|
|
+ cell.setCellValue(sheetName);
|
|
|
+ CellRangeAddress region = new CellRangeAddress(0, 0, 0, fields.size()-1);
|
|
|
+ sheet.addMergedRegion(region);
|
|
|
+ cell.setCellStyle(styles.get("total"));
|
|
|
+ if (StringUtils.isNotEmpty(screen)){
|
|
|
+ log.debug(screen);
|
|
|
+ Row r = sheet.createRow(++line);
|
|
|
+ Cell c = r.createCell(0);
|
|
|
+ c.setCellValue(screen);
|
|
|
+ CellRangeAddress rg = new CellRangeAddress(line, line, 0, fields.size()-1);
|
|
|
+ sheet.addMergedRegion(rg);
|
|
|
+ c.setCellStyle(styles.get("header"));
|
|
|
+ }
|
|
|
+ Row row = sheet.createRow(++line);
|
|
|
+ // 产生一行
|
|
|
+ int column = 0;
|
|
|
+ // 写入各个字段的列头名称
|
|
|
+ List<Object[]> fieldsList=new ArrayList<>();
|
|
|
+ for (Object[] os : fields) {
|
|
|
+ Excel excel = (Excel) os[1];
|
|
|
+ String [] ss={"销售类型","订单类型","结算类型","催款节点","是否会员","大客户","是否特批"};
|
|
|
+ for (String s : ss) {
|
|
|
+ if (excel.name().equals(s)){
|
|
|
+ fieldsList.add(os);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (Object[] os : fieldsList) {
|
|
|
+ Excel excel = (Excel) os[1];
|
|
|
+ this.createCell(excel, row, column++);
|
|
|
+ }
|
|
|
+ fields.clear();
|
|
|
+ fields.addAll(fieldsList);
|
|
|
+ filename = encodingFilename(sheetName);
|
|
|
+ out = Files.newOutputStream(Paths.get(getAbsoluteFile(filename)));
|
|
|
+ fillMergeExcelData(index,++line);
|
|
|
+ //新增合并
|
|
|
+// mergeOrderNo();
|
|
|
+ addStatisticsRow();
|
|
|
+ }
|
|
|
+ wb.write(out);
|
|
|
+ return new Result().data(filename);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new BusinessException("导出Excel失败,请联系网站管理员!");
|
|
|
+ } finally {
|
|
|
+ if (wb != null) {
|
|
|
+ try {
|
|
|
+ wb.close();
|
|
|
+ } catch (IOException e1) {
|
|
|
+ e1.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (out != null) {
|
|
|
+ try {
|
|
|
+ out.close();
|
|
|
+ } catch (IOException e1) {
|
|
|
+ e1.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|