You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.9 KiB
49 lines
1.9 KiB
import com.raqsoft.dm.Sequence;
|
|
import com.raqsoft.report.model.ReportDefine;
|
|
import com.raqsoft.report.usermodel.Context;
|
|
import com.raqsoft.report.usermodel.DataSourceConfig;
|
|
import com.raqsoft.report.usermodel.Engine;
|
|
import com.raqsoft.report.usermodel.IReport;
|
|
import com.raqsoft.report.util.ReportUtils;
|
|
import com.raqsoft.report.util.StyleConfig;
|
|
import com.raqsoft.report.view.ReportExporter;
|
|
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.sql.Connection;
|
|
import java.sql.Driver;
|
|
import java.sql.DriverManager;
|
|
|
|
public class Test {
|
|
public static void main(String[] args) throws Throwable {
|
|
// 设置报表授权文件
|
|
File flic = new File("./reportTrialLicense20211231.xml");
|
|
FileInputStream lis = new FileInputStream(flic);
|
|
Sequence.readLicense(Sequence.P_RPT, lis);
|
|
|
|
//加载报表
|
|
String reportFile = "D:\\1.rpx"; //该文件名可以为绝对路径,也可以相对当前程序启动路径
|
|
ReportDefine rd = (ReportDefine) ReportUtils.read(reportFile);
|
|
|
|
//构建报表引擎计算环境
|
|
Context cxt = new Context();
|
|
Connection con = null;
|
|
try {
|
|
Driver driver = (Driver) Class.forName("org.postgresql.Driver").newInstance();
|
|
DriverManager.registerDriver(driver);
|
|
con = DriverManager.getConnection("jdbc:postgresql://10.10.14.206:5432/eduData_db", "root", "DsideaL147258369");
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
cxt.setConnection("HUANGHAI", con);
|
|
cxt.setDefDataSourceName("HUANGHAI");//这样设定默认数据源
|
|
Engine engine = new Engine(rd, cxt); //构造报表引擎
|
|
|
|
IReport iReport = engine.calc(); //运算报表
|
|
ReportExporter re = new ReportExporter("d:\\1.xls", ReportExporter.EXPORT_EXCEL); //导出为Excel
|
|
re.export(iReport); //导出
|
|
|
|
System.out.println("恭喜,导出成功!");
|
|
}
|
|
}
|