如何在servlet中为谷歌应用程序引擎应用程序创建excel文件?
问题描述:
我正在开发托管在谷歌应用程序引擎上的云应用程序,并在此我想通过servlet点击按钮生成excel文件。如何在servlet中为谷歌应用程序引擎应用程序创建excel文件?
我已经做到了本地机器上,但是当我部署我在App Engine应用中显示错误HTTP错误500内部服务器错误
我使用JXL的Java API生成excel文件
代码我用的是这里
try
{
//i have used following content type but didn't worked.....
//response.setContentType("application/CSV");
//response.setContentType("application/x-ms-excel");
response.setContentType("application/vnd.ms-excel");
WritableWorkbook w = Workbook.createWorkbook(response.getOutputStream());
WritableSheet s = w.createSheet("Demo", 0);
Label label = new Label(0, 2, "A label record");
s.addCell(label);
w.write();
w.close();
}
catch (Exception e)
{
response.getOutputStream().println("Exception :"+e);
}
finally
{
}
答
我已经使用像这样的代码在过去导出CSV:
response.setHeader("Cache-Control", "");
response.setHeader("Pragma", "");
response.setHeader("Content-Disposition", "attachment; filename=foo.csv");
response.setContentType("text/csv");
jxl api是否支持谷歌应用程序引擎或不? – swan