NPOI Excel保护
作者:互联网
List<int> array = new List<int>(); int[] i ={1,2,3}; //指定那些列需要修改,当然剩下的列就是你希望只读的列了 array.AddRange(i); for (int i = 0; i < array.Count; i++) { HSSFCellStyle _cellstyle = workbook.CreateCellStyle(); _cellstyle.IsLocked = false;//解除锁定 short m=(short)array[i]; sheet.SetDefaultColumnStyle(m, _cellstyle); }
ICellStyle lockStyle = book.CreateCellStyle(); lockStyle.IsLocked = true; ICellStyle unLockStyle = book.CreateCellStyle(); unLockStyle.IsLocked = false; dataCell = dataRow.GetCell(materialCodeColIndex); if (dataCell == null) { dataCell = dataRow.CreateCell(materialCodeColIndex); dataCell.CellStyle = unLockStyle; dataRow.Cells.Add(dataCell); } else { dataCell = dataRow.CreateCell(materialCodeColIndex); dataCell.CellStyle = unLockStyle; dataRow.Cells.Add(dataCell); } // 把不需要保护的工作表取消保护,然后再保护工作表 dataValidSheet.ProtectSheet("MD5");
标签:unLockStyle,CreateCellStyle,cellstyle,dataCell,Excel,NPOI,保护,dataRow,array 来源: https://www.cnblogs.com/yiyanwei/p/16292563.html