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