easyExcel类 | 文档保护措施

easyexcel导出的文档保护方式有两种。

  1. 文档加密码(没有密码数据不可见)
ExcelWriter writer = EasyExcel.write().file(response.getOutputStream())
                     .autoCloseStream(Boolean.FALSE)
                     .password('666666')
                     .build();
  1. 单元格加密(没有密码单元格无法编辑)
//构建 ExcelWriter
ExcelWriter writer = EasyExcel.write().file(response.getOutputStream())
                     .autoCloseStream(Boolean.FALSE)
                     .build();

...

Workbook workbook = writer.writeContext().writeWorkbookHolder().getWorkbook();  
//获取sheet页数量
int numberOfSheets = workbook.getNumberOfSheets();
//遍历加密
for (int i = 0; i < numberOfSheets; i++) {
    Sheet sheetAt = workbook.getSheetAt(i);
    sheetAt.protectSheet(‘666666’);
}

你可能感兴趣的:(easyExcel类 | 文档保护措施)