简体   繁体   中英

Inserting multiple data into an excel sheet at a time using JXL

I have a scenario where I have to insert multiple lines of data into an Excel Sheet. I am using JXL API for this purpose. However the problem is that, only the last set of data in the loop is being written in to the Excel sheet. Can someone please help me in achieving it or provide a code snippet or an example?

Thanks a lot.



    int ccount = ws.getColumns();
    int rc = ws.getRows();

    int rnum = rc - 10;

    for(int i=1;i(lesser than symbol)3; i++){
        rnum++;
        String srnum = String.valueOf(rnum);
        wsheet.addCell(new jxl.write.Label(1, rc, srnum, wcf1));
        wsheet.addCell(new jxl.write.Label(2, rc, "b", wcf1));
        wsheet.addCell(new jxl.write.Label(3, rc, "c", wcf1));
        wsheet.addCell(new jxl.write.Label(4, rc, "d", wcf1));
        System.out.println("executing...........");
        wsheet.addCell(new jxl.write.Label(5, rc, "e", wcf1));
        wsheet.addCell(new jxl.write.Label(6, rc, "f", wcf1));  

        wb.write();

        rc++;   
    }

Here, wcf1 refers to the WritableCellFormat which I have defined in another method. In this sheet, I have inserted some information till row number 11 and now I need to insert multiple data after that. So I used for loop. But its not giving the result properly. Please help me out with this.

I can't ask for more detail directly (low rep) on the question. Could you write the output that you obtain?

I'm not sure that ws.getRows() would work correctly. Have you printed out the value of rc?

Following the code you would obtain something like

   |A   |B  |C  |D  |E  |F  |
...|....|...|...|...|...|...|
x  |bla |bla|bla|bla|bla|bla| 
x+1|x-10|b  |c  |d  |e  |f  |
x+2|x-9 |b  |c  |d  |e  |f  |

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM