温馨提示
本文档的示例代码仅适用于本文档中的示例报表/场景。若实际报表/场景与示例代码无法完全适配(如使用功能不一致,或多个宏代码冲突等),需根据实际需求开发代码。
示例说明
电子表格有回写及分页数据,并且不显示工具栏,使用openresource.jsp打开报表时(http://192.168.1.10:9999/smartbi/vision/openresource.jsp?resid=I4028818a32e86aa801543bef4d1317a2&showtoolbar=false),分页按钮和保存按钮显示在2行
有时为了节约空间,可以把分页按钮和保存按钮放在同一行。通过下面宏示例可以达到效果。
版本及客户端说明
1.smartbi版本:最新版本
2.客户端:PC
3.浏览器:IE11、谷歌浏览器(Chrome)、火狐浏览器(Firefox)
设置方法
1、首先在电子表格设计器(Microsoft Office Excel)中,创建电子表格报表。
2、在浏览器的资源定制节点下,选中电子表格,右键选择 编辑宏 进入报表宏界面。
3、在报表宏界面新建客户端模块。在弹出的新建模块对话框中,选择对象为spreadSheetReport、事件为onRender、并把下面宏代码复制到代码编辑区域。
宏类型
类型 | 对象 | 事件 |
---|---|---|
ClientSide | spreadsheetReport | onRender |
宏代码
function main(spreadsheetReport) { if (!spreadsheetReport._newBtn) { // 不要重复添加按钮 //按钮样式 var input = document.createElement("INPUT"); input.type = "button"; input.className = "button-buttonbar button-bgicon-save"; input.value = "保存(S)"; input.title = "保存"; input.accessKey = "S"; input.style.width = "80"; input.style.height = "22"; //按钮位置定位 var div = document.createElement("div"); div.style.marginLeft = "350"; var pElement = spreadsheetReport.elem_trPagePanel; if (!pElement.firstChild.firstChild) { return; } pElement.firstChild.firstChild.style.float = "left"; if (pElement.clientWidth < 430) { div.style.marginLeft = "5"; div.style.marginTop = "35"; } div.appendChild(input); //隐藏旧的保存按钮,并添加新按钮到报表页面 var nextEl = pElement.nextSibling; if (nextEl.nodeName != "TR") { nextEl = nextEl.nextSibling; } nextEl.style.display = "none"; var newBtn = pElement.firstChild.appendChild(div); //按钮事件 spreadsheetReport.addListener(newBtn, "click", function() { spreadsheetReport.spreadsheetReportWriteBack.doSaveClick(); }, spreadsheetReport); spreadsheetReport._newBtn = newBtn; } };
关键对象总结
- 电子表格分页按钮行对象:spreadsheetReport.elem_trPagePanel
- 保存按钮事件:spreadsheetReport.spreadsheetReportWriteBack.doSaveClick()
资源下载
报表资源:migrate.xml(该资源基于内置的northwind数据库实现)