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;
}
}