JSP生成Excel电子表格(XLS)下载 [英] JSP generating Excel spreadsheet (XLS) to download
问题描述
我正在用 JSP 开发这个应用程序,我希望从数据库中以 XLS(MS Excel 格式)导出一些数据.
I have this application I'm developing in JSP and I wish to export some data from the database in XLS (MS Excel format).
在tomcat下能不能像普通的Java应用一样写一个文件,然后生成这个文件的链接?或者我需要使用特定的 API 吗?
Is it possible under tomcat to just write a file as if it was a normal Java application, and then generate a link to this file? Or do I need to use a specific API for it?
这样做会不会有权限问题?
Will I have permission problems when doing this?
推荐答案
虽然您可以使用完整的库,例如 JExcelAPI,Excel 也会读取 CSV 和纯 HTML 表格,前提是您将响应 MIME 类型设置为application/vnd.ms-excel"之类的内容.
While you can use a full fledged library like JExcelAPI, Excel will also read CSV and plain HTML tables provided you set the response MIME Type to something like "application/vnd.ms-excel".
根据电子表格的复杂程度,CSV 或 HTML 可以为您完成这项工作,而无需第 3 方库.
Depending on how complex the spreadsheet needs to be, CSV or HTML can do the job for you without a 3rd party library.
这篇关于JSP生成Excel电子表格(XLS)下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!