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

查看:49
本文介绍了使用 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 行第 4 列的单元格中写入值100"?

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.

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

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天全站免登陆