0

I'm using Grails 1.3.4 with the export 0.9.5 plug in.

I have a formatter that I use that sets the date format to 'YYYY-MM-DD' when exporting to excel. But this doesn't change the data type. The date is exported to Excel as a string/general data type.

def dateFormat = { domain, value ->
    if(value instanceof Date){
         return new java.text.SimpleDateFormat("yyyy-MM-dd").format(value)
    }
    return value
}

Map formatters = [ecd:dateFormat, completed:dateFormat, dateCreated:dateFormat, approvedDate:dateFormat, dpaECD:dateFormat]
exportService.export(params.format, response.outputStream,exportList, jobService.parseColNames(columns), labels, formatters, null)

Is there a way to export data and set the datatype of a column in excel so the user doesn't have to manually set the cell/column formatting to 'Date' every time after exporting?

4

1 に答える 1

1

本当にそのプラグインを使用しますか? それは私にはうまくいきませんでした。

Grails 用の JXL プラグインをしばらく使用してきましたが、完全に動作します。

Excel ファイルを応答に書き込むオプションもあるため、ユーザーは REST サービスを使用してファイルを直接ダウンロードできます。

リンクは次のとおりです。http://grails.org/plugin/jxl

ワークブックの作成がいかに簡単かを示す例を次に示します。

new ExcelBuilder().workbook('/path/to/test.xls') {
    sheet('SheetName') {
        cell(0,0,'Current Date')
        cell(0,1,new Date())
    }
}

このcell()メソッドには、列、行、値の 3 つのパラメーターがあることに注意してください。この 3 番目のパラメーターは、数値、文字列、または日付にすることができ、完全に書式設定されます。

詳細については、こちらをご覧ください。

于 2013-09-16T19:37:14.053 に答える