通过Apache POI获取单元格参考信号标识符 [英] Get Cell by a Cell reference letter identifier with Apache POI
问题描述
我试图通过单元格参考从行中获取单元格,并且我有一个问题。例如我有:
row.getCell(CellReference.convertColStringToIndex(B));
如果列索引为 1
,但是如果列被删除,因此 B
列索引变为 2
和方法: CellReference.convertColStringToIndex(B)
仍然将其转换为 1
在这种情况下,我无法获取我的列,我得到 null
。
所以问题是如何从行中获取列取决于单元标识符是一个字母?
看看我对上一个问题的回答: p>
您可能想使用 CellReference 实用工具类来帮助您。它提供Excel样式字母+数字引用和POI样式0基行+列之间的转换。使用它时,您可以执行以下操作:
Sheet sheet = workbook.getSheet(MyInterestingSheet);
CellReference ref = new CellReference(B12);
Row r = sheet.getRow(ref.getRow());
if(r!= null){
单元格c = r.getCell(ref.getCol());
}
这将让您在给定的Excel样式引用中找到单元格(if它被定义,否则为null)
I am trying to get the Cell from the Row by a Cell reference and I have a problem. For example I have:
row.getCell(CellReference.convertColStringToIndex("B"));
That works fine if the Column index is 1
, but if Column was deleted so the B
Column index became 2
and the method: CellReference.convertColStringToIndex("B")
is still converting it to 1
in which case I can't get my Column, I am getting null
.
So the question is how can I get the Column from the Row depending on Cell identifier which is a letter?
Take a look at my answer to a previous question:
You probably want to use the CellReference utility class to help you out. It offers conversion between Excel style letter+number references, and POI style 0-based rows+columns. When using it, you can do something like:
Sheet sheet = workbook.getSheet("MyInterestingSheet");
CellReference ref = new CellReference("B12");
Row r = sheet.getRow(ref.getRow());
if (r != null) {
Cell c = r.getCell(ref.getCol());
}
That will let you find the cell at a given Excel-style reference (if it's defined, else null)
这篇关于通过Apache POI获取单元格参考信号标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!