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 in Others by Kithuzzz
• 20,660 points
298 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 by narikkadan
• 37,660 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 in Others by narikkadan
• 37,660 points
81 views
0 votes
0 answers
0 votes
1 answer
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 in Others by narikkadan
• 37,660 points
201 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 in Others by narikkadan
• 37,660 points
354 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 in Others by narikkadan
• 37,660 points
85 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 in Others by narikkadan
• 37,660 points
27 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 in Others by narikkadan
• 37,660 points
62 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