通过与Apache POI单元格引用字母标识符获得Cell [英] Get Cell by a Cell reference letter identifier with Apache POI

查看:1633
本文介绍了通过与Apache POI单元格引用字母标识符获得Cell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过一个单元格引用您可以通过行的单元格,我有一个问题。比如我有:

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

如果列索引是正常工作 1 ,但如果列被删除,在 B 列索引成为 2 和方法: CellReference.convertColStringToIndex(B)还是将其转换为 1 在这种情况下,我不能让我的专栏,我正在

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?

推荐答案

在看看<一个href=\"http://stackoverflow.com/questions/14053055/how-to-get-the-value-of-a-cell-at-a-specified-position-in-an-excel-sheet-using-j/14062181#14062181\">my回答到previous问题:

您可能要使用 CellReference 实用类来帮助你出去。它提供了基于Excel的0风格字母+数字的引用和POI风格之间的转换行+列。当使用它,你可以这样做:

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

这会让你发现在一个给定的Excel样式的引用的单元格(如果它定义,否则返回null)

That will let you find the cell at a given Excel-style reference (if it's defined, else null)

这篇关于通过与Apache POI单元格引用字母标识符获得Cell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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