如何获取Excel工作表的高度和宽度 named range HSSFWorkbook POI API
区域。
我有一个 reference来自谷歌,但无法获取 Excel 工作表的命名索引区域的高度和宽度。
提前致谢。
是的,它是命名范围,并且想要通过命名范围获取单元格的高度和宽度。下面的代码具有名为“print_area”的范围,并且想要单元格的高度和宽度。
int nameCellIdx = workbook.getNameIndex("Print_Area"); HSSFName aNamedCell = workbook.getNameAt(namedCellIdx);
// retrieve the cell at the named range and test its contents
String a = aNamedCell.getReference();
AreaReference aref = new AreaReference(aNamedCell.getRefersToFormula());
CellReference[] crefs = aref.getAllReferencedCells();
for (int i=0; i<crefs.length; i++) {
Sheet s = workbook.getSheet(crefs[i].getSheetName());
Row r = sheet.getRow(crefs[i].getRow());
System.out.println(r.getHeight());
System.out.println(sheet.getColumnWidth(crefs[i].getCol()));;
//here want height and width of "Print_area" cells
Cell c = r.getCell(crefs[i].getCol());
System.out.println(c.getStringCellValue());
// extract the cell contents based on cell type etc.
}
最佳答案
阅读 API 文档:http://poi.apache.org/apidocs/index.html
具体来说,请查看org.apache.poi.ss.util.AreaReference
,从中您可以获得第一个和最后一个单元格引用并确定范围的大小。
但是,您必须处理许多特殊情况,例如整列或整行的区域,甚至是不连续的区域。
关于java - 如何从 HSSFWorkbook POI API 获取 Excel 工作表“命名索引”区域的高度和宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15263636/