程序如下:
//读取Excel的类
import java.io.*;
import java.util.*;
import jxl.*;
import jxl.read.biff.BiffException;
public class ReadExcel{
public static void main(String[] args) {
try {
Workbook book = Workbook.getWorkbook(new File("1-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("Cell(x, y)" + " value : " + nc.getValue() + "; type : " + cell1.getType() +";Format:"+cell1.getCellFormat());
}else
System.out.println("Cell(x, y)" + " value : " + cell1.getContents() + "; type : " + cell1.getType() );
book.close();
} catch (BiffException e) {
// TODO 自动生成 catch 块
System.out.println(e);
} catch (IOException e) {
// TODO 自动生成 catch 块
System.out.println(e);;
}
}
}
本来想用getFormat()读取自定义类型
结果读出来变成 jxl.biff.。。。。。。。。。。
怎么才能正确地读出自定义类型啊????