Make column read-only using apache poi

后端 未结 3 1653
清歌不尽
清歌不尽 2020-12-03 12:28

I am using apache-poi for generating the excel file. I need to make the 4th column read-only and the remaining 2 columns will be editable by the user.

I am using

3条回答
  •  旧时难觅i
    2020-12-03 12:52

    CellRangeAddressList addressList = new CellRangeAddressList(firstRow, lastRow, firstCol, lastCol);
            DVConstraint dvConstraint = DVConstraint.createExplicitListConstraint(new String[] { "ReadOnlyCell" });
            HSSFDataValidation dataValidation = new HSSFDataValidation(addressList, dvConstraint);
        dataValidation.setSuppressDropDownArrow(true);
    
        dataValidation.setEmptyCellAllowed(false);
        dataValidation.createErrorBox("Error", "Cell can not be editable");
        spreadsheet.addValidationData(dataValidation);
    

提交回复
热议问题