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);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM