package test;
import java.io.File;
import java.util.Date;
import jxl.Cell;
import jxl.CellType;
import jxl.DateCell;
import jxl.LabelCell;
import jxl.NumberCell;
import jxl.Sheet;
import jxl.Workbook;
public class ReadXLS {
public static void main(String args[]) {
File path = new File("D://Android_test//test2.xls");
try {
Workbook book = Workbook.getWorkbook(path);
// 获得第一个工作表对象
Sheet sheet = book.getSheet(0);
String strc00 = null;
double strc10 = 0.00;
Date strc11 = null;
Cell c00 = sheet.getCell(0, 0);
Cell c10 = sheet.getCell(1, 0);
Cell c11 = sheet.getCell(1, 1);
if(c00.getType()==CellType.LABEL)
{
LabelCell labelc00=(LabelCell)c00;
strc00=labelc00.getString();
}
if(c10.getType()==CellType.NUMBER)
{
NumberCell numc10=(NumberCell)c10;
strc10=numc10.getValue();
}
if(c11.getType()==CellType.DATE)
{
DateCell datec11=(DateCell)c11;
strc11=datec11.getDate();
}
System.out.println("Cell(0,0)"+"value:"+strc00+";type:"+c00.getType());
System.out.println("Cell(1,0)"+"value:"+strc10+";type:"+c10.getType());
System.out.println("Cell(1,1)"+"value:"+strc11+";type:"+c10.getType());
// // 得到第一列第一行的单元格
// Cell cell1 = sheet.getCell(0, 0);
// 得到
// String result = cell1.getContents();
//System.out.println(result);
book.close();
} catch (Exception e) {
System.out.println(e);
}
}
}
评论0
最新资源