我们可以通过写Java类调用创建的报表模版,动态的填充数据
一 创建模版
打开设计器,创建一个报表
里面只有一个表格,
[img]http://dl.iteye.com/upload/attachment/0075/5135/b86b4fb8-c68e-3b71-8605-0828d0af3e73.jpg[/img]
双击可以查看表格的属性
[img]http://dl.iteye.com/upload/attachment/0075/5137/a595dddb-94c5-368f-9381-42a2d4b323a2.jpg[/img]
写一个Java类
运行
[img]http://dl.iteye.com/upload/attachment/0075/5141/40a50c0f-4e63-39ae-8f71-48029a31623e.jpg[/img]
一 创建模版
打开设计器,创建一个报表
里面只有一个表格,
[img]http://dl.iteye.com/upload/attachment/0075/5135/b86b4fb8-c68e-3b71-8605-0828d0af3e73.jpg[/img]
双击可以查看表格的属性
[img]http://dl.iteye.com/upload/attachment/0075/5137/a595dddb-94c5-368f-9381-42a2d4b323a2.jpg[/img]
写一个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();
}
}
}
运行
[img]http://dl.iteye.com/upload/attachment/0075/5141/40a50c0f-4e63-39ae-8f71-48029a31623e.jpg[/img]