package youg; import java.io.FileInputStream; import java.io.InputStream; import java.util.Vector; import jxl.Cell; import jxl.Sheet; import jxl.Workbook; public class ReadExcel { //Vector v_identNumber = new Vector(); // 存放读取出来的号码 public Vector<String> readExcel(String filePath) throws Exception { Vector<String> v = new Vector<String>(); // 存放读取出来的姓名和电话 InputStream iStream = null; Workbook workbook = null; iStream = new FileInputStream(filePath); workbook = Workbook.getWorkbook(iStream); // sheet row column 下标都是从0开始的 Sheet sheet = workbook.getSheet(0); int column = sheet.getColumns(); int rows = sheet.getRows(); System.out.println("共有" + rows + "行," + column + "列数据"); for (int i = 1; i < rows; i++) { Cell[] cells = sheet.getRow(i); //System.out.println(cells[0].getContents()); v.add(cells[0].getContents()); v.add(cells[1].getContents()); //System.out.println(cells[1].getContents()); //v_identNumber.add(cells[1].getContents()); //System.out.println(cells[2].getContents()); //System.out.println(cells[3].getContents()); } // 操作完成时,关闭对象,释放占用的内存空间 if (iStream != null) iStream.close(); if (workbook != null) workbook.close(); return v; } /** * @param args * @throws Exception */ // public static void main(String[] args) throws Exception { // String filePath = "D:\\testreadexcel.xls"; // ReadExcel readExcel = new ReadExcel(); // readExcel.readExcel(filePath).toString(); // // } }