可以看看这一页
要一个其中的例子
Java code
// Setup code
String cellName = "TestName";
Workbook wb = getMyWorkbook(); // retrieve workbook
// Retrieve the named range
// Will be something like "$C$10,$D$12:$D$14";
int namedCellIdx = wbgetNameIndex(cellName);
Name aNamedCell = wbgetNameAt(namedCellIdx);
// Retrieve the cell at the named range and test its contents
// Will get back one AreaReference for C10, and
// another for D12 to D14
AreaReference[] arefs = AreaReferencegenerateContiguous(aNamedCellgetRefersToFormula());
for (int i=0; i<arefslength; i++) {
// Only get the corners of the Area
// (use arefs[i]getAllReferencedCells() to get all cells)
CellReference[] crefs = arefs[i]getCells();
for (int j=0; j<crefslength; j++) {
// Check it turns into real stuff
Sheet s = wbgetSheet(crefs[j]getSheetName());
Row r = sgetRow(crefs[j]getRow());
Cell c = rgetCell(crefs[j]getCol());
// Do something with this corner cell
}
}
package comlinyistest1;
import orgapachepoihssfusermodelHSSFCell;
import orgapachepoihssfusermodelHSSFRow;
import orgapachepoihssfusermodelHSSFSheet;
public class HssfCells
{
public void getCellValues(HSSFSheet sheet)
{
if(sheet == null)
{
Systemoutprintln("sheet is null");
return ;
}
for(int i = 0 ; i < sheetgetLastRowNum() ; i ++)
{
HSSFRow row = sheetgetRow(i) ;
if(row == null)
{
Systemoutprintln("单元格第" + (i+1)+ "行为空");
}
else
{
for(int j = 0 ; j < rowgetLastCellNum() ; j ++)
{
HSSFCell cell = rowgetCell(j) ;
if(cell == null)
{
Systemoutprintln("单元格第" + (i+1)+ "行 " + (j+1) + "列为null");
}
else
{
String s = cellgetCellType() == HSSFCellCELL_TYPE_STRINGcellgetStringCellValue():cellgetNumericCellValue()+"";
Systemoutprintln("单元格第" + (i+1)+ "行 " + (j+1) + "列值为" + s);
}
}
}
}
}
}
你好,去看一下官方的API文档,或许你就会了
>
以上就是关于如何用Apache POI读取Excel的单元格自定义名称的值全部的内容,包括:如何用Apache POI读取Excel的单元格自定义名称的值、java poi 读取excel 获得一行的单元格个数不对、求 java用poi包读取excel单元格长度宽度的方法等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)