|
|
@@ -179,12 +179,6 @@ public class NewExcelUtil<T> {
|
|
|
|
|
|
private void exportExcel(HttpServletResponse response) {
|
|
|
try {
|
|
|
- log.debug("导出至本地开始");
|
|
|
-
|
|
|
- if (list.isEmpty()){
|
|
|
- log.debug("导出数据为空");
|
|
|
- }else{
|
|
|
- log.debug("导出数据"+list.size());
|
|
|
OutputStream out = response.getOutputStream();
|
|
|
// 取出一共有多少个sheet.
|
|
|
int sheetNo = (int) Math.ceil(list.size() / sheetSize);
|
|
|
@@ -213,7 +207,6 @@ public class NewExcelUtil<T> {
|
|
|
wb.write(out);
|
|
|
out.flush();
|
|
|
out.close();
|
|
|
- }
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
throw new BusinessException("导出Excel失败,请联系网站管理员!");
|
|
|
@@ -254,36 +247,37 @@ public class NewExcelUtil<T> {
|
|
|
*/
|
|
|
public Result exportExcel() {
|
|
|
OutputStream out = null;
|
|
|
+ String filename="";
|
|
|
try {
|
|
|
- // 取出一共有多少个sheet.
|
|
|
- int sheetNo = (int) Math.ceil(list.size() / sheetSize);
|
|
|
- for (int index = 0; index <= sheetNo; index++) {
|
|
|
- createSheet(sheetNo, index);
|
|
|
- // 产生一行
|
|
|
- Row title = sheet.createRow(0);
|
|
|
- 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"));
|
|
|
- Row row = sheet.createRow(1);
|
|
|
- // 产生一行
|
|
|
- int column = 0;
|
|
|
- // 写入各个字段的列头名称
|
|
|
- for (Object[] os : fields) {
|
|
|
- Excel excel = (Excel) os[1];
|
|
|
- this.createCell(excel, row, column++);
|
|
|
+ // 取出一共有多少个sheet.
|
|
|
+ int sheetNo = (int) Math.ceil(list.size() / sheetSize);
|
|
|
+ for (int index = 0; index <= sheetNo; index++) {
|
|
|
+ createSheet(sheetNo, index);
|
|
|
+ // 产生一行
|
|
|
+ Row title = sheet.createRow(0);
|
|
|
+ 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"));
|
|
|
+ Row row = sheet.createRow(1);
|
|
|
+ // 产生一行
|
|
|
+ int column = 0;
|
|
|
+ // 写入各个字段的列头名称
|
|
|
+ for (Object[] os : fields) {
|
|
|
+ Excel excel = (Excel) os[1];
|
|
|
+ this.createCell(excel, row, column++);
|
|
|
+ }
|
|
|
+ filename = encodingFilename(sheetName);
|
|
|
+ out = new FileOutputStream(getAbsoluteFile(filename));
|
|
|
+ fillExcelData(index, row);
|
|
|
+ addStatisticsRow();
|
|
|
}
|
|
|
+ wb.write(out);
|
|
|
|
|
|
- fillExcelData(index, row);
|
|
|
- addStatisticsRow();
|
|
|
- }
|
|
|
- String filename = encodingFilename(sheetName);
|
|
|
- out = new FileOutputStream(getAbsoluteFile(filename));
|
|
|
- wb.write(out);
|
|
|
return new Result().data(filename);
|
|
|
} catch (Exception e) {
|
|
|
- log.error("导出Excel异常{}", e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
throw new BusinessException("导出Excel失败,请联系网站管理员!");
|
|
|
} finally {
|
|
|
if (wb != null) {
|