Grails 2.4.4 如何导出 excel 文件?

Grails 2.4.4 How do I export excel file?

我看过一些插件但没有成功。 我也尝试了 Export Plugin 1.6,但视图无法识别 r:.. 和 export:.. 标签。 通过单击按钮将数据行从 postgresql 数据库导出到 excel 文件的最佳方法是什么? 谢谢。

您是否直接使用 apache poi 进行了尝试?

来自网站:

The Apache POI Project's mission is to create and maintain Java APIs for manipulating various file formats based upon the Office Open XML standards (OOXML) and Microsoft's OLE 2 Compound Document format (OLE2). In short, you can read and write MS Excel files using Java. In addition, you can read and write MS Word and MS PowerPoint files using Java. Apache POI is your Java Excel solution (for Excel 97-2008). We have a complete API for porting other OOXML and OLE2 formats and welcome others to participate.

编辑: 这是一个教程:Read / Write Excel file in Java using Apache POI 和一个 quick guide

编辑2: 我刚找到另一个 link using Grails that could help you. The example use another library: jexcelapi

您可以创建一个呈现 .csv 文件的 gsp,并在控制器中将响应的 content-type 设置为 application/vnd.ms-excel

这是最简单的方法,但您将无法控制单元格的格式。

A​​pache POI - 如 Abincepto 所述 - 是另一种更复杂的解决方案,但可以让您完全控制生成的 excel 文件

导出插件依赖于资源插件。您可以添加资源插件并重试。我使用资源 1.2.8。您还需要将其添加到您的依赖项中:

dependencies {
    ............
    // Needed for the export plugin?
    compile 'commons-beanutils:commons-beanutils:1.8.3'

plugins {
    ............
    runtime ":resources:1.2.8"