在使用java api连接Smartbi导出电子表格的时候,常有如下问题:
1、清单报表导出Excel数据只有一页
导出接口为smartbi.sdk.service.spreadsheetreport.SSReport 类的
public void doExport(java.lang.String type, java.io.OutputStream os)方法
type参数说明:type
- 导出格式,有以下几个备选值 PDF、PNG、WORD、EXCEL2007(常用)、LIST_EXCEL(清单表导出Excel专用)、EXCEL(输出Excel2003)、HTML、CSV
针对分组表/Excel分析:PDF、PNG、WORD、EXCEL2007(常用)、EXCEL(输出Excel2003)、HTML
针对清单表:LIST_EXCEL(清单表导出Excel专用)、CSV
原因:
导出清单表的Excel格式传递的type参数值是EXCEL2007,需要把type参数值改为LIST_EXCEL导出就可以解决。
2、如何判断电子表格的报表类型
在全模块的License环境,总共有分组报表、清单报表、Excel融合分析三种电子表格报表子类型
电子表格定义中有reportType属性,其对应关系如下表:
报表类型 | reportType值 |
---|---|
分组报表 | 0 |
清单报表 | 1 |
Excel融合分析 | 2 |
目前java api文档没有接口获取电子表格的报表类型,可以参考如下方法获取reportType的值从而获取报表类型:
获取电子表格的报表类型
/** * 获取电子表格类型 */ public static int getSSReportType(){ ClientConnector connector = new ClientConnector("http://192.168.1.10:17300/smartbi"); boolean open = connector.open("admin", "admin"); String resId = "I4028818a015f906290629888015f9505e9ea4c2a"; //电子表格资源id if (open) { InvokeResult remoteInvoke = connector.remoteInvoke("SpreadsheetReportModule", "openQueryInPage", new Object[] {resId,null}); JSONObject originalResult = remoteInvoke.getOriginalResult(); JSONArray jsonArray = originalResult.getJSONArray("result"); JSONObject jsonObject = (JSONObject)jsonArray.get(0); JSONObject jsonObjectSet = jsonObject.getJSONObject("settings"); int reportType = jsonObjectSet.getInt("reportType"); if (reportType == 0) { System.out.println("分组报表"); } else if (reportType == 1) { System.out.println("清单报表"); } else if (reportType == 2) { System.out.println("Excel融合分析"); } return reportType; }else{ System.out.println("登录失败,无法获取报表类型"); return -1; } }