Your welcome.

It is possible to have some cells locked and others that the user can
modify. To achieve this you need to create different HSSFCellStyle objects
to apply to the cells; one will be locked the other not. Then when you
protect the sheet only those cells to which the locked style was added will
be un-editable.

Yours

Mark B


Nagineni wrote:
> 
> Hi Mark,
> 
> Thanks for the spontaneous response.As I'm not aware of locking feature ,I
> used data validation approach
> Thanks again for letting me know about this feature.
> 
> Yes,this works for me.
> 
> 
> Regards,
> Naga.
> 
> 
> 
> 
> MSB wrote:
>> 
>> I think that you may be looking at the worng feature of the cell.
>> 
>> Are you saying that you want to enter a value into a cell when you are
>> preparing the sheet and to prevent the user from subsequently making any
>> changes to that value?
>> 
>> If this is the case then you need to create an HSSFCellStyle object that
>> has it's locked attribute set. This style needs to be applied to the cell
>> that you want to protect and the worksheet itself then needs to be
>> protected.
>> 
>> This is the sort of code you will need to use;
>> 
>> 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.
>> 
>> Data Vaidations are a different feature; they are used to ensure that the
>> value a user enters into a cell is within a specified range of values.
>> 
>> Hope that helps
>> 
>> Yours
>> 
>> Mark B
>> 
>> 
>> 
>> Nagineni wrote:
>>> 
>>> 
>>> Hi,
>>> 
>>> Can any one help me to make excel cell as read only.After creating
>>> workbook using POI,want make sure some of the columns in a sheet are
>>> read only.
>>> 
>>> I'm using following code to achieve this but it not showing the cell
>>> value.But when I try to edit the cell it is prompting error.
>>> 
>>> 
>>> CellRangeAddressList addressList = new CellRangeAddressList(3, 3, i, i);
>>> 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");
>>> sheet.addValidationData(dataValidation);
>>> 
>>> Please let me know if any other solutions for this.
>>> 
>>> Regards,
>>> Naga.
>>> 
>>> 
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/How-to-make-readonly-cell-tp24367500p24368782.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to