Excel源代码,导入导出各种工具类
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
</dependency>
代码实例:
String path = "";
byte[] bytes;
vo.setCurrentPage(0);
vo.setPageSize(Integer.MAX_VALUE);
List<ShOutOrderDetail> list = stockOrderController.exportShOutOrderDetail(vo);
Map<Integer, Object[]> empinfo = new TreeMap<>();
int index = 1;
empinfo.put(index++,
new Object[]{"销售单号", "销售时间", "会员", "商品总额", "来源", "商品名称/属性", "数量", "单价"});
for (ShOutOrderDetail item : list) {
empinfo.put(index++, new Object[]{
item.getOutOrderNo(),
DateUtil.SDF.format(item.getOutTime()),
item.getNickName()+"/"+item.getMobile(),
String.valueOf(item.getStockPrice().multiply(new BigDecimal(item.getStockAmount()))),
"01".equals(item.getSalesSource()) ? "线上订单" : "线下订单",
item.getGoodsNameAttrs(),
String.valueOf(item.getStockAmount()),
String.valueOf(item.getStockPrice())
});
}
try {
bytes = ExcelUtils.simpleExcel(empinfo, "销售单信息");
MultipartFile multipartFile = new MultipartFile();
multipartFile.setData(bytes);
multipartFile.setOriginalFilename("ShOutOrderDetailExport.xls");
path = fastDFSClientController.uploadFile(multipartFile);
} catch (Exception e) {
logger.error("出库单信息导出失败 : {}", e.getMessage(), e);
return "fail";
}
logger.info("出库单信息导出结束,path:{}", path);
return path;
- 1
- 2
- 3
- 4
- 5
- 6
前往页