I’m trying to export and MS Excel sheet from JAVA that involves some Multi-Language (Japanese) content as well. I’ve tried several things but the Multi-Language (Japanese) content isn’t appearing properly in Exported Excel Sheet.
I’m picking up content from Database (I’ve checked Database, the Multi-Language-Japanese content is saved properly)
String fileName = "output"+".xls";
ExcelExport excelExporter = new ExcelExport();
excelExporter.ExportExcel(fileName, ....); // Writing Database Fields to Excel
File file = new File(fileName);
int length = 0;
response.setContentType("application/vnd.ms-excel");
response.setContentLength((int) file.length());
response.setHeader("Content-Disposition", "attachment; filename=\""+ file.getName() + "\"");
ServletOutputStream outputStream = response.getOutputStream();
byte[] bbuf = new byte[1024];
DataInputStream in = new DataInputStream(new FileInputStream(file));
while ((in != null) && ((length = in.read(bbuf)) != -1))
{
outputStream.write(bbuf, 0, length);
}
in.close();
outputStream.flush();
outputStream.close();
file.delete();
It’s showing me encoding iso-8859-1 (by using response.getCharacterEncoding(); function), is that could be the issue ? Because English is going perfectly in Excel file, only Multi-Language (Japanese) is appearing wrong
Do not close the
outputStreamof the response. Furthermore use a BufferedInputStream instead of a DataInputStream which is more for objects.The test on
in != nullis not necessary. The bbuf dimension might be larger, say 4096.