七月上旬更新速递丨 聚焦集成、安全与AI深度进化

更新亮点: 本次重点强化系统集成能力与AI认知升级,新增4大核心模块9项资源,优化4项资源,点击标题了解(持续互动赢麦豆,解锁高阶技能)

重点推荐:《场景化数据分析实战》课程操作手册

配套六月王炸课程的全套落地指南,手把手教你复现实战场景!

二、实战技巧分享

高效处理资源集成难题》→ 从基础出发,深入探究集成的秘密

三、开发技能突破

第三方系统调用Smartbi接口》→讲解系统集成时的jar包获取,以及集成时代码调用的基本流程。

集成接口介绍》→梳理Smartbi目前提供的接口,以及不同接口的调用流程。

AI每日一学

DeepSeek-R1-0528模型升级:推理与生态的双重升级》→ 解析模型性能提升40%的关键技术 (技术前沿)

简单总结一下机器学习中的几种常见的学习方式与区别》→ 监督/无监督/强化学习差异与应用场景图解 (基础重构)

五、资源更新

CAS单点登录 V2版》上线→ 接入到 CAS 平台中,并实现单点登录

组织/用户/角色信息管理API接口》上线→ 一套 HTTP API的组织、用户、角色信息管理接口

竹云统一身份认证平台组织用户同步对接》上线→ Smartbi封装对应的服务接口,给竹云的统一身份认证平台实时调用,完成组织、用户和角色信息的实时同步。

交互式仪表盘支持自定义字体》优化→ 修复了文本组件编辑状态不生效的问题

只允许外网某种移动端APP访问》优化→ 针对V11版本,增加了钉钉、企业微信访问限制功能

AD域(LDAP/LDAPS)登录验证》优化→ 修复了“更新白名单状态之前没有判断判断用户是否存”的问题

元数据分析落地到知识库》优化→ 增加获取资源创建者的逻辑判断,对空值空对象等情况做优化

麦粉社区
>
帖子详情

填报禁止回写

电子表格软件 发表于 2025-5-28 11:14
发表于 2025-5-28 11:14:00
本帖最后由 kc 于 2025-5-28 11:42 编辑

我有两个sheet都是填报的电子表格,现在想通过每个sheet中的L1单元格判断是否为1,去禁止填写,两个sheet的L1值可能不一样,现在代码可以实现控制第二个sheet的回写,但是第一个只能控制前后几行,求助各位大佬帮忙看看是哪里有问题,感谢!!!


服务端:


function main(spreadsheetReport) {

   
    // 获取电子表格所有sheet对象,0表示第一个sheet,1表示第二个,2表示第三个
    var sheet1 = spreadsheetReport.workbook.getWorksheets().get(0);     
    var value1 = sheet1.getCells().getCell(0, 11).value;  // getCell(0, 11),表示获取L1单元格第1行,第12列的单元格的值
    spreadsheetReport.customProperties.put("LValue1", value1);

    var sheet11 = spreadsheetReport.sheets[0];
    var posList1 = sheet11.getExpandedPositions("F4"); //获取F4单元格拓展出来的最大行数
    spreadsheetReport.customProperties.put("maxrow1", posList1.length);
   

   
    // 获取电子表格所有sheet对象,0表示第一个sheet,1表示第二个,2表示第三个
    var sheet2 = spreadsheetReport.workbook.getWorksheets().get(1);     
    var value2 = sheet2.getCells().getCell(0, 11).value;  // getCell(0, 11),表示获取L1单元格第1行,第12列的单元格的值
    spreadsheetReport.customProperties.put("LValue2", value2);

    var sheet22 = spreadsheetReport.sheets[1];
    var posList2 = sheet22.getExpandedPositions("5"); //获取F4单元格拓展出来的最大行数
    spreadsheetReport.customProperties.put("maxrow2", posList2.length);

}




客户端:


function main(spreadsheetReport) {
   
    var customProperties = spreadsheetReport.elemSheetFrame.contentWindow.customProperties;
    var cells = spreadsheetReport.elemSheetFrame.contentWindow;
    var writableMap = cells.writableMap;

    var targetCols1 = ["5", "6", "7"];
               
    // 获取开始行数
    var startRow1 = 3;  // 第四行对应索引3
    // 获取最大数据行数
    var maxRow1 = customProperties["maxrow1"] + 100;

    for (var row1 = startRow1; row1 <= maxRow1; row1++) {
        var LValue1 = customProperties["LValue1"]
        // alert(LValue1);

        if (LValue1 == "1" || LValue1 == 1) {
            // 禁止回写逻辑
            targetCols1.forEach(function(col) {
                var colKey = row1 + ":" + col;  // 格式:"*:5" 表示所有行的第6列
                // alert(colKey)
                if (writableMap[colKey] && !writableMap["bak." + colKey]) {
                    writableMap["bak." + colKey] = writableMap[colKey];  // 备份原始状态
                    delete writableMap[colKey];                          // 禁用回写
                }
            });
        } else {
            // 恢复回写逻辑
            targetCols1.forEach(function(col) {
                var colKey = row1 + ":" + col;
                // alert(colKey)
                if (writableMap["bak." + colKey]) {
                    writableMap[colKey] = writableMap["bak." + colKey];  // 恢复原始状态
                    delete writableMap["bak." + colKey];                  // 清除备份
                }
            });
        
        }
    }
   

    var targetCols2 = ["1", "2", "3", "4", "5", "6","7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"];
               
    // 获取开始行数
    var startRow2 = 4;  // 第四行对应索引3
    // 获取最大数据行数
    var maxRow2 = customProperties["maxrow2"] + 50;

    for (var row2 = startRow2; row2 <= maxRow2; row2++) {
        var LValue2 = customProperties["LValue2"]
        // alert(LValue2);

        if (LValue2 == "1" || LValue2 == 1) {
            // 禁止回写逻辑
            targetCols2.forEach(function(col) {
                var colKey = row2 + ":" + col;  // 格式:"*:5" 表示所有行的第6列
                // alert(colKey)
                if (writableMap[colKey] && !writableMap["bak." + colKey]) {
                    writableMap["bak." + colKey] = writableMap[colKey];  // 备份原始状态
                    delete writableMap[colKey];                          // 禁用回写
                }
            });
        } else {
            // 恢复回写逻辑
            targetCols2.forEach(function(col) {
                var colKey = row2 + ":" + col;
                // alert(colKey)
                if (writableMap["bak." + colKey]) {
                    writableMap[colKey] = writableMap["bak." + colKey];  // 恢复原始状态
                    delete writableMap["bak." + colKey];                  // 清除备份
                }
            });
        
        }
    }
   
}
发表于 2025-5-28 11:18:16
88713683680706332a.png
776466836805a7217e.png
4089968368062e8464.png
回复

使用道具 举报

发表于 2025-5-28 14:57:51

已解决,增加sheet页的判断


function main(spreadsheetReport) {
    var win = spreadsheetReport.elemSheetFrame.contentWindow;
    var writableMap = win.writableMap;
    var customProperties = win.customProperties;
   
    var sheetIndex = spreadsheetReport.currentSheetIndex;//获取当前sheet页序号,从0开始
   
   if(sheetIndex==0){
    // alert("当前sheet页="+sheetIndex);
   
    // ========================= Sheet1:"家中、CP、RA" =========================
    var targetCols1 = ["5", "6", "7"]; // F-H 列(索引从0开始)
    var startRow1 = 3;                  // 起始行(第4行)
    var maxRow1 = (customProperties["maxrow1"] || 0) + 100; // 扩展行范围
    var LValue1 = customProperties["LValue1"];

    for (var row1 = startRow1; row1 <= maxRow1; row1++) {
        targetCols1.forEach(function(col) {
            var key1 = row1 + ":" + col;
            var backupKey = "sheet1_bak_" + key1; // 独立备份键
            if (LValue1 == "1" || LValue1 == 1) {
                if (writableMap[key1] && !writableMap[backupKey]) {
                    writableMap[backupKey] = writableMap[key1];
                    delete writableMap[key1];
                }
            } else {
                if (writableMap[backupKey]) {
                    writableMap[key1] = writableMap[backupKey];
                    delete writableMap[backupKey];
                }
            }
        });
    }


   }else if(sheetIndex==1){
    // alert("当前sheet页="+sheetIndex);
     
    // ========================= Sheet2:"地产、大项" =========================
    var targetCols2 = ["1", "2", "3", "4", "5", "6","7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"]; // B-T 列
    var startRow2 = 4;                   // 起始行(第5行)
    var maxRow2 = (customProperties["maxrow2"] || 0) + 50; // 更大的行范围
    var LValue2 = customProperties["LValue2"];

    for (var row2 = startRow2; row2 <= maxRow2; row2++) {
        targetCols2.forEach(function(col) {
            var key2 = row2 + ":" + col;
            var backupKey = "sheet2_bak_" + key2; // 独立备份键
            if (LValue2 == "1" || LValue2 == 1) {
                if (writableMap[key2] && !writableMap[backupKey]) {
                    writableMap[backupKey] = writableMap[key2];
                    delete writableMap[key2];
                }
            } else {
                if (writableMap[backupKey]) {
                    writableMap[key2] = writableMap[backupKey];
                    delete writableMap[backupKey];
                }
            }
        });
    }
   }
   
   
}

 

回复

使用道具 举报

发表于 2025-5-28 16:37:45
帅帅帅,学习学习
回复

使用道具 举报

高级模式
B Color Image Link Quote Code Smilies
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

3回帖数 0关注人数 319浏览人数
最后回复于:2025-5-28 16:37
快速回复 返回顶部 返回列表