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

该宏示例在 V10.5上 验证通过

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

示例说明

在透视分析报表的第一行参数最后添加“分析”按钮,点击“分析”则刷新报表,在第二行参数后面添加“导出”按钮,点击“导出”,则导出excel。

具体实现效果见下图:

设置方法

  1. 在“分析展现”节点下,创建一张透视分析。
  2. 选中透视分析,右键选择 编辑宏 进入报表宏界面。
    注意:该透视分析要求参数分两列。

  3. 在报表宏界面新建客户端模块,在弹出的新建模块对话框中选择对象为INSIGHT;事件为onRender;并把下面宏代码复制到代码区域。

宏类型

类型

对象

事件

ClientSide

INSIGHT

onRender

宏代码

添加按钮
function main(insight) {
    if (typeof(insight.old_rebuildParamPanel) == "undefined") {
        insight.old_rebuildParamPanel = insight.rebuildParamPanel;
        insight.rebuildParamPanel = function() {
            this.old_rebuildParamPanel();
            addBtns(this);
        };
    }
}
//添加按钮
function addBtns(insight) {
    var paramTable = insight.paramPanelObj.layoutTable;
    var i, cell, lastCell1, lastCell2;
    for (i = 0; i < paramTable.rows.length; i++) {
        cell = paramTable.rows[i].insertCell(-1);
        if (i == 0) lastCell1 = cell; //paramTable.rows.length - 1
        if (i == 1) lastCell2 = cell;
    }
    //添加分析按钮
    if (lastCell1) {
        var btnElem = document.createElement("button");
        btnElem.innerText = "分析";
        btnElem.className = "queryview-toolbar-button";
        btnElem.style.border = "1px solid #A1ACB9";
        btnElem.style.width = "60px";
        btnElem.style.height = "23px";
        btnElem.style.padding = "2px 0 0 0";
        btnElem.style.margin = "0 10px 0 10px";
        insight.addListener(btnElem, 'click',
            function() {
                insight.doRefresh();
            }, this);
        lastCell1.appendChild(btnElem);
    }
    //添加导出按钮
    if (lastCell2) {
        var btnExport = document.createElement("button");
        btnExport.innerText = "导出";
        btnExport.className = "queryview-toolbar-button";
        btnExport.style.border = "1px solid #A1ACB9";
        btnExport.style.width = "60px";
        btnExport.style.height = "23px";
        btnExport.style.padding = "2px 0 0 0";
        btnExport.style.margin = "0 10px 0 10px";
        insight.addListener(btnExport, "click",
            function() {
                insight.doExportMenuCloseUp("EXCEL2007");
            }, this);
        lastCell2.appendChild(btnExport);
    }
}

资源下载

资源:migrate.xml