Java - Apache POI - Trouble filling rows and cells with loops (Excel)

前端 未结 1 584
别那么骄傲
别那么骄傲 2021-01-23 02:13

There\'s a HashMap:

HashMap> matrix = new HashMap>();

I want to fil

相关标签:
1条回答
  • 2021-01-23 02:39

    In the inner for loop, keyCell never changes value. This means you are writing to the same cell value each time. (I'm surprised the code works at all due to this problem.)

     for (String s : e.getValue()) { 
            if ((row - 5) < (e.getValue().size())) {
                valueRow = worksheet.createRow(row += 1);
                valueRow.createCell(keyCell).setCellValue(s);
                } else {
                    valueRow.createCell(keyCell).setCellValue(s);
                }
            }
    

    So first, I'd fix this problems and use keyCell++. If that doesn't work, add debugging showing the row and keyCell number each time you call createCell(). This will show if the indexes are following the correct pattern or not. You want the pattern:

    • 0, 0
    • 0, 1
    • ....
    • 0, 4
    • 1, 0
    • etc
    0 讨论(0)
提交回复
热议问题