摘要: JexcelApi读取Excel的内容 //导入 package com.jExcelApi.test; import java.io.File;import java.io.IOException; import jxl.Cell;import jxl.CellType;import jxl.LabelCell;import jxl.NumberCell;import jxl.S ...
JexcelApi读取Excel的内容
//导入
package com.jExcelApi.test;
import java.io.File; import java.io.IOException;
import jxl.Cell; import jxl.CellType; import jxl.LabelCell; import jxl.NumberCell; import jxl.Sheet; import jxl.Workbook; import jxl.read.biff.BiffException;
/** * JExcelApi读取Excel数据 * @author kanjingcai
* */ public class ReadExcel {
public static void main(String args[]){ try { Workbook workBook =Workbook.getWorkbook(new File("D://myFile.xls")); Sheet sheet =workBook.getSheet(0); Cell c1 =sheet.getCell(0,2); Cell c2 =sheet.getCell(3,4); /* String s1 =c1.getContents(); String s2 =c2.getContents(); System.out.println(s1); System.out.println(s2); */ String s =null; Double d =null; //判断c1单元格的值类型 if(c1.getType() ==CellType.LABEL){ LabelCell label =(LabelCell)c1; s =label.getString(); } if(c2.getType() ==CellType.NUMBER){ NumberCell nc =(NumberCell)c2; d =nc.getValue(); }
//打印获取的内容
System.out.println(s); System.out.println(d); workBook.close(); } catch (BiffException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
|