程序如下:
public class ReadExcel{
public static void main(String[] args) {
try {
Workbook book = Workbook.getWorkbook(new File("1.xls"));
Sheet sheet = book.getSheet(0);
System.out.println("请输入要读取的单元格");
Scanner in = new Scanner(System.in);
int x = in.nextInt();
in = new Scanner(System.in);
int y = in.nextInt();
Cell cell1 = sheet.getCell(x,y);
String result = cell1.getContents();
if (cell1.getType() == CellType.NUMBER) {
NumberCell nc = (NumberCell) cell1;
System.out.println("value : " + nc.getValue());
System.out.println("type : " + cell1.getType());
System.out.println("Format : " + cell1.getCellFormat());
System.out.println("NumberFormat:" + nc.getNumberFormat());
}
else {
System.out.println("Cell(x, y)" + " value : " + cell1.getContents()
+ "; type : " + cell1.getType()+"Format"+cell1.getCellFormat() );
}
book.close();
} catch (BiffException e) {
// TODO 自动生成 catch 块
System.out.println(e);
} catch (IOException e) {
// TODO 自动生成 catch 块
System.out.println(e);;
}
}
}
为什么getFormat()得到的是
要怎么得到属性?
还有,有没办法得到一个单元格即cell的所有属性?而不用一个个找?