POI锁定列并设置Cell文本格式

 1         SXSSFWorkbook workbook = new SXSSFWorkbook();
 2         Font font = workbook.createFont();
 3         CellStyle style = workbook.createCellStyle();
 4         style.setLocked(true);// 将整个sheet设置为只读
 5         CellStyle notLockStyle = workbook.createCellStyle();
 6         notLockStyle.setLocked(false);// 放开可以修改的列
 7 
 8         DataFormat dataFormat = workbook.createDataFormat();// 设置可编辑列为文本格式,打开excel编辑不会自动科学计数法
 9         notLockStyle.setDataFormat(dataFormat.getFormat("@"));
10 
11         Sheet sheet = wb.createSheet(title);
12         sheet.protectSheet("123456");// 整个sheet加保护,不然不可编辑模式不生效
13         Row rowValue = sheet.createRow(rowIndex);// rowIndex行标
14         Cell celValue = rowValue.createCell(cellIndex);// cellIndex列标
15         celValue.setCellStyle(notLockStyle);

猜你喜欢

转载自www.cnblogs.com/laom2016/p/11942508.html
今日推荐