一 创建模版
打开设计器,创建一个报表
里面只有一个表格,
双击可以查看表格的属性
写一个Java类
package report; import inetsoft.report.PreviewView; import inetsoft.report.Previewer; import inetsoft.report.ReportSheet; import inetsoft.report.XSessionManager; import inetsoft.report.io.Builder; import inetsoft.report.lens.JDBCTableLens; import java.io.FileInputStream; public class Report2 { public static void main(String[] args) { try { //找到报表模版 FileInputStream input = new FileInputStream("D:\\StyleIntelligence Eval\\bin\\template.srt"); Builder builder = Builder.getBuilder(Builder.TEMPLATE, input); ReportSheet report = builder.read("."); //数据库连接,查询 JDBCTableLens table = new JDBCTableLens("jdbc:oracle:thin:@127.0.0.1:1521:orcl", "scott","Qwer1234", "select * from emp"); //数据绑定 report.setElement("Table1", table); //数据展示 PreviewView previewer = Previewer.createPreviewer(); previewer.setExitOnClose(true); previewer.pack(); previewer.setVisible(true); previewer.print(report); } catch (Exception e) { e.printStackTrace(); } } }
运行