马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。如果您注册时有任何问题请联系客服QQ: 83569622 。
您需要 登录 才可以下载或查看,没有帐号?注册
x
本帖最后由 wsff 于 2009/5/21 16:31 编辑
下面是本人得到的关于FineReport三个典型报表图的代码制作过程。有兴趣的可以参考一下,很有帮助!
ListReport
实现代码: package ms;
import java.io.File;
import com.fr.base.Constants;
import com.fr.base.FRContext;
import com.fr.base.dav.LocalEnv;
import com.fr.demo.ArrayTableDataDemo;
import com.fr.report.CellElement;
import com.fr.report.Report;
import com.fr.report.WorkBook;
import com.fr.report.WorkSheet;
import com.fr.report.cellElement.CellExpandAttr;
import com.fr.report.cellElement.TableDataColumn;
import com.fr.report.cellElement.core.DSColumn;
import com.fr.report.cellElement.core.FunctionGrouper;
import com.fr.report.io.TemplateImporter;
import com.fr.web.Reportlet;
import com.fr.web.ReportletException;
import com.fr.web.ReportletRequest;
public class ListReportlet implements Reportlet{
public Report createReport(ReportletRequest req) throws ReportletException {
WorkBook workBook = null;
try {
File cptFile = new File("D:\\listreport.cpt");
TemplateImporter templateImporter = new TemplateImporter(cptFile);
workBook = (WorkBook)templateImporter.generateReport();
// 定义程序数据集
String[] columnNames = {"月份", "产品", "销售额"};
Object[][] rowData = {
{"五月", "手机", new Integer(500)},
{"五月", "相机", new Integer(600)},
{"五月", "手表", new Integer(800)},
{"六月", "手机", new Integer(300)},
{"六月", "相机", new Integer(100)}
};
ArrayTableDataDemo tableData = new ArrayTableDataDemo(columnNames, rowData);
WorkSheet workSheet = (WorkSheet)workBook.getReport(0);
// 将数据集添加到workSheet中, Employee为表名
workSheet.putTableData("Employee", tableData);
// 把月份数据列放在单元格A2
DSColumn dsColumn = new DSColumn();
dsColumn.setDSName("Employee");
dsColumn.setGrouper(new FunctionGrouper());
dsColumn.setColumn(TableDataColumn.createColumn("月份"));
CellElement cellElement = workSheet.getCellElement(0, 1);
cellElement.setValue(dsColumn);
// 把产品填入到B2
dsColumn = new DSColumn();
dsColumn.setDSName("Employee");
dsColumn.setGrouper(new FunctionGrouper());
dsColumn.setColumn(TableDataColumn.createColumn("产品"));
cellElement = workSheet.getCellElement(1, 1);
cellElement.setValue(dsColumn);
// 把销售额填入到c2
// 把产品填入到B2
dsColumn = new DSColumn();
dsColumn.setDSName("Employee");
dsColumn.setGrouper(new FunctionGrouper());
dsColumn.setColumn(TableDataColumn.createColumn("销售额"));
cellElement = workSheet.getCellElement(2, 1);
cellElement.setValue(dsColumn);
} catch (Exception exp) {
exp.printStackTrace();
}
return workBook;
}
}
|
附件为相关的CPT文件注意查收~
|