Grails:如何将我的列表设为 MS Excel 文件?
gsp 分为两部分,顶部部分就像一个搜索过滤器,底部部分是 Grails 提供的常规列表
。我的 list.gsp 中有一个模板 _list.gsp。我想创建一个按钮,使 _list.gsp 模板成为 MS Excel 文件。
但我只想将模板放在 Excel 文件中。不是页面的其余部分
我怎样才能以最简单直接的方式做到这一点?谢谢你!
gsp is divided into two, the top part is like a search filter, and the bottom part is the regular list that is provided by Grails
I have a template _list.gsp in my list.gsp. And I wanna create a button to make that _list.gsp template a MS Excel file.
But I want only the template to be on the Excel file. Not the rest of the page
How can I do this in the simplest and direct way possible?? Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您想将列表导出为 Excel 格式,您还可以查看导出插件
http://www .grails.org/plugin/export
you can also take a look at the export plugin if you want to export the list to excel format
http://www.grails.org/plugin/export
在索引方法中尝试这个相当肮脏的技巧:
说明:这个技巧是重命名为 *.xls 的 HTML 页面可以被办公软件套件读取。您所做的就是告诉浏览器下载具有该名称的文件,而不是导航到常规 HTML 文件。如果您想在按钮中使用它,您应该像处理任何 HTML 生成页面一样继续,然后将此标头添加到响应中。
response
对于 Grails 控制器中的操作来说是全局的。Try this quite dirty trick in your index method:
Explanation: the trick is that an HTML page renamed as *.xls can be read by office software suites. What you're doing is telling the browser to download a file with that name, instead of navigating to a regular HTML file. If you want to use this in a button, you should proceed as with any HTML generating page, and then add this header to the response.
response
is global to actions in Grails controllers.您所需要做的就是将搜索数据发送到您的控制器,在控制器中您可以按照 mschonaker 的解释发送内容,这是我所做的一个示例
All you need is to send search data to your controller, in the controller you can send content as explained by mschonaker, this is an example of what I did
看一下 Excel 导出插件。仅支持 .xlsx 格式下载。用最简单的编码导出 Excel。
由于与渲染插件发生冲突,我从导出插件切换到此插件。
https://grails.org/plugin/excel-export
Take a look at the Excel-export plugin. This has support for downloading only in .xlsx format. Exports an excel with the simplest coding.
I switched to this plugin from export plugin since had a clash with rendering plugin.
https://grails.org/plugin/excel-export