|
@@ -18,24 +18,11 @@ import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
import java.util.UUID;
|
|
|
import java.util.stream.Collectors;
|
|
|
-import org.apache.poi.ss.usermodel.BorderStyle;
|
|
|
-import org.apache.poi.ss.usermodel.Cell;
|
|
|
-import org.apache.poi.ss.usermodel.CellStyle;
|
|
|
-import org.apache.poi.ss.usermodel.CellType;
|
|
|
-import org.apache.poi.ss.usermodel.DataValidation;
|
|
|
-import org.apache.poi.ss.usermodel.DataValidationConstraint;
|
|
|
-import org.apache.poi.ss.usermodel.DataValidationHelper;
|
|
|
-import org.apache.poi.ss.usermodel.DateUtil;
|
|
|
-import org.apache.poi.ss.usermodel.FillPatternType;
|
|
|
-import org.apache.poi.ss.usermodel.Font;
|
|
|
-import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
|
|
-import org.apache.poi.ss.usermodel.IndexedColors;
|
|
|
-import org.apache.poi.ss.usermodel.Row;
|
|
|
-import org.apache.poi.ss.usermodel.Sheet;
|
|
|
-import org.apache.poi.ss.usermodel.VerticalAlignment;
|
|
|
-import org.apache.poi.ss.usermodel.Workbook;
|
|
|
-import org.apache.poi.ss.usermodel.WorkbookFactory;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.ss.util.CellRangeAddressList;
|
|
|
+import org.apache.poi.ss.util.CellReference;
|
|
|
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFDataValidation;
|
|
|
import org.slf4j.Logger;
|
|
@@ -409,6 +396,45 @@ public class ExcelUtil<T>
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 总账统计导入到excel表单
|
|
|
+ *
|
|
|
+ * @param list 导出数据集合
|
|
|
+ * @param sheetName 工作表的名称
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ public AjaxResult statisticsExportExcel(List<T> list, String sheetName)
|
|
|
+ {
|
|
|
+ this.init(list, sheetName, Type.EXPORT);
|
|
|
+ return statisticsExportExcel();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 单票分析导入到excel表单
|
|
|
+ *
|
|
|
+ * @param list 导出数据集合
|
|
|
+ * @param sheetName 工作表的名称
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ public AjaxResult singleAnalysisExportExcel(List<T> list, Map<String, Object> map, String sheetName)
|
|
|
+ {
|
|
|
+ this.init(list, sheetName, Type.EXPORT);
|
|
|
+ return singleAnalysisExportExcel(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 单票分析费用导入到excel表单
|
|
|
+ *
|
|
|
+ * @param list 导出数据集合
|
|
|
+ * @param sheetName 工作表的名称
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ public AjaxResult singleAnalysisFeesExportExcel(List<T> list, String sheetName)
|
|
|
+ {
|
|
|
+ this.init(list, sheetName, Type.EXPORT);
|
|
|
+ return singleAnalysisFeesExportExcel();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 对list数据源将其里面的数据导入到excel表单
|
|
|
*
|
|
|
* @param sheetName 工作表的名称
|
|
@@ -451,14 +477,271 @@ public class ExcelUtil<T>
|
|
|
addStatisticsRow();
|
|
|
}
|
|
|
}
|
|
|
+ String filename = encodingFilename(sheetName);
|
|
|
+ out = new FileOutputStream(getAbsoluteFile(filename));
|
|
|
+ wb.write(out);
|
|
|
+ return AjaxResult.success(filename);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ log.error("导出Excel异常{}", e.getMessage());
|
|
|
+ throw new CustomException("导出Excel失败,请联系网站管理员!");
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ if (wb != null)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ wb.close();
|
|
|
+ }
|
|
|
+ catch (IOException e1)
|
|
|
+ {
|
|
|
+ e1.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (out != null)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ out.close();
|
|
|
+ }
|
|
|
+ catch (IOException e1)
|
|
|
+ {
|
|
|
+ e1.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 总账统计导入到excel表单
|
|
|
+ *
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ public AjaxResult statisticsExportExcel()
|
|
|
+ {
|
|
|
+ OutputStream out = null;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ // 取出一共有多少个sheet.
|
|
|
+ double sheetNo = Math.ceil(list.size() / sheetSize);
|
|
|
+ for (int index = 0; index <= sheetNo; index++)
|
|
|
+ {
|
|
|
+ createSheet(sheetNo, index);
|
|
|
+
|
|
|
+ // 产生一行
|
|
|
+ Row row = sheet.createRow(0);
|
|
|
+ int column = 0;
|
|
|
+ // 写入各个字段的列头名称
|
|
|
+ for (Object[] os : fields)
|
|
|
+ {
|
|
|
+ Excel excel = (Excel) os[1];
|
|
|
+ this.createCell(excel, row, column++);
|
|
|
+ }
|
|
|
+ if (Type.EXPORT.equals(type))
|
|
|
+ {
|
|
|
+ fillExcelData(index, row);
|
|
|
+ addStatisticsRow();
|
|
|
+ }
|
|
|
+ }
|
|
|
Row row = sheet.createRow(list.size() + 1);
|
|
|
row.createCell(1).setCellValue("全部累计");
|
|
|
row.createCell(3).setCellValue("仓储费");
|
|
|
row.createCell(4).setCellValue("出入库费用");
|
|
|
row.createCell(5).setCellValue("合计人民币");
|
|
|
+ String filename = encodingFilename(sheetName);
|
|
|
+ out = new FileOutputStream(getAbsoluteFile(filename));
|
|
|
+ wb.write(out);
|
|
|
+ return AjaxResult.success(filename);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ log.error("导出Excel异常{}", e.getMessage());
|
|
|
+ throw new CustomException("导出Excel失败,请联系网站管理员!");
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ if (wb != null)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ wb.close();
|
|
|
+ }
|
|
|
+ catch (IOException e1)
|
|
|
+ {
|
|
|
+ e1.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (out != null)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ out.close();
|
|
|
+ }
|
|
|
+ catch (IOException e1)
|
|
|
+ {
|
|
|
+ e1.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 单票分析导入到excel表单
|
|
|
+ *
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ public AjaxResult singleAnalysisExportExcel(Map<String, Object> map)
|
|
|
+ {
|
|
|
+ OutputStream out = null;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ // 取出一共有多少个sheet.
|
|
|
+ double sheetNo = Math.ceil(list.size() / sheetSize);
|
|
|
+ for (int index = 0; index <= sheetNo; index++)
|
|
|
+ {
|
|
|
+ createSheet(sheetNo, index);
|
|
|
+ // 产生一行
|
|
|
+ Row row = sheet.createRow(0);
|
|
|
+ int column = 0;
|
|
|
+ // 写入各个字段的列头名称
|
|
|
+ for (Object[] os : fields)
|
|
|
+ {
|
|
|
+ Excel excel = (Excel) os[1];
|
|
|
+ this.createCell(excel, row, column++);
|
|
|
+ }
|
|
|
+ if (Type.EXPORT.equals(type))
|
|
|
+ {
|
|
|
+ fillExcelData(index, row);
|
|
|
+ addStatisticsRow();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Row row = sheet.createRow(list.size() + 1);
|
|
|
+ Cell cell;// 单元格
|
|
|
+ String colString;//长度转成ABC后的列
|
|
|
+ String sumString;//求和公式
|
|
|
+ Integer[] line = {4, 5, 7, 8, 9, 10};
|
|
|
+ cell = row.createCell(0);// 创建单元格
|
|
|
+ cell.setCellValue("合计:");
|
|
|
+ int totalRows = sheet.getPhysicalNumberOfRows();
|
|
|
+ for (Integer l : line) {
|
|
|
+ cell = row.createCell(l);// 创建单元格
|
|
|
+ cell.setCellStyle(styles.get("total"));// 设置单元格样式
|
|
|
+ colString = CellReference.convertNumToColString(l); //长度转成ABC列
|
|
|
+ //求和公式 求i9至i12单元格的总和
|
|
|
+ if (l == 5 || l == 8) {
|
|
|
+ sumString = "SUM(" + colString + "2:" + colString + (totalRows-1) + ") / 1000";
|
|
|
+ } else {
|
|
|
+ sumString = "SUM(" + colString + "2:" + colString + (totalRows-1) + ")";
|
|
|
+ }
|
|
|
+ cell.setCellFormula(sumString);// 把公式塞入合计列
|
|
|
+ }
|
|
|
+ wb.setForceFormulaRecalculation(true);
|
|
|
+ String mblno = "", corpName = "", goodsName = "";
|
|
|
+ if (map.containsKey("mblno")) {
|
|
|
+ mblno = map.get("mblno").toString();
|
|
|
+ }
|
|
|
+ if (map.containsKey("corpName")) {
|
|
|
+ corpName = map.get("corpName").toString();
|
|
|
+ }
|
|
|
+ if (map.containsKey("goodsName")) {
|
|
|
+ goodsName = map.get("goodsName").toString();
|
|
|
+ }
|
|
|
+ Row primaryRow = sheet.createRow(list.size() + 2);
|
|
|
+ primaryRow.createCell(1).setCellValue("货主:");
|
|
|
+ cell = primaryRow.createCell(2);// 创建单元格
|
|
|
+ cell.setCellValue(corpName);
|
|
|
+ primaryRow.createCell(3).setCellValue("提单号:");
|
|
|
+ cell = primaryRow.createCell(4);// 创建单元格
|
|
|
+ cell.setCellValue(mblno);
|
|
|
+ primaryRow.createCell(5).setCellValue("品名:");
|
|
|
+ cell = primaryRow.createCell(6);// 创建单元格
|
|
|
+ cell.setCellValue(goodsName);
|
|
|
+ String filename = encodingFilename(sheetName);
|
|
|
+ out = new FileOutputStream(getAbsoluteFile(filename));
|
|
|
+ wb.write(out);
|
|
|
+ return AjaxResult.success(filename);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ log.error("导出Excel异常{}", e.getMessage());
|
|
|
+ throw new CustomException("导出Excel失败,请联系网站管理员!");
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ if (wb != null)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ wb.close();
|
|
|
+ }
|
|
|
+ catch (IOException e1)
|
|
|
+ {
|
|
|
+ e1.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (out != null)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ out.close();
|
|
|
+ }
|
|
|
+ catch (IOException e1)
|
|
|
+ {
|
|
|
+ e1.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 单票分析费用导入到excel表单
|
|
|
+ *
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ public AjaxResult singleAnalysisFeesExportExcel()
|
|
|
+ {
|
|
|
+ OutputStream out = null;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ // 取出一共有多少个sheet.
|
|
|
+ double sheetNo = Math.ceil(list.size() / sheetSize);
|
|
|
+ for (int index = 0; index <= sheetNo; index++)
|
|
|
+ {
|
|
|
+ createSheet(sheetNo, index);
|
|
|
+ // 产生一行
|
|
|
+ Row row = sheet.createRow(0);
|
|
|
+ int column = 0;
|
|
|
+ // 写入各个字段的列头名称
|
|
|
+ for (Object[] os : fields)
|
|
|
+ {
|
|
|
+ Excel excel = (Excel) os[1];
|
|
|
+ this.createCell(excel, row, column++);
|
|
|
+ }
|
|
|
+ if (Type.EXPORT.equals(type))
|
|
|
+ {
|
|
|
+ fillExcelData(index, row);
|
|
|
+ addStatisticsRow();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Row row = sheet.createRow(list.size() + 1);
|
|
|
+ Cell cell;// 单元格
|
|
|
+ String colString;//长度转成ABC后的列
|
|
|
+ String sumString;//求和公式
|
|
|
+ Integer[] line = {4, 6};
|
|
|
+ cell = row.createCell(0);// 创建单元格
|
|
|
+ cell.setCellValue("合计:");
|
|
|
+ int totalRows = sheet.getPhysicalNumberOfRows();
|
|
|
+ for (Integer l : line) {
|
|
|
+ cell = row.createCell(l);// 创建单元格
|
|
|
+ cell.setCellStyle(styles.get("total"));// 设置单元格样式
|
|
|
+ colString = CellReference.convertNumToColString(l); //长度转成ABC列
|
|
|
+ //求和公式 求i9至i12单元格的总和
|
|
|
+ sumString = "SUM(" + colString + "2:" + colString + (totalRows-1) + ")";
|
|
|
+ cell.setCellFormula(sumString);// 把公式塞入合计列
|
|
|
+ }
|
|
|
+ wb.setForceFormulaRecalculation(true);
|
|
|
String filename = encodingFilename(sheetName);
|
|
|
out = new FileOutputStream(getAbsoluteFile(filename));
|
|
|
wb.write(out);
|
|
@@ -689,9 +972,13 @@ public class ExcelUtil<T>
|
|
|
{
|
|
|
cell.setCellValue(convertDictByExp(Convert.toStr(value), dictType, separator));
|
|
|
}
|
|
|
- else if (value instanceof BigDecimal && -1 != attr.scale())
|
|
|
+ else if (value instanceof BigDecimal) {
|
|
|
+ double doubleVal = ((BigDecimal) value).doubleValue();
|
|
|
+ cell.setCellValue(doubleVal);
|
|
|
+ }
|
|
|
+ else if (value instanceof Integer && -1 != attr.sort())
|
|
|
{
|
|
|
- cell.setCellValue((((BigDecimal) value).setScale(attr.scale(), attr.roundingMode())).toString());
|
|
|
+ cell.setCellValue((Integer) value);
|
|
|
}
|
|
|
else
|
|
|
{
|