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
3,586 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
• 63,600 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
• 63,600 points
1,693 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
663 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
• 63,600 points
1,405 views
0 votes
1 answer

What is the better API to Reading Excel sheets in java - JXL or Apache POI

Here are the things where both APIs ...READ MORE

answered Oct 9, 2022 in Others by narikkadan
• 63,600 points
3,437 views
0 votes
1 answer

How to get columns from Excel files using Apache POI?

The only way to see all the ...READ MORE

answered Oct 18, 2022 in Others by narikkadan
• 63,600 points
5,309 views
0 votes
1 answer

Apache POI. Setup data filters in Excel

It's already enabled in Apache POI 3.7. ...READ MORE

answered Oct 21, 2022 in Others by narikkadan
• 63,600 points
2,102 views
0 votes
1 answer

How to insert a new row in the specified cell only, of Excel sheet using c#?

I have this worksheet with a matrix ...READ MORE

answered Nov 24, 2022 in Others by narikkadan
• 63,600 points
2,362 views
0 votes
1 answer

How can I use a command button in excel to set the value of multiple cells in one click?

Try this: Private Scan As Integer Private Sub CommandButton1_Click() ...READ MORE

answered Oct 24, 2022 in Others by narikkadan
• 63,600 points
798 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP