如何在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 
{ 

} 
+0

jxl api是否支持谷歌应用程序引擎或不? – swan

我已经使用像这样的代码在过去导出CSV:

response.setHeader("Cache-Control", ""); 
response.setHeader("Pragma", ""); 
response.setHeader("Content-Disposition", "attachment; filename=foo.csv"); 
response.setContentType("text/csv"); 

println语句的输出是什么?

无论如何,您都遇到了麻烦,因为据我所知,您不能在Google App引擎上使用外部库(我认为他们没有包含该特定服务)。

+0

嗨,我可以在谷歌应用程序引擎上使用jxl吗? jxl它是外部库生成excel文件... – swan

+0

是否有任何其他方式来在谷歌应用程序引擎应用程序中创建excel文件.. – swan