kalyan.sarkar Posted August 2, 2013 Share Posted August 2, 2013 We are generating CSV reports using Jasperreports 5.0.1. The reports are UTF-8 encoded.However, when we download the report, the report opens in Excel using the file association, but the Japanese characters are not rendered. For example instead of 市場取引 we see å¸‚å ´å–引. Our locale is en_US on Windows 7. In locale ja_JP, the Japanese characters are improperly rendered. If we download the report and open in any text editor, the characters are showing correctly.Any idea, what is going on? Thanks in advance. Link to comment Share on other sites More sharing options...
aspanier Posted August 2, 2013 Share Posted August 2, 2013 Hi, Kalyan. Are you exporting directly to Excel, or are you exporting to CSV then opening that report in Excel?If you aren't doing it already, try exporting directly to Excel, then saving the Excel report as a CSV. If you are still experiencing the problem, leave me a comment and I'll look into it further.Thanks!aimee Link to comment Share on other sites More sharing options...
kalyan.sarkar Posted August 4, 2013 Author Share Posted August 4, 2013 Hi Aimee, thanks for the reply. Unfortunately, exporting to Excel and then saving it as CSV is not an option. It would be inconvenient for the users. The users shall be able to (1) download the CSV reports and (2) directly open the CSV reports in Excel. Link to comment Share on other sites More sharing options...
aspanier Posted August 5, 2013 Share Posted August 5, 2013 OK, let me look into it further and see if I can find a solution for you. Link to comment Share on other sites More sharing options...
caleb.canon Posted February 2, 2015 Share Posted February 2, 2015 aspanier , any update on this. @kalyan.sarkar, I'm also facing a similar issue, Have you reolved this issue . If yes please let me know the steps. Link to comment Share on other sites More sharing options...
namnvptit Posted March 17, 2015 Share Posted March 17, 2015 @caleb.canon:I've just resolved this issue. The root cause of this problem is we did'nt inserted BOM (byte-order marker) to out put file before insert its content. Therefore we can not see data correctly. Here is my solution: public static boolean exportToCSV(Connection conn, String outputFile, Map params, JasperReport jasperReportCSV) throws JRException { try { ByteArrayOutputStream outputByteArray = new ByteArrayOutputStream(); FileOutputStream outStream = new FileOutputStream(new File(outputFile + ".csv")); //byte-order marker (BOM) byte b[] = {(byte)0xEF, (byte)0xBB, (byte)0xBF}; //insert BOM byte array into outputStream outStream.write(b); params.put(JRParameter.IS_IGNORE_PAGINATION, Boolean.TRUE); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReportCSV, params, conn); jasperPrint.getPropertiesMap().setProperty("net.sf.jasperreports.export.csv.exclude.origin.band.pageFooter","pageFooter"); JRCsvExporter exporter = new JRCsvExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outputByteArray); exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8"); exporter.exportReport(); outStream.write(outputByteArray.toByteArray()); outStream.flush(); outStream.close(); } catch (Exception e) { log.error(e.getMessage(), e); return false; } return true; }[/code]Hope it will help you!Best,NamNV Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now