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

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

问题描述

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

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

第一种方法解释了将活动单元格移动到范围内的左上角单元格。

有没有办法从XSSFWorkbook对象获取rowindex和column索引?

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:


  • 如果您有单元格对象,则可以将其标记为活动: cell.setAsActiveCell ();

  • 如果您使用 XSSFSheet 并想要设置多个单元格选择: xssfSheet.setActiveCell(reference)(适用于 xmlbeans 2.6.0 ,而不是 2.3.0

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

参考可以设置为字符串:A1:A2或使用 CellReference class:

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

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




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

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

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

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