user3490014
user3490014

Reputation: 47

Grails excel-export plugin

I am currently using the excel-export plugin to export a queried result list to excel. I have a question on how to format the cells prior to exporting in 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. 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.

Upvotes: 2

Views: 2070

Answers (2)

Olencha
Olencha

Reputation: 418

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
    }
}

Upvotes: 0

ShadowHunter
ShadowHunter

Reputation: 54

Its explained in the export plugins documentation

link https://github.com/TouK/excel-export/blob/master/README.md#how-to-export-my-own-types

Upvotes: 1

Related Questions