我知道我知道。使用宏。
需要在服务端和客户端分别创建宏,服务端的宏用于获取电子表格的值,客户端从服务端获取该值,并进行判断和限制。
以下是我的案例。
需求背景:
有个文件上传功能的电子表格,但是当文件上传次数大于3时,就禁止上传
(1.禁止点击上传文件按钮;2.禁止填写描述文本。分别对应电子表格坐标7:13,7:15)。
实现如下:
1.创建服务端宏:
//服务端宏代码: function main(spreadsheetReport) { var sheets = spreadsheetReport.workbook.getWorksheets(); var sheet = sheets.get(0); var cnt= sheet.getCells().getCell(7,8).value;//展示已上传次数单元格的坐标。初始位置[0,0] spreadsheetReport.customProperties.put("CNT",cnt);//命名并绑定 }
2.创建客户端宏
//客户端宏代码
function main(spreadsheetReport) { ////获取上传次数单元格cnt_cell var cnt = spreadsheetReport.customProperties["CNT"]//服务端创建变量的值。 ////获取回写单元格坐标:wirtable_position
//alert(cnt); var cells = spreadsheetReport.elemSheetFrame.contentWindow; var uploadposition = "7:13"; //回写文件单元格的坐标。初始位置[0,0] var descposition = "7:15"; //回写文件单元格的坐标。初始位置[0,0] if (cnt >= "3") { //判断上传文件的次数是否大于3 if (cells.writableMap[uploadposition]) { cells.writableMap["bak.uploadposition"] = cells.writableMap[uploadposition]; delete cells.writableMap[uploadposition]; cells.writableMap["bak.descposition"] = cells.writableMap[descposition]; delete cells.writableMap[descposition]; } } else { if (cells.writableMap["bak.uploadposition"]) { cells.writableMap[uploadposition] = cells.writableMap["bak.uploadposition"]; delete cells.writableMap["bak.uploadposition"]; cells.writableMap[descposition] = cells.writableMap["bak.descposition"]; delete cells.writableMap["bak.descposition"]; } } } |