Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Apache POI: protect only some cells excel sheet

 
E torres
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to protect an excel sheet using Apache POI so that no Cell in the sheet can be written to but the cells in column C that must be editable. The problem is that my code is resulting in NONE of the excel being editable. This is the code I am using:



I debugged this and the issue seems to be that this line is returning null:
Cell c = r.getCell(editableColumn);
The columm exist, but no cell in it has value. Actually, this is the reason why this column needs to be editable. This column will be filled later, and I have to make sure that only this column will be edited (and therefore I am trying to protect the rest of sheet). How could I set this empty column to NOT locked?
 
Winston Gutkowski
Bartender
Pie
Posts: 10417
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
E torres wrote:I am trying to protect an excel sheet using Apache POI so that no Cell in the sheet can be written to but the cells in column C that must be editable.

E torres,

I've moved your topic to a more suitable forum, as POI is quite specialized. You should get more answers there.

Winston
 
E torres
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since I am already iterating I am considering this:


Still it feels like a ugly hack. For starters not being able to work directly with columns in an excel document feels weird (I am talking about the part in which I got to iterate over all the rows and set the protection options cell by cell), and now on the top of that if the document has a cell empty cannot work with it.
I am not complicating things too much? Does not exist a more intuitive/clear way of stating a column must be protected/unprotected?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic