Tuesday, 21 November 2017

Exporting data into csv format

Use Open CSV to export the data.
Here I have given download option for the whole table.
I am getting the whole table data as a list.And making csv values and storing in csv file.
public void exportEvent(ActionRequest actionRequest,ActionResponse actionResponse) throws SystemException, IOException{
       List<stuadmissi
on> admissions = stuadmissionLocalServiceUtil.getstuadmissions(-1, -1);

             
    CSVWriter writer = new CSVWriter(new FileWriter("
/home/filename.csv"), '\t');
    for (stuadmission student : admissions){
            String str = Integer.toStrin
g(student.getAdmissionno());
           String str2 = str + ","+ student.getBatc
h();
           

            String[] strings = str2.split(",")
;
            writer.writeNex
t(strings);
                   writer.close();
}
               
        }

TEST

I am Java Developer. I have 6 year Experiance in this field and like to post in blogging. So keep sharing and like my post

0 comments:

Post a Comment

 

Copyright @ 2017 Liferay Article.