使用apache poi使列只读
我正在使用apache-poi生成excel文件。 我需要将第4列设为只读,其余2列将由用户编辑。
我正在使用XSSFCellStyle
实现这一点,但它不适合我。
整个代码是:
Map styles = new HashMap(); XSSFCellStyle style5 = wb.createCellStyle(); XSSFFont headerFont = wb.createFont(); headerFont.setBold(true); style5.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); style5.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); style5.setFont(headerFont); style5.setLocked(true); // this line does not get executed. styles.put("header", style5);
您必须保护整个工作表并解锁应该可编辑的单元格:
String file = "c:\\poitest.xlsx"; FileOutputStream outputStream = new FileOutputStream(file); Workbook wb = new XSSFWorkbook(); CellStyle unlockedCellStyle = wb.createCellStyle(); unlockedCellStyle.setLocked(false); Sheet sheet = wb.createSheet(); sheet.protectSheet("password"); Row row = sheet.createRow(0); Cell cell = row.createCell(0); cell.setCellValue("TEST"); cell.setCellStyle(unlockedCellStyle); wb.write(outputStream); outputStream.close();
- 如何使用Apache的POI以编程方式从Powerpoint演示文稿中读取图形值?
- 将MS文档打开到JFrame中
- 使用带有openjdk的stix-fonts的例外?
- 如何避免Apache POI中的java.lang.NoSuchMethodError:org.apache.poi.util.IOUtils.copy(Ljava / io / InputStream; Ljava / io / OutputStream;)
- 使用Apache POI创建.xlsx文件时的java.lang.NoClassDefFoundError
- Apache POI性能
- 使用JAVA中的Apache POI和iText从Word(DOC)创建PDF
- 写入XWPFTable单元时,将忽略Java Apache POI换行符
- java.lang.ClassNotFoundException:org.apache.xmlbeans.XmlException