Grails:如何将 Grails 列表导出到 Microsoft Excel?
我有一个包含信息的列表,我想将其导出到 Excel。 我该怎么做?
“导出插件”好用吗?我想我不久前看到过一个将文件导出到 Excel 的功能,但现在找不到了。
I have a list with information and I want to export it to Excel.
How do I do it?
Is the "Export Plugin" any good? I think I saw one a while ago to export files to Excel but I can't find it anymore.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想要实际 Excel 文档(而不仅仅是 CSV 文件),我使用了 JExcel 库 取得了一些成功。这是一个快速编写的示例,可能需要一点 Groovy 化。
编辑:更新了我的示例以在控制器中执行此操作。从架构上来说,将其分开一点会更有意义,但这只是为了举例。
使用此库可以让您执行格式化、使用多个工作表等操作。
If you want actual Excel documents (rather than just CSV files), I've used the JExcel library with some success. Here's a quickly-written example that could probably be Groovy-fied a little bit.
Edit: Updated my example to do this in a controller. Architecturally it would make more sense to split this up a bit, but this is just for example's sake.
Using this library lets you do things like formatting, using multiple worksheets, etc.
Grails 导出插件 的功能非常出色:将域对象(或查询结果)列表导出到单个工作表(或页面),采用多种格式 - 包括 Excel。命名列、指示宽度、动态转换数据的能力非常棒——我已经在几个项目中使用过它。
然而,当我想要除简单列表之外的其他内容时,我也按照 Rob 的建议使用了 JExcel。适合工作的工具等等。 :-)
The Grails Export Plugin is excellent at what it does: export a list of domain objects (or query results) onto a single sheet (or page), in a number of formats -- including Excel. The ability to name columns, indicate width, transform your data on-the-fly is great -- I've used it in several projects.
However, I've also used JExcel as suggested by Rob, when I wanted something other than a simple list. The right tool for the job, and all that. :-)
我已经使用 Grails 的 JXL 插件有一段时间了,它运行得很好。
它甚至可以选择将 Excel 文件写入响应,以便用户可以使用我的 REST 服务直接下载文件。
链接是: http://grails.org/plugin/jxl
下面是一个示例,说明它是多么简单是创建工作簿:
您可以在此处找到更多信息。
I've been using the JXL plugin for Grails for a while and it works perfectly.
It even has an option to write the Excel file to the response, so that the user can directly download the file using my REST service.
The link is: http://grails.org/plugin/jxl
Here is an example of how simple it is to create workbooks:
You can find more information here.