如何使用 XSSFWorkbook 将活动单元格移动到范围 apache poi 中的左上角单元格? [英] how to move the active cell to the top left cell in the range apache poi using XSSFWorkbook?

查看:40
本文介绍了如何使用 XSSFWorkbook 将活动单元格移动到范围 apache poi 中的左上角单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 Java excel 代码从 JBook 迁移到 XSSFWorkbook.我没有得到 JBook 中使用的确切方法.其中一些是:

JBook.setSelection(int row, int col, int row, int col);JBook.setSelection(JBook.getDefinedName("some String"));

第一种方法解释了将活动单元格移动到范围内左上角的单元格.
有没有办法从 XSSFWorkbook 对象中获取行索引和列索引?

解决方案

您无法通过工作簿对象设置活动单元格.可能的选项:

  • 如果您有单元格对象,您可以将其标记为活动:cell.setAsActiveCell();
  • 如果您使用 XSSFSheet 并希望设置多个单元格选择:xssfSheet.setActiveCell(reference)(适用于 xmlbeans 2.6.0, 不是 2.3.0)

Reference 可以设置为字符串:"A1:A2" 或使用 CellReference 类:

String reference = new CellReference(rowNum, colNum).formatAsString()

<块引用>

有没有办法从 XSSFWorkbook 对象中获取行索引和列索引?

您可以从单元格中获取索引:

cell.getColumnIndex()cell.getRowIndex()

我不知道什么是 JBook.getDefinedName("some String") 但如果它适用于命名范围,请查看 POI 用户指南:命名范围和命名单元格.

I am trying to migrate the java excel code from JBook to XSSFWorkbook. Am not getting exact methods that are used in JBook. Some of them are:

JBook.setSelection(int row, int col, int row, int col);
JBook.setSelection(JBook.getDefinedName("some String"));

The first method explains moving the active cell to the top left cell in the range.
Is there any way to get the rowindex and column index from XSSFWorkbook object?

解决方案

You can't set active cell via workbook object. Possible options:

  • if you have cell object you can mark it as active: cell.setAsActiveCell();
  • if you work with XSSFSheet and want to set multiple cell selection: xssfSheet.setActiveCell(reference) (works with xmlbeans 2.6.0, not 2.3.0)

Reference can be set as a string: "A1:A2" or using CellReference class:

String reference = new CellReference(rowNum, colNum).formatAsString()

Is there any way to get the rowindex and column index from XSSFWorkbook object?

You can get index from the cell:

cell.getColumnIndex()
cell.getRowIndex()

I don't know what is JBook.getDefinedName("some String") but if it works with named ranges, check POI user guide: Named Ranges and Named Cells.

这篇关于如何使用 XSSFWorkbook 将活动单元格移动到范围 apache poi 中的左上角单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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