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:
我正在尝试将java excel代码从JBook迁移到XSSFWorkbook。我没有得到在JBook中使用的确切方法。他们中的一些人是:
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?
第一个方法解释了将活动单元格移动到范围中的左上角单元格。是否有方法从XSSFWorkbook对象获取rowindex和列索引?
2 个解决方案
#1
1
You can't set active cell via workbook object. Possible options:
不能通过workbook对象设置活动单元格。可能的选项:
- if you have cell object you can mark it as active:
cell.setAsActiveCell();
- 如果您有cell对象,可以将其标记为active: cell.setAsActiveCell();
- if you work with
XSSFSheet
and want to set multiple cell selection:xssfSheet.setActiveCell(reference)
(works withxmlbeans 2.6.0
, not2.3.0
) - 如果您使用XSSFSheet并希望设置多个单元格选择:XSSFSheet . setactivecell(引用)(使用xmlbeans 2.6.0,而不是2.3.0)
Reference can be set as a string: "A1:A2"
or using CellReference
class:
可将引用设置为字符串:“A1:A2”或使用CellReference类:
String reference = new CellReference(rowNum, colNum).formatAsString()
Is there any way to get the rowindex and column index from XSSFWorkbook object?
是否有方法从XSSFWorkbook对象获取rowindex和列索引?
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.
我不知道JBook是什么。getDefinedName(“一些字符串”),但是如果它使用命名范围,请查看POI用户指南:命名范围和命名单元格。
#2
0
Did you try this way
你试过这种方法吗?
HSSFWorkbook book1 = new HSSFWorkbook();
HSSFSheet sheet = book1.getSheet("sheetName");
int rowIndex=sheet.getLastRowNum()+1;//
int columnIndex = sheet.getRow(sheet.getLastRowNum()).getPhysicalNumberOfCells()
#1
1
You can't set active cell via workbook object. Possible options:
不能通过workbook对象设置活动单元格。可能的选项:
- if you have cell object you can mark it as active:
cell.setAsActiveCell();
- 如果您有cell对象,可以将其标记为active: cell.setAsActiveCell();
- if you work with
XSSFSheet
and want to set multiple cell selection:xssfSheet.setActiveCell(reference)
(works withxmlbeans 2.6.0
, not2.3.0
) - 如果您使用XSSFSheet并希望设置多个单元格选择:XSSFSheet . setactivecell(引用)(使用xmlbeans 2.6.0,而不是2.3.0)
Reference can be set as a string: "A1:A2"
or using CellReference
class:
可将引用设置为字符串:“A1:A2”或使用CellReference类:
String reference = new CellReference(rowNum, colNum).formatAsString()
Is there any way to get the rowindex and column index from XSSFWorkbook object?
是否有方法从XSSFWorkbook对象获取rowindex和列索引?
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.
我不知道JBook是什么。getDefinedName(“一些字符串”),但是如果它使用命名范围,请查看POI用户指南:命名范围和命名单元格。
#2
0
Did you try this way
你试过这种方法吗?
HSSFWorkbook book1 = new HSSFWorkbook();
HSSFSheet sheet = book1.getSheet("sheetName");
int rowIndex=sheet.getLastRowNum()+1;//
int columnIndex = sheet.getRow(sheet.getLastRowNum()).getPhysicalNumberOfCells()