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