0

I have to protect only one row (example the rowNum 0) in a xssf Excel generated in this way (using library NPOI version 2.2.1.0)

ISheet sheet_for_dropdown_list = Workbook.CreateSheet("DropDownList");

Actually the protect command is used only to protect entirely sheet by means of a password

sheet_for_dropdown_list.ProtectSheet("admin");

Then I tryed to unlock the row1 setting the property isLocked false in a style

ICellStyle extCellStyle = Workbook.CreateCellStyle();

unprotectCellStyle.IsLocked = false

IRow1 row1= sheet_for_dropdown_list.GetRow(1);

and unprotect all cell

foreach (ICell cell in row1)
        cell.CellStyle = unprotectCellStyle;

This operation could be done for all the row > 0

This solution partially works, because is possible to modify the cell contents but isn't possible to modify the height of the column. So in the free cell isn't possible to insert contents with height greater than the actual height column.

1 Answers1

0

I think you are looking to set the height of header row. You can either assign the height or wrap the text or both.

To assign the height see this link. To Wrap a text use below syntax

XSSFCellStyle headerStyle = (XSSFCellStyle)workbook.CreateCellStyle();
headerStyle.WrapText = true;
kumar chandraketu
  • 2,232
  • 2
  • 20
  • 25
  • Ok . Your solution gave me an important tip. My problem is that using the cast to ISheet i can accceed only to function exported by interface ISheet interface, Instead if the cast is a (XSSFSheet) I can accedd to all fiunction and I can set the height of the row aslo if the sheet is protect. So this works for me (XSSFSheet) mySheet = (XSSFSheet)WorkbooK.CreateSheet("nameSheet"); – Massimo Cervi Dec 05 '17 at 10:30
  • mySheet.ProtectSheet("admin"); mySheet.unlockFormatColumns(); – Massimo Cervi Dec 05 '17 at 10:45