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
• 12,240 points
24 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
• 20,880 points

Related Questions In Others

0 votes
0 answers
0 votes
2 answers

How to get the URL of the current tab in Google Chrome?

Its so simple.... If you want to ...READ MORE

answered Aug 12, 2020 in Others by Steve
• 200 points
968 views
0 votes
1 answer

How to change the background color of AppBar in Flutter?

Hi@akhtar, You can add backgroundColor keyword in your ...READ MORE

answered Aug 12, 2020 in Others by MD
• 95,360 points
1,357 views
0 votes
1 answer

How to retrieve the value of a text field in Flutter App?

Hi@akhtar, In your TextField, you can call one ...READ MORE

answered Sep 3, 2020 in Others by MD
• 95,360 points
882 views
0 votes
1 answer
0 votes
1 answer

Can anyone show how to modify an existing excel sheet using Apache POI?

Hello Prakash, to modify an existing excel ...READ MORE

answered Jul 17, 2019 in Selenium by Anvi
• 14,170 points
2,682 views
0 votes
1 answer

How can I read numeric data from an Excel sheet using Selenium Webdriver?

Hey Jignesh, for reading numeric data from ...READ MORE

answered Jul 17, 2019 in Selenium by Abha
• 28,120 points
6,347 views
0 votes
1 answer

How to print an Excel Sheet using VBA with Nitro PDF Creator in Excel 2016

you can use the built-in excel facilities ...READ MORE

answered Sep 24 in Others by narikkadan
• 20,880 points
18 views
0 votes
1 answer

Unable to import data in excel from another website using VB code

Replace : Set ieTable = ieDoc.all.Item("report-table") With: Set ieTable = ...READ MORE

answered Sep 21 in Others by narikkadan
• 20,880 points
17 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