How to lock data in excel sheet using POI leaving cells without any data the rest of the sheet unlocked

0 votes

In order to prevent alteration of the data previously entered into an Excel worksheet but allow editing and additional data entry in the remaining empty spaces, I'm attempting to lock the data within the worksheet. I tried setting the cell style throughout the entire sheet using the code provided below, but it is only the pertinent code, therefore it doesn't work, which is consistent with the previously posed question. 

Lock single column in Excel using Apache POI

XSSFCellStyle lockCell = getFileWriter().getWorkbook().createCellStyle();
lockCell.setLocked(true);
for(Row row : sheet){
    for(Cell mycell : row){
        mycell.setCellStyle(lockCell);
    }
}

The exact opposite: I've tried locking the entire sheet and setting the cell styles for the relevant rows to unlock, but the cells without any data don't unlock, thus it doesn't work for me. In any event, how much space is required for the unknowable amount of data to be added, hence how far and wide should one unlock the cells?

Sep 23, 2022 in Others by Kithuzzz
• 38,000 points
4,509 views

1 answer to this question.

0 votes
If the cells in a row have never been explicitly generated previously, the iterator for that row won't return any cells. A cell must be expressly set to an unlocked style in order to unlock it. To my understanding, it is not feasible to alter the default. The only option, in my opinion, is to make cells for each row up to a given column index.
answered Sep 24, 2022 by narikkadan
• 86,360 points

Related Questions In Others

0 votes
1 answer

How to hide and unhide the columns of an excel sheet using asp.net

Use this. For Row: worksheet_sub.Row(i).Height = 0; For Column: ...READ MORE

answered Oct 29, 2022 in Others by narikkadan
• 86,360 points
2,305 views
0 votes
0 answers

Data Driven Framework -- how to read and write in excel sheet using Selenium WebDriver with java

I'm using this code to read something, ...READ MORE

Oct 31, 2022 in Others by Kithuzzz
• 38,000 points
1,044 views
0 votes
1 answer

How can I store the data of an open excel workbook in a collection using BluePrism?

To do what you want is like ...READ MORE

answered Nov 24, 2022 in Others by narikkadan
• 86,360 points
1,995 views