【发布时间】:2014-07-04 06:49:44
【问题描述】:
我正在使用 Apache POI 创建 MS Excel 文件,当我在本地主机上使用它时一切正常。但是当我在 Google App Engine 上部署项目然后尝试在 MS Excel 中打开创建的文件时,我可以注意到我所有的特殊字符都变成了问号“?”。你们有谁可以告诉我为什么它可以在 localhost 上运行但在部署后无法显示特殊字符。
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
try {
OutputStream out = null;
try
{
String dataa = req.getParameter("dataa");
String json = URLDecoder.decode(dataa, "UTF-8");
Gson gson = new Gson();
ExcelData excelData = gson.fromJson(json, ExcelData.class);
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet1 = (HSSFSheet) workbook.createSheet("myData");
// workbook creation...
ByteArrayOutputStream outByteStream = new ByteArrayOutputStream();
workbook.write(outByteStream);
byte [] outArray = outByteStream.toByteArray();
res.setContentType("application/ms-excel");
res.setContentLength(outArray.length);
res.setHeader("Expires:", "0");
res.setHeader("Content-Disposition", "attachment; filename=raport.xls");
out = res.getOutputStream();
out.write(outArray);
out.flush();
} catch (Exception e)
{
throw new ServletException("Exception in Excel Sample Servlet", e);
} finally
{
if (out != null)
out.close();
}
} catch (Exception ex) {
throw new ServletException(ex);
}
}
【问题讨论】:
-
我怀疑问题可能出在您的代码中...您没有向我们展示。
标签: java excel google-app-engine apache-poi