List<IWorkbook> workbooks = new ArrayList<>();
DeserializationOptions deserializationOptions = new DeserializationOptions();
deserializationOptions.setIgnoreStyle(false);
deserializationOptions.setIgnoreFormula(true);
Workbook workbook =new Workbook(LogConstant.LicenseV5); //授权你们自己填下
workbook.fromJson(附件中的json, deserializationOptions);
doFontSet(workbook);
workbooks.add(workbook);
String fileName = UUID.randomUUID().toString().toLowerCase(Locale.ROOT) + ".pdf";
FileOutputStream outputStream = new FileOutputStream("../" + fileName);
//这里我这边有多个文件合并情况,可不管,就测试单个导出
PrintManager printManager = new PrintManager();
printManager.saveWorkbooksToPDF(outputStream, workbooks);
File file = new File("../" + fileName);
InputStream in = new FileInputStream(file.getPath());
byte[] bytes = new byte[in.available()];
in.read(bytes);
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Disposition", "attachment;filename=" + fileName);
ResponseEntity<byte[]> entity = new ResponseEntity<byte[]>(bytes, headers, HttpStatus.OK);
in.close();
file.delete();
return entity;
|