Jump to content
Changes to the Jaspersoft community edition download ×

leading zeroes getting suppressed in CSV report


bhavaharan1

Recommended Posts

Teodor Please help.

 

I am trying to generate a report in CSV format and I am using XLS to open it.Leading zeros are getting suppresed in my report.For e.g 0997 is displayed as 997 and 00004486 is displayed as 4486. Can you please tell me how to stop this behaviour i.e how to display 0997 as 0997.The corresponding fields in JRXML are java.lang.String.

 

I am using iReport 1.3.0 and jasperreports-1.3.0.jar.

 

I am using the following method to generate my CSV report.I can send the JRXML file if needed.

 

I tried using JRXlsExporterParameter.IS_AUTO_DETECT_CELL_TYPE,Boolean.FALSE but it did not work.

 

 

public void renderXLS() {

 

JasperPrint jasperPrint = fillJasperPrint(ReportTab.EXCEL);

 

ServletOutputStream out = null;

HttpServletResponse response = FacesUtils.getServletResponse();

 

try {

response.setContentType("csv");

response.setHeader("Content-Disposition", "attachment; filename="

+ "unsaved.csv");

 

out = response.getOutputStream();

logger.info("Opened Servlet Output Stream: " + out);

} catch (IOException e) {

logger.error("Could not create an output stream due to... "

+ e.getMessage());

 

}

 

JRCsvExporter xlsExporter = new JRCsvExporter();

ByteArrayOutputStream xlsReport = new ByteArrayOutputStream();

xlsExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

xlsExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, xlsReport);

 

try {

xlsExporter.exportReport();

} catch (JRException e) {

logger.error("Could not export to Excel due to... "

+ e.getMessage());

}

 

byte[] bytes = xlsReport.toByteArray();

 

response.setContentLength(bytes.length);

 

try {

out.write(bytes, 0, bytes.length);

} catch (IOException e) {

logger.error("Error writing report to XLS stream. "

+ e.getMessage());

 

}

}

}

Post edited by: bhavaharan1, at: 2007/01/23 16:19

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...