how to create dynamic rows of records for creating xls file using list
<p>Here after fetching records from database I have added data in some list and I have set some session variables for them so that I can access in another method by using get(key) method of session which I am successful to do so .Now what I want is I want to create dynamic records by setting this list value in row but I am unable to do so.It creates file but there is no record displayed .Below is my code:  </p>

<pre><code>package com.ca.actions;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.struts2.dispatcher.SessionMap;
import org.apache.struts2.interceptor.SessionAware;

import com.ca.database.Database;
import com.ca.pojo.Event;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;

public class DataForGeneralReportsAction extends ActionSupport implements
        Preparable, SessionAware {
    private List&lt;String&gt; eventsGeneral = new ArrayList&lt;String&gt;();
    private List&lt;String&gt; companiesGeneral = new ArrayList&lt;String&gt;();
    private SessionMap&lt;String, Object&gt; sessionMapGeneral;
    List&lt;String&gt; eventIdList = new ArrayList&lt;String&gt;();
    List&lt;String&gt; eventNameList = new ArrayList&lt;String&gt;();
    List&lt;String&gt; eventVenueList = new ArrayList&lt;String&gt;();
    List&lt;String&gt; eventTimeList = new ArrayList&lt;String&gt;();
    List&lt;String&gt; companyNameList = new ArrayList&lt;String&gt;();
    List&lt;String&gt; totalAmountList = new ArrayList&lt;String&gt;();
    List&lt;String&gt; receivedAmountList = new ArrayList&lt;String&gt;();
    List&lt;String&gt; balanceAmountList = new ArrayList&lt;String&gt;();
    List&lt;String&gt; eventTdsList = new ArrayList&lt;String&gt;();
    List&lt;String&gt; paymentDateList = new ArrayList&lt;String&gt;();
    List&lt;String&gt; chequeDdList = new ArrayList&lt;String&gt;();

    private String eventGeneral = null;
    private String companyGeneral = null;
    List&lt;Event&gt; dataForGeneralReports;

    public List&lt;String&gt; getEventIdList() {
        return eventIdList;
    }

    public void setEventIdList(List&lt;String&gt; eventIdList) {
        this.eventIdList = eventIdList;
    }

    public List&lt;String&gt; getEventNameList() {
        return eventNameList;
    }

    public void setEventNameList(List&lt;String&gt; eventNameList) {
        this.eventNameList = eventNameList;
    }

    public List&lt;String&gt; getEventVenueList() {
        return eventVenueList;
    }

    public void setEventVenueList(List&lt;String&gt; eventVenueList) {
        this.eventVenueList = eventVenueList;
    }

    public List&lt;String&gt; getEventTimeList() {
        return eventTimeList;
    }

    public void setEventTimeList(List&lt;String&gt; eventTimeList) {
        this.eventTimeList = eventTimeList;
    }

    public List&lt;String&gt; getCompanyNameList() {
        return companyNameList;
    }

    public void setCompanyNameList(List&lt;String&gt; companyNameList) {
        this.companyNameList = companyNameList;
    }

    public List&lt;String&gt; getTotalAmountList() {
        return totalAmountList;
    }

    public void setTotalAmountList(List&lt;String&gt; totalAmountList) {
        this.totalAmountList = totalAmountList;
    }

    public List&lt;String&gt; getReceivedAmountList() {
        return receivedAmountList;
    }

    public void setReceivedAmountList(List&lt;String&gt; receivedAmountList) {
        this.receivedAmountList = receivedAmountList;
    }

    public List&lt;String&gt; getBalanceAmountList() {
        return balanceAmountList;
    }

    public void setBalanceAmountList(List&lt;String&gt; balanceAmountList) {
        this.balanceAmountList = balanceAmountList;
    }

    public List&lt;String&gt; getEventTdsList() {
        return eventTdsList;
    }

    public void setEventTdsList(List&lt;String&gt; eventTdsList) {
        this.eventTdsList = eventTdsList;
    }

    public List&lt;String&gt; getPaymentDateList() {
        return paymentDateList;
    }

    public void setPaymentDateList(List&lt;String&gt; paymentDateList) {
        this.paymentDateList = paymentDateList;
    }

    public List&lt;String&gt; getChequeDdList() {
        return chequeDdList;
    }

    public void setChequeDdList(List&lt;String&gt; chequeDdList) {
        this.chequeDdList = chequeDdList;
    }

    public SessionMap&lt;String, Object&gt; getSessionMapGeneral() {
        return sessionMapGeneral;
    }

    public void setSessionMapGeneral(
            SessionMap&lt;String, Object&gt; sessionMapGeneral) {
        this.sessionMapGeneral = sessionMapGeneral;
    }

    public String getEventGeneral() {
        return eventGeneral;
    }

    public void setEventGeneral(String eventGeneral) {
        this.eventGeneral = eventGeneral;
    }

    public String getCompanyGeneral() {
        return companyGeneral;
    }

    public void setCompanyGeneral(String companyGeneral) {
        this.companyGeneral = companyGeneral;
    }

    public List&lt;Event&gt; getDataForGeneralReports() {
        return dataForGeneralReports;
    }

    public void setDataForGeneralReports(List&lt;Event&gt; dataForGeneralReports) {
        this.dataForGeneralReports = dataForGeneralReports;
    }

    public List&lt;String&gt; getEventsGeneral() {
        return eventsGeneral;
    }

    public void setEventsGeneral(List&lt;String&gt; eventsGeneral) {
        this.eventsGeneral = eventsGeneral;
    }

    public List&lt;String&gt; getCompaniesGeneral() {
        return companiesGeneral;
    }

    public void setCompaniesGeneral(List&lt;String&gt; companiesGeneral) {
        this.companiesGeneral = companiesGeneral;
    }

    public DataForGeneralReportsAction() {
        // TODO Auto-generated constructor stub
    }

    @Override
    public void prepare() throws Exception {
        // TODO Auto-generated method stub
        Connection con = null;
        try {
            con = new Database().Get_Connection();

            // load companies
            PreparedStatement ps = con
                    .prepareStatement("SELECT DISTINCT company_name FROM event");
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                companiesGeneral.add(rs.getString("company_name"));
            }

            // load events
            ps = con.prepareStatement("SELECT DISTINCT event_name FROM event");
            rs = ps.executeQuery();
            while (rs.next()) {
                eventsGeneral.add(rs.getString("event_name"));
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            con.close();
        }

    }

    @Override
    public String execute() throws Exception {

        Connection con = null;
        try {
            con = new Database().Get_Connection();

            // load the table. The first time the table is loaded completely
            String sql = "SELECT EVENT_ID, EVENT_NAME, COMPANY_NAME,EVENT_VENUE,TOTAL_AMOUNT,RECEIVED_AMOUNT,EVENT_TDS,BALANCE_AMOUNT,CHEQUE_DD_NO,"
                    + "date_format(PAYMENT_DATE,'%d/%m/%Y') as dateAsPayment,EVENT_TIME "
                    + "FROM event";
            String where = "";

            // if instead this action has been called from the JSP page,
            // the result is filtered on event and company:
            if (eventGeneral != null &amp;&amp; companyGeneral != null) {
                where = " WHERE event_name = ? AND company_name = ?";
            }

            // load companies
            PreparedStatement ps = con.prepareStatement(sql + where);
            if (where.length() &gt; 0) {
                ps.setString(1, eventGeneral);
                ps.setString(2, companyGeneral);
            }
            dataForGeneralReports = new ArrayList&lt;Event&gt;();
            ResultSet rs = ps.executeQuery();
            int i, j = 0;
            while (rs.next()) {

                dataForGeneralReports.add(new Event(rs.getString("EVENT_ID"),
                        rs.getString("EVENT_NAME"), rs
                                .getString("COMPANY_NAME"), rs
                                .getString("EVENT_VENUE"), rs
                                .getString("EVENT_TIME"), rs
                                .getString("TOTAL_AMOUNT"), rs
                                .getString("RECEIVED_AMOUNT"), rs
                                .getString("CHEQUE_DD_NO"), rs
                                .getString("dateAsPayment"), rs
                                .getString("BALANCE_AMOUNT"), rs
                                .getString("EVENT_TDS")));

                eventIdList.add(rs.getString("EVENT_ID"));
                eventNameList.add(rs.getString("EVENT_NAME"));
                companyNameList.add(rs.getString("COMPANY_NAME"));
                eventVenueList.add(rs.getString("EVENT_VENUE"));
                eventTimeList.add(rs.getString("EVENT_TIME"));
                totalAmountList.add(rs.getString("TOTAL_AMOUNT"));
                receivedAmountList.add(rs.getString("RECEIVED_AMOUNT"));
                chequeDdList.add(rs.getString("CHEQUE_DD_NO"));
                paymentDateList.add(rs.getString("dateAsPayment"));
                eventTdsList.add(rs.getString("EVENT_TDS"));
                balanceAmountList.add(rs.getString("BALANCE_AMOUNT"));

            }
            sessionMapGeneral.put("eventIdPdf", eventIdList);
            sessionMapGeneral.put("eventNamePdf", eventNameList);
            sessionMapGeneral.put("companyNamePdf", companyNameList);
            sessionMapGeneral.put("eventVenuePdf", eventVenueList);
            sessionMapGeneral.put("eventTimePdf", eventTimeList);
            sessionMapGeneral.put("totalAmountPdf", totalAmountList);
            sessionMapGeneral.put("receivedAmountPdf", receivedAmountList);
            sessionMapGeneral.put("chequeDdPdf", chequeDdList);
            sessionMapGeneral.put("paymentDatePdf", paymentDateList);
            sessionMapGeneral.put("eventTdsPdf", eventTdsList);
            sessionMapGeneral.put("balanceAmountPdf", balanceAmountList);

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            con.close();
        }

        return SUCCESS;

    }

    public String generatePdfGeneral() throws Exception {

        System.out.println(sessionMapGeneral.get("eventIdPdf"));
        Document document = new Document(PageSize.A4_LANDSCAPE, 50, 50, 50, 50);
        float[] columnWidths = { 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 };

        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream("D:\\GeneralReports.pdf"));
        PdfPTable table = new PdfPTable(11);
        table.setSpacingBefore(25);
        table.setWidthPercentage(100);
        table.setSpacingAfter(25);
        table.setWidths(columnWidths);
        PdfPCell c1 = new PdfPCell(new Phrase("Event ID "));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);

        c1 = new PdfPCell(new Phrase("Event Name "));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);

        c1 = new PdfPCell(new Phrase("Event Time"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);

        c1 = new PdfPCell(new Phrase("Event Venue"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase("Company Name"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase("Total Amount"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase("Received Amount"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase("Cheque/DD Number"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase("Payment Date"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase("Event TDS"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase("Balance Amount"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);

        table.setHeaderRows(1);
        PdfPCell cell = new PdfPCell();
        List&lt;String&gt; list = (List&lt;String&gt;) sessionMapGeneral.get("eventIdPdf");
        for (String item : list) {
            cell.addElement(new Paragraph(item));
        }
        PdfPCell cell1 = new PdfPCell();
        List&lt;String&gt; list1 = (List&lt;String&gt;) sessionMapGeneral
                .get("eventNamePdf");
        for (String item : list1) {
            cell1.addElement(new Paragraph(item));
        }
        table.addCell(cell1);
        PdfPCell cell2 = new PdfPCell();
        List&lt;String&gt; list2 = (List&lt;String&gt;) sessionMapGeneral
                .get("eventTimePdf");
        for (String item : list2) {
            cell2.addElement(new Paragraph(item));
        }
        table.addCell(cell2);
        PdfPCell cell3 = new PdfPCell();
        List&lt;String&gt; list3 = (List&lt;String&gt;) sessionMapGeneral
                .get("eventVenuePdf");
        for (String item : list1) {
            cell3.addElement(new Paragraph(item));
        }

        table.addCell(cell3);
        PdfPCell cell4 = new PdfPCell();
        List&lt;String&gt; list4 = (List&lt;String&gt;) sessionMapGeneral.get("eventIdPdf");
        for (String item : list4) {
            cell4.addElement(new Paragraph(item));
        }

        table.addCell(cell4);
        PdfPCell cell5 = new PdfPCell();
        List&lt;String&gt; list5 = (List&lt;String&gt;) sessionMapGeneral
                .get("companyNamePdf");
        for (String item : list5) {
            cell5.addElement(new Paragraph(item));
        }

        table.addCell(cell5);
        PdfPCell cell6 = new PdfPCell();
        List&lt;String&gt; list6 = (List&lt;String&gt;) sessionMapGeneral
                .get("totalAmountPdf");
        for (String item : list6) {
            cell6.addElement(new Paragraph(item));
        }

        table.addCell(cell6);
        PdfPCell cell7 = new PdfPCell();
        List&lt;String&gt; list7 = (List&lt;String&gt;) sessionMapGeneral
                .get("receivedAmountPdf");
        for (String item : list7) {
            cell7.addElement(new Paragraph(item));
        }

        table.addCell(cell7);
        PdfPCell cell8 = new PdfPCell();
        List&lt;String&gt; list8 = (List&lt;String&gt;) sessionMapGeneral
                .get("chequeDdPdf");
        for (String item : list8) {
            cell8.addElement(new Paragraph(item));
        }

        table.addCell(cell8);
        PdfPCell cell9 = new PdfPCell();
        List&lt;String&gt; list9 = (List&lt;String&gt;) sessionMapGeneral
                .get("paymentDatePdf");
        for (String item : list9) {
            cell9.addElement(new Paragraph(item));
        }

        table.addCell(cell9);
        PdfPCell cell10 = new PdfPCell();
        List&lt;String&gt; list10 = (List&lt;String&gt;) sessionMapGeneral
                .get("eventTdsPdf");
        for (String item : list10) {
            cell10.addElement(new Paragraph(item));
        }

        table.addCell(cell10);
        PdfPCell cell11 = new PdfPCell();
        List&lt;String&gt; list11 = (List&lt;String&gt;) sessionMapGeneral
                .get("balanceAmountPdf");
        for (String item : list11) {
            cell11.addElement(new Paragraph(item));
        }

        table.addCell(cell11);

        document.open();
        document.add(table);
        document.close();
        return "success";

    }

    public String generateGeneralXls() throws Exception {
        try {
            HSSFWorkbook workbook = new HSSFWorkbook();
            HSSFSheet sheet = workbook.createSheet("FirstSheet");
            HSSFRow rowhead = sheet.createRow((short) 0);
            rowhead.createCell(0).setCellValue("Event ID");
            rowhead.createCell(1).setCellValue("Event Name");
            rowhead.createCell(2).setCellValue("Event Time");
            rowhead.createCell(3).setCellValue("Event Venue");
            rowhead.createCell(4).setCellValue("Company Name");
            rowhead.createCell(5).setCellValue("Total Amount");
            rowhead.createCell(6).setCellValue("Received Amount");
            rowhead.createCell(7).setCellValue("Payment Date");
            rowhead.createCell(8).setCellValue("Cheque/DD No.");
            rowhead.createCell(9).setCellValue("Event TDS");
            rowhead.createCell(10).setCellValue("Balance Amount");
            FileOutputStream fileOut;

            fileOut = new FileOutputStream("D:\\Samplmgjkm.xls");

            // HSSFRow row1 = sheet.createRow((short) 1);
            System.out.println(sessionMapGeneral.size());
            for (int i = 1; i &lt;= sessionMapGeneral.size(); i++) {
                HSSFRow row1 = sheet.createRow((short) i);
                row1.createCell(i-1).setCellValue(
                        sessionMapGeneral.get("eventIdPdf").toString());

                row1.createCell(i).setCellValue(
                        sessionMapGeneral.get("eventNamePdf").toString());

            }


            /*
             * row1.createCell(1).setCellValue(
             * sessionMapGeneral.get("eventNamePdf").toString());
             * row1.createCell(1).setCellValue(
             * sessionMapGeneral.get("eventNamePdf").toString());
             * row1.createCell(1).setCellValue(
             * sessionMapGeneral.get("eventNamePdf").toString());
             * row1.createCell(1).setCellValue(
             * sessionMapGeneral.get("eventNamePdf").toString());
             * row1.createCell(1).setCellValue(
             * sessionMapGeneral.get("eventNamePdf").toString());
             * row1.createCell(1).setCellValue(
             * sessionMapGeneral.get("eventNamePdf").toString());
             * row1.createCell(1).setCellValue(
             * sessionMapGeneral.get("eventNamePdf").toString());
             * row1.createCell(1).setCellValue(
             * sessionMapGeneral.get("eventNamePdf").toString());
             * row1.createCell(1).setCellValue(
             * sessionMapGeneral.get("eventNamePdf").toString());
             */

            workbook.write(fileOut);
            fileOut.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return "success";
    }

    @Override
    public void setSession(Map&lt;String, Object&gt; map) {
        // TODO Auto-generated method stub
        sessionMapGeneral = (SessionMap) map;
    }

}
</code></pre>

<p>I have edited my code where I get result in string but all records are displayed in single cell. I want each record in new cell.I have attached image of how it looks.  <a href="https://i.stack.imgur.com/ZLlvT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZLlvT.png" alt="enter image description here"></a>
No error is displayed. Please help me to solve my problem. </p>