I tried lockFormatColumns() and enableLocking() methods on the XSSFSheet object, after setting the cellstyle as the code that I had posted last, but I still I find that unlocked columns cannot be resized.
-Mamatha -----Original Message----- From: Mark Beardsley [mailto:markbrd...@tiscali.co.uk] Sent: Wednesday, February 09, 2011 11:15 PM To: user@poi.apache.org Subject: RE: Apache POI -Protected sheet disables the Row/Column resize Using HSSF to build binary files, you will not be able to access this functionality at all as there are no methods defined that support it. The reason may be - and I am guessing here - that HSSF targets a fairly early iteration of the binary file format and it could be that the option to lock column widths was simply not available at the time. You have two options here, one using macros and one - possibly - using a template file. There is a Workbook_Change event, triggered whenever the user tries to make a change to the workbook. You can write VBA code here to set the widths of the columns and effectively prevent the user from changing them. The drawback with this is that as the workbook contains macros, the user will be notified when they open the file and offered the chance to disable the code' that is unless you can sign macros in binary workbooks and this, I do not know. Your second option is to try wuth a template file that has all cells in certain columns unloced and all cells in other columns locked. When you populate the workbook using POI, it should result in a workbook where the user is unable to modify the column widths but I am not yet convinced this will work and have not been able to test it. XSSF on the other hand might - and that is might - allow you to do this. As far as I have been able to determine from chatting to an experienced Excel user, you protect the sheet and deselect the format columns option on that dialog. Now, any column in which the cells are locked will have a fixed width and the user will not be able to adjust it. I cannot play with any POI code at the moment but I think that what you need to do is create a CellStyle which is locked, apply this to all of the cells in the column whose width cannot be adjusted, then call the lockFormatColumns() and enableLocking() methods on the XSSFSheet object. As far as I can remember, you have to do it in that order - and, onbiously, after you have populated the sheet and set column widths. Sorry to say that I will not have the chance to play with any code before the weekend so if you have the opportunity to experiment can you please let us know the outcome? Yours Mark B PS You will also need to create unlocked CellStyle objects to apply to cells in those columns which you do want the user to be able to adjust. -- View this message in context: http://apache-poi.1045710.n5.nabble.com/Apache-POI-Protected-sheet-disables-the-Row-Column-resize-tp3369042p3377984.html Sent from the POI - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@poi.apache.org For additional commands, e-mail: user-h...@poi.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@poi.apache.org For additional commands, e-mail: user-h...@poi.apache.org