package common.util;
import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.CellType;
import jxl.NumberCell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class Excelread {
//读excel文件
static void read()
{
//getClass().getClassLoader().getResource(
try {
/*//没有类型要求随意取
* Workbook workbook = Workbook.getWorkbook(new File((Excelread.class.getResource("")+"shazhenhua.xls").substring(6)));
Sheet sheet = workbook.getSheet(0);
Cell c2 = sheet.getCell(0,0);
String stringc2 = c2.getContents();
System.out.println(stringc2);
workbook.close();*/
//取到数字类型的
//路径处理的一个方法
Workbook workbook = Workbook.getWorkbook(new File((Excelread.class.getResource("")+"shazhenhua.xls").substring(6)));
Sheet sheet = workbook.getSheet(0);
Cell c2 = sheet.getCell(0,0);
if(c2.getType() == CellType.NUMBER)
{
NumberCell nc = (NumberCell)c2;
Number b2 = nc.getValue(); //Number不是基本数据类型,是一个工具类
System.out.println(b2);
}
workbook.close();
}
catch (BiffException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
void write()
{
}
public static void main(String args[])
{
read();
}
}