在使用java api连接Smartbi操作电子表格的时候,常有如下问题:
原因分析:
一般是导出分组报表doExport方法传递的的type参数的值不对,比如应该传递EXCEL2007写成了EXCEL_2007。
使用的导出接口为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导出
在全模块的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; } } |