写使用Apache POI Excel中的一个特定的单元格位置 [英] Writing to a particular cell location using Apache POI Excel

查看:1117
本文介绍了写使用Apache POI Excel中的一个特定的单元格位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有那不排序参数'X,Y,Z'的名单,有没有将它们写入特定的细胞POI创建一个Excel文档在一个简单的方法,就好像前两个参数在X和Y坐标?

If I've got an list of parameters 'x,y,z' that aren't sorted, is there a straightforward way to write them to particular cells in an excel document created with POI, as though the first two parameters are X and Y coordinates?

例如,我有这样的行:

10,4,100

是否有可能在第10行进行写入单元格中的数值'100',第4列?

Is it possible to write the value '100' in the cell at the 10th row, 4th column?

综观文档,它看起来直截了当地迭代值到下一行,但我不能看到创建的行和列的固定数量和写入特定值只有某些细胞的任何方式。

Looking at the documentation, it looks straightforward to iterate values into the next row, but I can't see any way of creating a fixed number of rows and columns and writing particular values to only certain cells.

任何意见或建议将是AP preciated,谢谢!

Any advice or suggestions would be appreciated, thanks!

推荐答案

当然,这是很容易的,只记得POI是基于0而不是1基于解决。假设你要写入第10行,第4列,你会做这样的事情。

Sure, it's very easy, just remember that POI is 0 based not 1 based in addressing. Assuming you want to write to the 10th row, 4th column, you'd do something like

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);

这篇关于写使用Apache POI Excel中的一个特定的单元格位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆