Java POI Excel creating new column and new rows

后端 未结 5 931
慢半拍i
慢半拍i 2021-01-16 05:09

Ok so Im iterating over a list and instead of inserting values into cells horizontally, im putting the values in the cells vertically.

It works fine for the first ti

5条回答
  •  醉酒成梦
    2021-01-16 05:55

    On each iteration of your loop, you're recreating the rows at index 0 & 1. When you re-create these rows, you're going to blow away all of your already existing data.

    Try something like this:

    int k = 1;
    Row myRow1 = sheet.createRow(0); //first row of the document
    Row myRow2 = sheet.createRow(1);
    for (List dataList: someList) {
      myRow1.createCell(k).setCellValue (dataList.getVal())); 
      myRow2.createCell(k).setCellValue (dataList.getSecVal())); 
      k++;
    }
    

提交回复
热议问题