HSSFDataValidation displayNameValidation = new HSSFDataValidation(displayNameCellRange,displayNameConstraint) ĭisplayNameValidation.createErrorBox("Not Applicable","Cannot change the value") ĭtSuppressDropDownArrow(true) ĭisplayNameCell.getSheet().addValidationData(displayNameValidation) įileOutputStream fileOut1 = new FileOutputStream("D:\\book. String displayNameList = new String //ADDING SAME VALUE INTO A STRING ARRAY AS THE RESTRICTED VALUEĭVConstraint displayNameConstraint = DVConstraint.createExplicitListConstraint(displayNameList) ĬellRangeAddressList displayNameCellRange = new CellRangeAddressList(displayNameCell.getRowIndex(),displayNameCell.getRowIndex(),displayNameCell.getColumnIndex(),displayNameCell.getColumnIndex()) HSSFSheet sheet1 = workBook.createSheet() ĬtCellValue("text: The new line which should be locked") // SETTING INITIAL VALUE HSSFWorkbook workBook = new HSSFWorkbook () For a better protection, protect the sheet with a password. Note: If you only want to recommend users to open the Excel file as read-only, without. Users can still save changes by creating a new copy of the workbook. In the Password to modify box, enter a password and click OK. Sheet Explanation: This sheet enables the user to figure out what length of bolt to use given the selected arrangement of connector pad thicknesses.
HOW TO MAKE EXCEL SHEET READ ONLY HOW TO
This sets an initial value in a cell, then it uses a data constraint to ensure that fixed value cannot be modified by the user in Excel. This example shows you how to make your workbook read-only. I currently have an excel sheet that I've made for my team at work, but I'd like to make some improvements to it, and don't know the best way to go about it.
HOW TO MAKE EXCEL SHEET READ ONLY CODE
Here is some tested code that works in making the specific cell readonly. OutputStream out = new FileOutputStream("sample.xls") tCellStyle(lockedCellStyle) Ĭell unlockedCell = sheet.createRow(1).createCell(0) * password required for locks to become effective */ĬellStyle lockedCellStyle = workbook.createCellStyle() ĬellStyle unlockedCellStyle = workbook.createCellStyle() Ĭell lockedCell = sheet.createRow(0).createCell(0) HSSFSheet sheet = workbook.createSheet("sheet1") I just want to make it so that I can't accidentally edit the sheet, and I don't want to have to deal with a password-not even a blank one. HSSFWorkbook workbook = new HSSFWorkbook() I want to make one of the worksheets in an Excel 2010 workbook read-only, but I don't want to use a password. A detailed description can be found here:īasically you have to assign your cells a custom CellStyle with tLocked(true) Edited