我想使用 Apache POI 将字符串插入到 Excel 中的单元格矩阵中,代码如下:
for (int j=0;j<13;j++){
for(int i=6;i<30;i++)
{
XSSFRow row=sheet6.createRow(i);
cell0=row.createCell(j);
cell0.setCellValue("SampleRules_CI_01");
}
}
执行程序后,我正确填充了 j=12 列,但其他列(从 0 到 11)仍然为空
最佳答案
当您调用 createRow
method 时,每次返回到相同的 i
值时,您都会替换该行。 。这具有删除该行上已经存在的所有内容的效果,并且只有最后一列不会以这种方式被删除。
首先,在您的 i
for
循环中,调用 the getRow
method查看它是否已经存在。如果它返回null
,则该行尚不存在,然后您可以调用createRow
。
XSSFRow row = sheet6.getRow(i);
if (row == null)
{
row = sheet6.createRow(i);
}
关于java - Apache POI : Why data is not properly inserted?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23499079/