Jump to content

CSV reports not displaying Japanese characters


kalyan.sarkar

Recommended Posts

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

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

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

  • 1 year later...
  • 1 month later...

@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

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...