controller导出方法:
@RequestMapping("exportExcel")
public void export(HttpServletResponse response){
List<Goods> userList = goodsService.queryGoodsInfo();
//导出操作
ExcleOut.exportExcel(userList,"商品信息","sheet1",Goods.class,"testDATA.xls",response);
}
工具类:
//导出
public static void exportExcel(List<Goods> list, String title, String sheetName, Class<Goods> pojoClass, String fileName, HttpServletResponse response){
defaultExport(list, pojoClass, fileName, response, new ExportParams(title, sheetName));
}
```java
怎样将数据库中的base64字节码转换成图片导出到excel中呢?
/**
* 将文件编码成的base64字符串解码为文件输入流
*/
public InputStream decode2ExcelFromBase64(String base64Str) throws Exception {
byte[] byteArray = null;
try {
// 解码为byte数组
byteArray = Base64.getDecoder().decode(base64Str);
}catch (Exception e){
throw new Exception("解码失败");
}
// 将byte数组转化为输入流
InputStream inputStream = new ByteArrayInputStream(byteArray);
return inputStream;
}