本文档的示例代码仅适用于本文档中的示例报表/场景。若实际报表/场景与示例代码无法完全适配(如使用功能不一致,或多个宏代码冲突等),需根据实际需求开发代码。 |
在项目中有是要对单元格中的值进行校验,如单元格中的值是不是数字,如下图:
1、首先在电子表格设计器(Microsoft Office Excel)中,创建电子表格报表。
2、在浏览器的资源定制节点下,选中电子表格,右键选择 编辑宏 进入报表宏界面。
3、在报表宏界面新建客户端模块。在弹出的新建模块对话框中,选择对象为spreadSheetReport、事件为onRenderReport、并把下面宏代码复制到代码编辑区域。
类型 | 对象 | 事件 |
---|---|---|
ClientSide | spreadsheetReport | onRenderReport |
function main(spreadsheetReport) { spreadsheetReport.spreadsheetReportWriteBack.updateWriteBackData_marco = spreadsheetReport.spreadsheetReportWriteBack.updateWriteBackData; spreadsheetReport.spreadsheetReportWriteBack.updateWriteBackData = function(sheetIndex, position, td, oldValue, value, displayValue, type,update) { var m = spreadsheetReport.elemSheetFrame.contentWindow.writableMap[position]; //读取修改单元格的信息 if (m.cell == "B3") { //判断单元格在模板中的位置 if (!value || !value.match(/^\d+$/)) { //判断数据是数字 alert('输入不合法'); return; } } this.updateWriteBackData_marco(sheetIndex, position, td, oldValue, value, displayValue, type,update); } } |
通过spreadsheetReport.elemSheetFrame.contentWindow.writableMap[position] 读取修改单元格的信息。