[英]Grails excel-export plugin
I am currently using the excel-export plugin to export a queried result list to excel. 我目前正在使用excel-export插件将查询的结果列表导出到excel。 I have a question on how to format the cells prior to exporting in excel.
我对在导出Excel之前如何格式化单元格有疑问。 My Code is
我的代码是
def export(){
def list = session.ObjectListKey
def headers = ['Consultant', 'Contract', 'Contract Engineer', 'Project', 'Work Category', 'Eval Begin Date', 'Eval End Date', 'Overall Average Score']
def withProperties = ['consultantName', 'contractName', 'projectManager', 'project', 'workCategory', 'evalBeginDate', 'evalEndDate', 'averageScore']
new WebXlsxExporter().with {
setResponseHeaders(response)
fillHeader(headers)
add(list, withProperties)
save(response.outputStream)
}
}
What I need to be able to do is format the begin and end date fields with mm/dd/yyyy. 我需要做的是使用mm / dd / yyyy格式化开始日期和结束日期字段。 Also the average score field is stored in the database as a varchar so when exporting to excel I would like to change this to a number so they can do calculations.
此外,平均得分字段还以varchar的形式存储在数据库中,因此在导出为excel时,我想将其更改为数字,以便他们可以进行计算。
Its explained in the export plugins documentation 在导出插件文档中对其进行了解释
link https://github.com/TouK/excel-export/blob/master/README.md#how-to-export-my-own-types 链接https://github.com/TouK/excel-export/blob/master/README.md#how-to-export-my-own-types
import pl.touk.excel.export.getters.PropertyGetter
class DateGetter extends PropertyGetter<Date, String> {
DateGetter(String propertyName) {
super(propertyName)
}
@Override
protected String format(Date value) {
return value?.format('MM/dd/yyyy') // you can do anything you like in here
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.