使用Apache POI Excel写入特定单元格位置

now*_*ter 4 java excel formatting apache-poi

如果我有一个未排序的参数'x,y,z'列表,是否有一种直接的方法将它们写入使用POI创建的Excel文档中的特定单元格,就好像前两个参数是X和Y坐标?

例如,我有以下行:

10,4,100
Run Code Online (Sandbox Code Playgroud)

是否可以在第10行,第4列的单元格中写入值"100"?

查看文档,将值迭代到下一行看起来很简单,但我看不到创建固定数量的行和列以及将特定值写入特定单元格的任何方法.

任何建议或意见将不胜感激,谢谢!

Gag*_*arr 12

当然,这很简单,只需记住POI为0而不是基于寻址的1.假设你要写第10行,第4列,你会做类似的事情

Row r = sheet.getRow(9); // 10-1
if (r == null) {
   // First cell in the row, create
   r = sheet.createRow(9);
}

Cell c = r.getCell(3); // 4-1
if (c == null) {
    // New cell
    c = r.createCell(3, Cell.CELL_TYPE_NUMERIC);
}
c.setCellValue(100);
Run Code Online (Sandbox Code Playgroud)