Results 1 to 2 of 2

Thread: Export to Excel error

  1. #1
    Join Date
    Sep 2010
    Posts
    1

    Default Export to Excel error

    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="[empIdarams?.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);
    }else{
    //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()]
    }

  2. #2
    Join Date
    Jun 2010
    Location
    London
    Posts
    304

    Default

    What happens when you try to export as Excel?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •