相关文章推荐
忧郁的篮球  ·  vue的 v-for ...·  1 周前    · 
飘逸的黄瓜  ·  MotionEvent Class ...·  11 月前    · 
苦恼的登山鞋  ·  蓝牙BLE: GATT Profile ...·  1 年前    · 
年轻有为的烤地瓜  ·  Cannot access ...·  1 年前    · 
刚分手的椰子  ·  Spring ...·  1 年前    · 
高大的机器人  ·  ios - 如何在 React ...·  1 年前    · 
HSSFSheet sheet1 = hssfworkbook.CreateSheet("Sheet1");
sheet1.ProtectSheet("password");//设置密码
HSSFRow row1 = sheet1.CreateRow(0); 
HSSFCell cel1
= row1.CreateCell(0);
HSSFCell cel2
= row1.CreateCell(1);

HSSFCellStyle unlocked
= hssfworkbook.CreateCellStyle();
unlocked.IsLocked
= false;

HSSFCellStyle locked
= hssfworkbook.CreateCellStyle();
locked.IsLocked
= true;

cel1.SetCellValue(
"没被锁定");
cel1.CellStyle
= unlocked;

cel2.SetCellValue(
"被锁定");
cel2.CellStyle
= locked;

正如代码中所看到的,我们通过设置CellStype的ISLocked为True,表示此单元格将被锁定。相当于在Excel中执行了如下操作:

执行结果如下:

没被锁定的列可以任意修改。

锁定的点击编辑就会提示:

需要输入密码才可以(这里密码是我们上面设置的password)

原贴地址: https://www.cnblogs.com/dfzone/p/3805697.html