使用快逸报表Api导出Word

package com.widemex.reportViewWord;

import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.runqian.report4.model.ReportDefine;
import com.runqian.report4.model.engine.ExtCellSet;
import com.runqian.report4.usermodel.Context;
import com.runqian.report4.usermodel.DataSourceConfig;
import com.runqian.report4.usermodel.Engine;
import com.runqian.report4.usermodel.IReport;
import com.runqian.report4.usermodel.PageBuilder;
import com.runqian.report4.util.ReportUtils;
import com.runqian.report4.view.word.WordReport;

public class ReportViewWord {

/**
* @param args
*/
public static void main(String[] args) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("userId", "");
params.put("orgId", "");
Calendar c = Calendar.getInstance();

params.put("beginTime", "2011-1-1" );
c.set(Calendar.DAY_OF_MONTH, 30);
//params.put("endTime", c.getTime());
params.put("endTime", "2011-12-31" );

try {
ReportViewWord.reportViewWord("E:\\work\\report\\orderFood.raq", "D:/temp/orderFood.doc", params);
} catch (Throwable e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


}

public static void reportViewWord(String tmp_reportname,String temp_FileName,Map<String, Object> params) throws Throwable{
String text = "";
// String[] temp_array =temp_Url.split("&");
// String tmp_reportname = "D:/reportfiles/"+temp_array[0]+".raq"; //本地
// String tmp_reportname = "D:/AppVirFiles/reportFiles/"+temp_array[0]+".raq";//114
// String tmp_reportname = "D:/eps/AppVirFiles/reportfiles/"+temp_array[0]+".raq";//生产
Connection con = null;

try{
if( tmp_reportname != null ) {
//if( !temp_FileName.startsWith( "/" ) ) temp_FileName = "/" + temp_FileName;
ReportDefine rd = (ReportDefine)ReportUtils.read(tmp_reportname);
ExtCellSet.setLicenseFileName("E:\\work\\report\\license.lic");
//Env env = new Env( rd );
//JDBC连接
//Class.forName( "com.newatlanta.jturbo.driver.Driver" );
//con = DriverManager.getConnection( "jdbc:JTurbo://32.0.179.202/easyreport", "", "" );
//web.xml中的jndi配置
//con = DataServlet.getDBObject(null).getConnection();
Context ctx=new Context();
for(Map.Entry e :params.entrySet()){
ctx.setParamValue(e.getKey().toString(),e.getValue());
}
Class.forName( "com.ibm.db2.jcc.DB2Driver" );
con = DriverManager.getConnection( "jdbc:db2://192.168.1.16:50000/WIDES1", "S1", "w123456");
ctx.setDefDataSourceName("WIDES1_EXT");
ctx.setConnection("WIDES1_EXT",con);
DataSourceConfig dsoc = new DataSourceConfig(2, true, "UTF-8", "UTF-8", false);
ctx.setDataSourceConfig("WIDES1_EXT", dsoc);
Engine engine = new Engine(rd, ctx);
//DataSource ds=(DataSource)ctx.lookup("YTDS");
//con=ds.getConnection();
//env.setConnection( con, "iso-8859-1", DBTypes.INFMIX );
IReport report = engine.calc();

WordReport doc = new WordReport();
doc.export(new PageBuilder(report));


/*//设置报表参数
String[] temp_arrayAbs =null;
String temp_str="";
for(int i=1;i<temp_array.length;i++){
temp_arrayAbs=temp_array[i].split("=");
// temp_str =temp_arrayAbs[1];
if(temp_arrayAbs.length==2){
if(temp_arrayAbs[1].trim().length()!=0){
// temp_arrayAbs[1] = toISO(temp_arrayAbs[1]);
// System.err.println("temp_arrayAbs[1]:"+temp_arrayAbs[1]);
env.putParam(temp_arrayAbs[0],temp_arrayAbs[1]);
}

}

}*/
//构造一个报表引擎实例
//Engine e = new Engine( env );
//利用报表引擎计算得到报表实例

//Report report = e.calc();
//直接以文本方式显示报表
//text = report.toText();
File file = new File(temp_FileName);

java.io.OutputStream outStream=new java.io.FileOutputStream(file);
//report.exportToText(outStream);
doc.saveTo(outStream);
outStream.close();
//report.exportToHTML(temp_FileName);

//temp_FileName = rename(temp_FileName);

}
}
catch( Exception e ) {
e.printStackTrace();
System.err.println("导出文本错误:"+e);
}
/*finally{
if( con != null ) con.close();
}*/

//return temp_FileName;
}

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值