随笔 - 74,  文章 - 1,  评论 - 1,  阅读 - 45048

 

复制代码
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");
复制代码

 

posted on   不知勿言  阅读(179)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· 单线程的Redis速度为什么快?
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示