简体   繁体   English

使用JXL一次将多个数据插入Excel工作表

[英]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. 我有一种情况,我必须在Excel工作表中插入多行数据。 I am using JXL API for this purpose. 我正在为此目的使用JXL API。 However the problem is that, only the last set of data in the loop is being written in to the Excel sheet. 但是,问题在于,只有循环中的最后一组数据才被写入Excel工作表。 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. 在这里,wcf1指的是我在另一种方法中定义的WritableCellFormat。 In this sheet, I have inserted some information till row number 11 and now I need to insert multiple data after that. 在此工作表中,我插入了一些信息,直到第11行为止,现在我需要在此之后插入多个数据。 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. 我不确定ws.getRows()是否可以正常工作。 Have you printed out the value of rc? 您是否已打印出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  |

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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