Grails simple export to CSV

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Grails simple export to CSV

bbface
This post has NOT been accepted by the mailing list yet.
My code below only shows the last two records on m database. I want all records to be exported to csv format from my database. Any help guys?Thanks......
 

def cif() {
    def customers = Customer.list()

    response.setHeader("Content-disposition", "attachment; filename=\"Customer Information.csv\"")
    response.contentType = "text/csv"
       
        def outs = response.outputStream

    outs << "Customer Name, Customer ID, Customer Type, Branch, Birth Date, Gender, Civil Status, Birth Place, Taxable?," +
            "Credit Limit, Resident Type, Risk Type, Firm Size, Nationality, Dosri Code, SSS No., GSIS No., TIN No., Passport No.," +
            "Address Type, Address, Postal Code, Phone 1, Phone 2, Fax 1, Fax2, Contact Type, Contact\n"
       
        customers.each() { customer ->
        customer.contacts.each() { contact ->
        customer.addresses.each() { address ->
        outs << "\"" +
                customer.displayName + "\",\"" +
                        customer.customerId + "\",\"" +
                customer.type.description + "\",\"" +
                            customer.branch.name + "\",\"" +
                            customer.birthDate + "\",\"" +
                            customer.gender.description + "\",\"" +
                            customer.civilStatus.itemValue + "\",\"" +
                            customer.birthPlace + "\",\"" +
                            customer.isTaxable + "\",\"" +
                            customer.creditLimit + "\",\"" +
                        customer.customerCode1.description + "\",\"" +
                        customer.customerCode2.description + "\",\"" +
                        customer.customerCode3.description + "\",\"" +
                        customer.nationality.itemValue + "\",\"" +
                        customer.dosriCode.description + "\",\"" +
                        customer.sssNo + "\",\"" +
                        customer.gisNo + "\",\"" +
                        customer.tinNo + "\",\"" +
                        customer.passportNo + "\",\"" +
                            address.type.description + "\",\"" +
                            address.address1 + " " + address.address2 + " " + address.address3 + "\",\"" +
                        address.postalCode + "\",\"" +
                        address.phone1 + "\",\"" +
                        address.phone2 + "\",\"" +
                        address.phone3 + "\",\"" +
                        address.phone4 + "\",\"" +
                    contact.type.itemValue + "\",\"" +
                    contact.contactValue + "\""
            outs << "\n"
        }
            }
        }
    outs.flush()
    outs.close()
    }