|
@@ -321,42 +321,44 @@ function initSheet(sheet, cellAuthority, authority) {
|
|
|
sheet.config.authority = newAuthority;
|
|
|
} else {
|
|
|
let lastCell = sheet.celldata[sheet.celldata.length - 1];
|
|
|
- let lastCol = String.fromCharCode(lastCell.c);
|
|
|
- // 第一列禁止编辑但是可以增加
|
|
|
- let canEditCell = sheet.celldata.filter((item) => {
|
|
|
- if (item.r == 0) {
|
|
|
- // 判断是否为空
|
|
|
- if ((item?.v?.v ?? "") === "" && !item?.v?.ct?.s) return true;
|
|
|
- }
|
|
|
- });
|
|
|
- let canEditRangeList = canEditCell.map((item) => {
|
|
|
- let col = String.fromCharCode(item.c + 65);
|
|
|
- return {
|
|
|
- hintText: "",
|
|
|
- sqref: `$${col}$1:$${col}$1`,
|
|
|
- };
|
|
|
- });
|
|
|
- // 设置保护区域,lucksheet不能直接设置不允许编辑的区域
|
|
|
- // 只能禁止整体编辑,设置例外区域
|
|
|
- sheet.config.authority = {
|
|
|
- sheet: 1,
|
|
|
- hintText: "表头只能新增,禁止编辑!",
|
|
|
- // insertColumns: 0,
|
|
|
- allowRangeList: [
|
|
|
- // 第一行以外都能编辑
|
|
|
- {
|
|
|
- hintText: "",
|
|
|
- sqref: `$a$2:$z$99999`,
|
|
|
- },
|
|
|
-
|
|
|
- // 第一列未加载出来的row也允许编辑
|
|
|
- {
|
|
|
+ if (lastCell) {
|
|
|
+ let lastCol = String.fromCharCode(lastCell.c);
|
|
|
+ // 第一列禁止编辑但是可以增加
|
|
|
+ let canEditCell = sheet.celldata.filter((item) => {
|
|
|
+ if (item.r == 0) {
|
|
|
+ // 判断是否为空
|
|
|
+ if ((item?.v?.v ?? "") === "" && !item?.v?.ct?.s) return true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ let canEditRangeList = canEditCell.map((item) => {
|
|
|
+ let col = String.fromCharCode(item.c + 65);
|
|
|
+ return {
|
|
|
hintText: "",
|
|
|
- sqref: `$${lastCol}$1:$${lastCol}$1`,
|
|
|
- },
|
|
|
- ...canEditRangeList
|
|
|
- ],
|
|
|
- };
|
|
|
+ sqref: `$${col}$1:$${col}$1`,
|
|
|
+ };
|
|
|
+ });
|
|
|
+ // 设置保护区域,lucksheet不能直接设置不允许编辑的区域
|
|
|
+ // 只能禁止整体编辑,设置例外区域
|
|
|
+ sheet.config.authority = {
|
|
|
+ sheet: 1,
|
|
|
+ hintText: "表头只能新增,禁止编辑!",
|
|
|
+ // insertColumns: 0,
|
|
|
+ allowRangeList: [
|
|
|
+ // 第一行以外都能编辑
|
|
|
+ {
|
|
|
+ hintText: "",
|
|
|
+ sqref: `$a$2:$z$99999`,
|
|
|
+ },
|
|
|
+
|
|
|
+ // 第一列未加载出来的row也允许编辑
|
|
|
+ {
|
|
|
+ hintText: "",
|
|
|
+ sqref: `$${lastCol}$1:$${lastCol}$1`,
|
|
|
+ },
|
|
|
+ ...canEditRangeList,
|
|
|
+ ],
|
|
|
+ };
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
sheet.config.colhidden = colhidden;
|