页面树结构
转至元数据结尾
转至元数据起始

提示:本文档的示例代码仅适用于本文档中的示例报表/场景。若实际报表/场景与示例代码无法完全适配(如使用功能不一致,或多个宏代码冲突等),需根据实际需求开发代码。

示例说明

    电子表格回写,插入新行,若点击不是第一列单元格,则插入的新行不是完整的一行,如:
    

    使用宏代码之后,点击任一单元格插入新行,都是完整的一行

    注:该宏实现的任一单元格插入新行的效果,只对通过工具栏的 添加行)按钮插入的方式有效。
    

设置方法

  1. 在电子表格设计器(Microsoft Office Excel)中,创建 回写电子表格。
  2. 在浏览器的资源定制节点下,选中电子表格,右键选择 编辑宏 进入报表宏界面
  3. 在报表宏界面新建客户端模块,在弹出的新建模块对话框中,选择对象为 spreadsheetReport、事件为onRenderReport,并把下面宏代码复制到代码编辑区域。


宏类型

宏类型

对象

事件

ClientSide

spreadsheetReport

onRenderReport


宏代码

function main(spreadsheetReport) {
    //debugger;
    var spreadsheetReportWriteBack = spreadsheetReport.spreadsheetReportWriteBack;
    spreadsheetReportWriteBack.removeListener(spreadsheetReportWriteBack.elem_btnAppendRow, "click", spreadsheetReportWriteBack.doInsertRowClick);
    spreadsheetReportWriteBack.addListener(spreadsheetReportWriteBack.elem_btnAppendRow, "click", function() {
            var currentEditingPosition = this.currentEditingPosition;
            var idx = currentEditingPosition.indexOf(':') + 1;
            this.currentEditingPosition = currentEditingPosition.substring(0, idx) + 1; //这个1是表示第二列的意思,从0开始计数
            //若报表中第一个字段放置在C列,则应该+2,若第一个字段放置在D列,则应该+3
            this.doInsertRowClick();
        },
        spreadsheetReportWriteBack);
    spreadsheetReportWriteBack.doInsertRowClick_old = spreadsheetReportWriteBack.doInsertRowClick;
    spreadsheetReportWriteBack.doInsertRowClick = function(e) {
        var currentEditingPosition = this.currentEditingPosition;
        var idx = currentEditingPosition.indexOf(':') + 1;
        this.currentEditingPosition = currentEditingPosition.substring(0, idx) + 1; //这个1是表示第二列的意思,从0开始计数
        //若报表中第一个字段放置在C列,则应该+2,若第一个字段放置在D列,则应该+3
        spreadsheetReportWriteBack.doInsertRowClick_old(e);
    }
};

评论

  1. 李顺波 发表:

     不支持字段设置了排序,如果设置了排序,添加行的效果就会有问题。