Column header postion is not appearing at top in CSV output using JRCSVMetadataExporter while exporting Group fields

0

I have a report with a group field and certain fields in the Detail section. Report is attached hereby. I am using XML file as datasource, it is also attached. While exporting it using JRCSVMetaDataExporter, column header position is coming at wrong position. Attached are the CSV output and PDF output for the report. I am using jasperreports 4.1.1 library.

On further analysis I found below.
1. Column header in CSV is appearing just above the row, falling in the group, with multiple rows.
2. Going through the JRCSVMetaDataExporter source, I found that for each page in the JasperPrint object exportPage() method is called. In this method, to export column header below logic is given.
if (columnNames.contains(currentColumnName) && !currentRow.containsKey(currentColumnName) && isColumnReadOnTime(currentRow, currentColumnName)) // the column is for export but was not read yet and comes in the expected order
{
currentRow.put(currentColumnName, currentTextValue);
} else if ( (columnNames.contains(currentColumnName) && !currentRow.containsKey(currentColumnName) && !isColumnReadOnTime(currentRow, currentColumnName)) // the column is for export, was not read yet, but it is read after it should be
|| (columnNames.contains(currentColumnName) && currentRow.containsKey(currentColumnName)) ) // the column is for export and was already read{
// write header
if (isFirstRow && writeHeader){
writeReportHeader();
}
if (isFirstRow) isFirstRow = false;
writeCurrentRow(currentRow, repeatedValues);......
}


3. If list of columns to export in CSV output (mentioned with net.sf.jasperreports.export.csv.column.names report property), contains any group column then elsif portion of above logic is not getting called and the row will be written without the column header being written.

4. I extended and updated the logic in JRCsvMetaDataExporter class and added below in exportPage() method. Now the output in the CSV file is proper.

// write last row
if (columnNames != null && columnNames.size() > 0){
// write header
if (isFirstRow && writeHeader){
writeReportHeader();
}
if (isFirstRow) isFirstRow = false;
writeCurrentRow(currentRow, repeatedValues);
}

Is there any way without extending the JRCsvMetaDataExporter class to resolve this problem? Or is this a bug in the JRCsvMetaDataExporter? Did anyone find similar kind of issue, if yes, could you please let me know how you resolved it?


 

ajaykumart's picture
Joined: Jun 19 2012 - 2:17am
Last seen: 5 years 1 month ago

0 Answers:

No answers yet
Feedback