Export Plugin


New member
Below is my code in the controller.

I have a page that takes empId and empDt as an input. based on that the query is run and results are displayed on the screen. I want these tabular results to be exported to an excel. For that I installed the export plugin.
and put <export:formats formats="['excel']" , params="[empId:params?.empId, empName: params?.empName, empDt: params?.empDt]" in my gsp.

However, I m not able to export to excel.

I think I am doing something wrong here.
Please advice

def list = {

def empId=params.empId
def empDt=params.empDt

String date = null

SimpleDateFormat sdfSource = new SimpleDateFormat("dd-MMM-yyyy")
if(empDt instanceof Date) {
date = sdfSource.format(empDt);
//to handle the excel case
//convert to 29-jul-2010 format then parse

date = '29-Jul-2010'
def employeeInstanceList = new ArrayList<Employee>()

Sql sql = new Sql(dataSource)

def results = sql.eachRow ("select employee_id from employee where empDt = ('" + date + "')")

def employe = new Employee()
employee.setEmpId it.emp_id

employeeInstanceList.add employee


if(params?.format && params.format != "html"){

//response.contentType = ConfigurationHolder.config.grails.mime.types[params.format]
//response.setHeader("Content-disposition", "attachment; filename=Employee.${params.format}")
exportService.export(params.format, response.outputStream, employeeInstanceList.list(params), [:], [:])

[employeeList: employeeInstanceList, employeeInstanceTotal: Employee.count()]