当前位置:首页 > ognos SDK将报表下载到本地
import com.cognos.developer.schemas.bibus._3.EventManagementService_ServiceLocator; import com.cognos.developer.schemas.bibus._3.Option; import com.cognos.developer.schemas.bibus._3.Output;
import com.cognos.developer.schemas.bibus._3.ParameterValue; import com.cognos.developer.schemas.bibus._3.ParmValueItem; import com.cognos.developer.schemas.bibus._3.PropEnum; import com.cognos.developer.schemas.bibus._3.QueryOptions;
import com.cognos.developer.schemas.bibus._3.RunOptionBoolean; import com.cognos.developer.schemas.bibus._3.RunOptionEnum;
import com.cognos.developer.schemas.bibus._3.RunOptionStringArray; import com.cognos.developer.schemas.bibus._3.SearchPathMultipleObject; import com.cognos.developer.schemas.bibus._3.SearchPathSingleObject; import com.cognos.developer.schemas.bibus._3.SimpleParmValueItem; import com.cognos.developer.schemas.bibus._3.Sort;
import com.cognos.developer.schemas.bibus._3.XmlEncodedXML;
public class Lesson1{
public ContentManagerService_Port contentManagerService = null; public EventManagementService_Port eventManagementService = null;
/**
*
方法名称: connectToReportServer|描述: 连接cognos服务器
* @param cognosURL cognos服务器的服务URL * @throws Exception */public void connectToReportServer(String cognosURL) throws Exception{ // 创建一个连接cognos内容库的服务定位对象 ContentManagerService_ServiceLocator cmServiceLocator ContentManagerService_ServiceLocator();
=
new
// 创建一个连接cognos事件管理的服务定位对象
EventManagementService_ServiceLocator evtServiceLocator = new EventManagementService_ServiceLocator(); try{
// 通过cognos服务器的服务URL,得到本机调用远程cognos内容库服务的入口方法
contentManagerService = cmServiceLocator.getcontentManagerService(new URL(cognosURL));
// 通过cognos服务器的服务URL,得到本机调用远程cognoscognos事件管理服务的入口方法
eventManagementService = evtServiceLocator.geteventManagementService(new URL(cognosURL)); }catch (Exception e){
System.out.println(e);
} }
/**
*
方法名称: logon|描述: LDAP登录。其实其它认证方式也类似。
* @param namespaceID LDAP命名空间 * @param uid LADP用户名 * @param pwd LDAP密码 * @return* @throws Exception */
public String logon(String namespaceID, String uid, String pwd) throws Exception{ // 创建一个XML,用于存放认证所需要的相关信息 StringBuffer credentialXML = new StringBuffer(); credentialXML.append(\
credentialXML.append(\
credentialXML.append(\ credentialXML.append(\ credentialXML.append(\
String encodedCredentials = credentialXML.toString(); try{
// 执行cognos登录操作
contentManagerService.logon(new XmlEncodedXML(encodedCredentials), null); BiBusHeader bibus = (BiBusHeader) ((Stub) contentManagerService).getHeaderObject(\
((Stub) eventManagementService).setHeader(\\bibus);
return (\用户 \登录成功。\ }catch (Exception e){
e.printStackTrace(); return (e.toString()); } }
/**
*
方法名称: executeReport|描述: 执行将报表导出为excel
* @param reportSearchPath 你要导出的报表,在cognos服务器中的完整名称 * @param execTime 执行时间 * @throws Exception */
public void executeReport(String reportSearchPath, GregorianCalendar execTime)
throws Exception{
// 导出设置
Option[] runOptions = new Option[3]; // 设置1:是否保存
RunOptionBoolean saveOutput = new RunOptionBoolean(); saveOutput.setName(RunOptionEnum.saveOutput); saveOutput.setValue(true); runOptions[0] = saveOutput;
// 设置2:导出格式 格式可以为CSV, HTMLFragment, MHT, PDF, singleXLS, XHTML, XLS,
的正常运行
// XLWA, XML, HTML
RunOptionStringArray outputFormat = new RunOptionStringArray(); outputFormat.setName(RunOptionEnum.outputFormat); // 目前设置的为 excel
outputFormat.setValue(new String[] {\runOptions[1] = outputFormat;
// 设置3:设置提示参数
RunOptionBoolean prompt = new RunOptionBoolean(); prompt.setName(RunOptionEnum.prompt); prompt.setValue(false); runOptions[2] = prompt;
// 下面为设置你的报表,页面需要传递的参数
// 假设我的报表需要输入4个参数, 年, 月, 数据来源, 企业名称 // 如果你的报表没有设置参数,那么就算设置了参数,也不会影响报表ParameterValue[] pvalue = new ParameterValue[4]; // 设置 年
SimpleParmValueItem item1 = new SimpleParmValueItem(); item1.setUse(\使用的值
item1.setDisplay(\显示用的值 item1.setInclusive(true);
ParmValueItem[] p1 = new ParmValueItem[1]; p1[0] = item1;
pvalue[0] = new ParameterValue();
pvalue[0].setName(\你在报表中定义的参数名称 pvalue[0].setValue(p1); // 设置 月
SimpleParmValueItem item2 = new SimpleParmValueItem(); item2.setUse(\item2.setDisplay(\item2.setInclusive(true);
ParmValueItem[] p2 = new ParmValueItem[1]; p2[0] = item2;
pvalue[1] = new ParameterValue();
pvalue[1].setName(\ pvalue[1].setValue(p2); // 数据来源
SimpleParmValueItem item3 = new SimpleParmValueItem(); item3.setUse(\ item3.setDisplay(\ item3.setInclusive(true);
ParmValueItem[] p3 = new ParmValueItem[1]; p3[0] = item3;
pvalue[2] = new ParameterValue(); pvalue[2].setName(\ pvalue[2].setValue(p3);
// 对企业名称的输入
SimpleParmValueItem item4 = new SimpleParmValueItem(); item4.setUse(\ item4.setDisplay(\ item4.setInclusive(true);
ParmValueItem[] p4 = new ParmValueItem[1]; p4[0] = item4;
pvalue[3] = new ParameterValue();// 数据来源 pvalue[3].setName(\ pvalue[3].setValue(p4);
// 将执行时间,导出设置,参数设置传递给cognos的event管理服务。于是cognos的event管理服务在设定的时间后开始异步执行。
String eventID = eventManagementService.runAt(execTime, new SearchPathSingleObject(reportSearchPath), pvalue, runOptions);
System.out.println(\报表: \
SimpleDateFormat formatter = new SimpleDateFormat(\HH:mm:ss.SSS\
String str = formatter.format(execTime.getTime()); System.out.println(\将在 \开始运行。\
System.out.println(\的event管理服务为其生成的事件唯一编号为: \
System.out.println(\你可以在congos门户中的Cognos Administration->状态中,看到此即将进行的活动。\ } /**
*
方法名称: getExecutionTime|描述: 设置导出的执行时间
共分享92篇相关文档