Excel源代码,导入导出各种工具类
org.apache.poi
poi
org.apache.poi
poi-scratchpad
代码实例:
String path = "";
byte[] bytes;
vo.setCurrentPage(0);
vo.setPageSize(Integer.MAX_VALUE);
List list = stockOrderController.exportShOutOrderDetail(vo);
Map 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