0

我正在尝试从涉及一些多语言(日语)内容的 JAVA 导出和 MS Excel 表。我已经尝试了几件事,但多语言(日语)内容在导出的 Excel 工作表中没有正确显示。

我正在从数据库中获取内容(我已经检查了数据库,多语言日语内容已正确保存)

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();

它向我展示了对iso-8859-1的编码(通过使用 response.getCharacterEncoding();函数),这可能是问题吗?因为英语在 Excel 文件中运行良好,所以只有多语言(日语)出现错误

4

1 回答 1

0

不要关闭outputStream响应。此外,使用 BufferedInputStream 而不是更适合对象的 DataInputStream。

in != null不需要测试。bbuf 维度可能更大,例如 4096。

于 2012-10-02T12:03:14.573 回答