获取单元格的名称apache poi

我有一个Cell对象,我怎样才能得到那个单元格的名字?

想要一个function如:

String name = myCell.getName(); 

在Excel中,我已经在名称框中进行了命名,所以我不想得到“B4”,我想获得“InterestRate”这样的名称。

找不到这样的方法,我可以用其他方式实现吗?

要find与一个单元格完全匹配的指定范围,您需要如下所示的内容:

 // Get the cell we want to find - A1 for this case Workbook wb = WorkbookFactory.create("input.xlsx"); int sheetIndex = 0; Sheet s = wb.getSheetAt(sheetIndex); Cell wanted = s.getRow(0).getCell(0); String wantedRef = (new CellReference(wanted)).formatAsString(); // Check all the named range for (int nn=0; nn<wb.getNumberOfNames(); nn++) { Name n = wb.getNameAt(nn); if (n.getSheetIndex() == -1 || n.getSheetIndex() == sheetIndex) { if (n.getRefersToFormula().equals(wantedRef)) { // Found it! return name.getNameName(); } } } 

请注意,这将返回适用于单元格的第一个命名范围,如果有多个单元格并且您想要所有单元格,则需要调整该代码以继续并返回列表