@GetMapping("/test")
@ResponseBody
public void getWorkbook(HttpServletResponse response) throws IOException, GeneralSecurityException {
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;filename*=UTF-8''" + URLEncoder.encode("文件名.xlsx","UTF-8"));
response.addHeader("Pargam", "no-cache");
response.addHeader("Cache-Control", "no-cache");
Workbook workbook = new XSSFWorkbook();
OutputStream os = response.getOutputStream();
//加密
EncryptionInfo info = new EncryptionInfo(EncryptionMode.standard);
Encryptor enc = info.getEncryptor();
enc.confirmPassword("123456");
POIFSFileSystem poifsFileSystem = new POIFSFileSystem();
OutputStream encryptOutPutStream = enc.getDataStream(poifsFileSystem);
workbook.write(encryptOutPutStream);
encryptOutPutStream.close();
poifsFileSystem.writeFilesystem(os);
os.close();
}
08-15
670
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
11-23
847
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-17
3727
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)