1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > java 锁定excel单元格格式化 java – Apache POI – Excel写入 – 锁定单个单元格

java 锁定excel单元格格式化 java – Apache POI – Excel写入 – 锁定单个单元格

时间:2024-02-08 07:30:42

相关推荐

java 锁定excel单元格格式化 java – Apache POI – Excel写入 – 锁定单个单元格

尝试以下代码,它可以解决您的问题:

HSSFWorkbook workbook = new XSSFWorkbook();

// Cell styles. Note the setLocked(true) method call.

HSSFCellStyle lockedNumericStyle = workbook.createCellStyle();

lockedNumericStyle.setAlignment(XSSFCellStyle.ALIGN_RIGHT);

lockedNumericStyle.setLocked(true);

HSSFSheet sheet = workbook.createSheet("Protection Test");

HSSFRow row = sheet.createRow(0);

HSSFCell cell = row.createCell(0);

cell.setCellValue(100);

cell.setCellStyle(lockedNumericStyle);

// This line should cause all locked cells to be protected,

// the user should not be able to change the cells

// contents.

sheet.protectSheet("password");

The password makes it possible to remove the protection from the sheet and makes it possible then for the locked cells to be modified.

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。