I'm trying to lock a column/cell in an excel sheet that is created from Jasper Studio, because our client doesn't want the user to be able to update the formula. I haven't been able to find much on this.
I added the locked property that I found in the config reference (http://jasperreports.sourceforge.net/config.reference.html#net.sf.jasperreports.export.xls.cell.locked), although it does not prevent the cells in the column from being edited on the exported sheet.
<reportElement stretchType="RelativeToTallestObject" x="100" y="0" width="100" height="30" uuid="c356dd4b-5227-4917-b4ff-d2d4c72bafd0">
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
With the whole sheet protected, I tried adding the locked property set to false for the fields that need to be updatable. But I still couldn't update them since the entire sheet was protected.
Any ideas on how to protect some cells or columns and not others?
1 Answer:
Thanks @morlandin. You have started me thinking at the right direction.
It seems that once we have set password at the sheet level, all the cells are by default locked (on second thought, this seems obvious). So, if we want to unlock a cell we have to mention explicitly
<property name="net.sf.jasperreports.export.xls.cell.locked" value="false"/>
So, the below code will produce an excel sheet where "Static Text" cell will be locked and "Static Text22" cell will be unlocked. Hope this example will help others and they will not have to go round and round at it like me.
You must set the password property at report level and the locked property at element level. I've tested something like this and it works: