如何获取名为范围区域的 Excel 工作表的高度和宽度HSSFWorkbook POI API
。
我从谷歌获得了一份参考资料,但无法获得 excel 表的命名索引区域的高度和宽度。
提前致谢。
是的,它是命名范围,并且需要命名范围获取的单元格的高度和宽度。下面的代码具有“print_area”命名范围,并且想要单元格的高度和宽度。
int namedCellIdx = 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.
}