I am using ICsvBeanWriter to export data as CSV and i am trying to open it in Excel.But I am unable to view Chinese characters in Excel by default.But if i load the csv file and change encoding from Western European to 65001 Unicode(UTF-8) then i am able to see Chinese characters displayed in excel.So my question is "Is it possible to open excel with default UTF-8 encoding? Here is my code
Controller.java
response.setHeader("Content-Disposition",
"attachment; filename=Report " + downloadDateFormatted + ".csv");
response.setHeader(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, HttpHeaders.CONTENT_DISPOSITION);
**response.setContentType("text/csv;charset=UTF-8");**
CsvExporter csvExporter = new CsvExporter(transactions);
csvExporter.export(response);
CsvExporter.java
public void export(HttpServletResponse response) throws IOException {
csvWriter = new CsvBeanWriter(response.getWriter(), CsvPreference.STANDARD_PREFERENCE);
writeHeaderRow();
}
private void writeHeaderRow() throws IOException {
String[] csvHeader = {"Chinese address" };
csvWriter.writeHeader(csvHeader);
String[] nameMapping = { "chineseAddress" };
csvWriter.write(transaction, nameMapping);
}
csvWriter.close();
}
I tried setting charset to utf-8 but still it is opening in Western European encoding in Excel by default.I tried with UTF-16.But still same result.When i open in other editors like notepad chinese characters are displayed perfectly but not working in Excel