public static void createPointExcel(HttpServletRequest request, List<PointUtil> finalPointList) throws Exception {
XSSFWorkbook wb = null;
String excel = pathModel + "/point.xlsx";
File fi = new File(excel);
// 读取excel模板
wb = new XSSFWorkbook(new FileInputStream(fi));
// 读取了模板内所有sheet内容
XSSFSheet sheet = wb.getSheetAt(0);
sheet.protectSheet(“password”); sheet.lockSelectLockedCells(true); sheet.lockSelectUnlockedCells(true); CellStyle lockedStyle = wb.createCellStyle(); lockedStyle.setLocked(true);
// 在相应的单元格进行赋值
int rowIndex = 1;
// int j = 1;
for (PointUtil pointUtil : finalPointList) {
XSSFRow row = sheet.getRow(rowIndex);
if (null == row) {
row = sheet.createRow(rowIndex);
}
for (int i = 1; i < 6; i++) {
XSSFCell cell = row.getCell(i);
if (null == cell) {
cell = row.createCell(i);
}
switch (i) {
case 1:
//不可编辑
cell.setCellStyle(lockedStyle);
cell.setCellValue(pointUtil.getEQUIPMENT_CODE());
break;
}
}
rowIndex++;
}
// 输出Excel文件
FileOutputStream output = new FileOutputStream(path + "/point" + System.nanoTime() + ".xlsx");
wb.write(output);
output.flush();
}