使用JasperReports 3.7.6(带有iReport)生成跨越两页的报告:report包含18列数据的表,第一页上的列为1到10,第二页上的列为11到18,一个数据记录显示在两个页面上,可以收集大量数据。我试图搜索论坛,在jasper论坛上提问,但没有得到答案。
什么能解决这个问题?
答案 0 :(得分:0)
1)我认为这很清楚,但是......只需将多页报告的每页分开。
2)使用从一个报告到另一个报告的复制/粘贴XML将所有分隔的页面合成为一个,最后只存在一个报告,它将包含所有元素(之前已分开)
3)写数据源,可能会包含你:
private final List data; private final Iterator iterator;
private List<IRecord> buffer;
private Iterator<IRecord> bufferIterator;
private IRecord currentValue;
private int pageCount;
private int pageRowNum;
private boolean useBuffer;
private int position;
private int counter;
public MultiPageReportDataSource(List<? extends IRecord> data, int pageRowNum, int pageCount) {
this.data = data;
this.iterator = this.data.iterator();
this.buffer = new LinkedList<IRecord>();
this.bufferIterator = this.buffer.iterator();
this.pageRowNum = pageRowNum;
this.pageCount = pageCount;
this.counter = pageCount;
}
@Override
public boolean next() throws JRException {
if (position > 0 && position % pageRowNum == 0) {
counter--;
if (counter == 0) {
buffer.clear();
useBuffer = false;
counter = pageCount;
} else {
useBuffer = true;
bufferIterator = buffer.iterator();
}
position = 0;
}
if (useBuffer) {
if (bufferIterator.hasNext()) {
currentValue = bufferIterator.next();
}
} else {
if (iterator.hasNext()) {
currentValue = iterator.next();
buffer.add(currentValue);
} else {
return false;
}
}
position++;
return true;
}
@Override
public Object getFieldValue(JRField jrField) throws JRException {
Field field = ReflectUtil.field(CashierReportEntity.class, jrField.getName());
try {
return ReflectUtil.accessible(field).get(currentValue);
} catch (IllegalAccessException e) {
throw new JRException(e);
}
}