Category: | Bug report |
Priority: | Normal |
Status: | New |
Project: | Severity: | Minor |
Resolution: | Open |
|
Component: | Reproducibility: | Always |
Assigned to: |
When i use JRXlsAbstractMetadataExporter with properties set as:
net.sf.jasperreports.export.xls.write.header=true
net.sf.jasperreports.export.xls.one.page.per.sheet=false
an extra empty row will always be printed between pages.
And be noticed, when export data without writing the header, there won't have any extra empty rows.
These extra empty rows will cause some troubles when we need to do some data calculations or other operations based on it.
So i think in most cases, these extra line shouldn't be exported.
After taking some study on the source code of JRXlsAbstractMetadataExporter.java, i found it's easy to fix this.
Below is my modified JRXlsAbstractMetadataExporter.java (based on 4.7.0 version) to solve this problem:
(1)remove line 249 in method exportPage(JRPrintPage page):
protected int exportPage(JRPrintPage page) throws JRException
{
List<JRPrintElement> elements = page.getElements();
currentRow = new HashMap<String, Object>();
line 249: //rowIndex += writeHeader ? 1 : 0; //this is not correct for all cases!
(2)add below code right before line 205 , in the method: exportReportToStream(OutputStream os):
add this line: rowIndex += (writeHeader ? 1 : 0); //only for isOnePagePerSheet=true that need to add for each page!
line 205: exportPage(page);
(3)add below code right before line 231, in the method: exportReportToStream(OutputStream os):
// only need to add 1 row for the first page in case of exporting all data to one sheet!
if (pageIndex == startPageIndex){
rowIndex += (writeHeader ? 1 : 0);
}
line 231: exportPage(page);
I'm not quite sure if this modify will cause other problems , but at least it works for me.
1 Comment: