示例说明
我们有时候会需要在电子表格报表的工具栏上添加新的按钮,实现一些特殊的需求。比如添加按钮,点击时跳转到其它系统等。类似上述需求,皆可以参照如下方法进行设置。参考示例:
版本及客户端说明
1.smartbi版本:最新版本
2.客户端:PC
3.浏览器:IE11、谷歌浏览器(Chrome)、火狐浏览器(Firefox)
设置方法
1.创建电子表格
首先在电子表格设计器(Microsoft Office Excel)中,创建电子表格报表。
2.进入宏界面
在浏览器界面上,选中电子表格,右键选择 编辑宏 进入报表宏界面。
3.创建客户端宏
在报表宏界面新建客户端模块。在弹出的新建模块对话框中,选择对象为spreadSheetReport、事件为onRender、并把下面宏代码复制到代码编辑区域。
宏类型
类型 | 对象 | 事件 |
---|---|---|
ClientSide | spreadsheetReport | onRender |
宏代码
代码块 | ||||
---|---|---|---|---|
| ||||
function main(spreadsheetReport, isAjaxRefreshCallback) {
if (!spreadsheetReport._newBtn) { // 不要重复添加按钮
var input = document.createElement("button");
//input.className = "button-buttonbar button-bgicon-save";
input.innerText = "新按钮";
input.title = "新添加的按钮";
input.accessKey = "N";
input.style.width = "50px";
input.style.height = "25px";
input.style.verticalAlign = 'top';
input.style.marginLeft = "12px";
//spreadsheetReport.elem_tdSheets
var target = spreadsheetReport.elem_btnPrint.parentNode.nextSibling;
var newBtn = target.parentNode.insertBefore(input, target);
//var newBtn = spreadsheetReport.elem_btnPrint.parentNode.parentNode.appendChild(input);
spreadsheetReport.addListener(newBtn, "click", doNewButtonClick, spreadsheetReport);
spreadsheetReport._newBtn = newBtn;
}
}
// 新添加按钮Click事件处理函数
function doNewButtonClick(e) {
alert("TODO:Click事件处理函数。");
//如果要调用电子表格的相关方法,可参考如下:
//this.doPrint(true, false);//打印
//清单报表导出有如下方法
//this.doExportMenuCloseUp("CSV");//导出CSV,只支持清单报表
//this.doExportMenuCloseUp("LIST_EXCEL");//导出Excel
//分组报表导出有如下方法
//this.doExportMenuCloseUp("HTML");//导出HTML
//this.doExportMenuCloseUp("PDF");//导出PDF
//this.doExportMenuCloseUp("WORD");//导出Word
//this.doExportMenuCloseUp("EXCEL2007");//导出Excel
}
|
关键对象总结
通过spreadsheetReport.elem_btnPrint.parentNode.appendChild 方法,将新创建的按钮添加到工具栏的尾部。
- 利用spreadsheetReport.addListener 方法,为新创建的按钮绑定事件处理函数。
资源下载
报表资源:电子表格工具栏上添加按钮.xml
borderColor | #BBBBBB |
---|---|
bgColor | #F0F0F0 |
borderWidth | 1 |
borderStyle | solid |