java的poi导出excel怎么设置单元格不可编辑(试过.setLocked(true)没有用)
我是以为新人,最近在做excel的导入导出,
问题:java的poi导出excel怎么设置单元格不可编辑
少说话,直接上代码。//单元格锁定的样式
XSSFCellStyle lockstyle = (XSSFCellStyle) wb.createCellStyle();
lockstyle.setLocked(true);
lockstyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
lockstyle.setFillForegroundColor(IndexedColors.RED.getIndex());
//单元格不锁定的样式
XSSFCellStyle unlockstyle = (XSSFCellStyle) wb.createCellStyle();
unlockstyle.setLocked(false);
ExcelUtil ex = new ExcelUtil();
for (int i = 0; i < row.length; i++) {
row[i] = sheet.createRow(i);
for (int j = 0; j < cell.length; j++) {
cell[j] = row[i].createCell(j);
cell[j].setCellValue((value[i][j]).toString());
if(i==0&&j==0){
cell[j].setCellStyle(lockstyle);
}else{
cell[j].setCellStyle(unlockstyle);
}
}
}