import com.hao.util.FileUtil;import java.io.File;import java.io.IOException;import java.io.InputStream;import java.util.ArrayList;import java.util.List;import jxl.Cell;import jxl.Sheet;import jxl.Workbook;import jxl.read.biff.BiffException;public class ReaderExcel {public static List<String[]> readExcel(String fileName) {return readExcel(FileUtil.getInputStream(fileName));}public static List<String[]> readExcel(File file) {return readExcel(FileUtil.getInputStream(file));}public static List<String[]> readExcel(InputStream in) {List lt = new ArrayList();Workbook wb = null;try {wb = Workbook.getWorkbook(in);Sheet[] sheets = wb.getSheets();for (int i = 0; i < sheets.length; ++i) {Sheet sheet = sheets[i];for (int j = 0; j < sheet.getRows(); ++j) {Cell[] cells = sheet.getRow(j);if ((cells != null) && (cells.length > 0)) {String[] dataCells = new String[cells.length];for (int k = 0; k < cells.length; ++k) {dataCells[k] = cells[k].getContents();}lt.add(dataCells);}}}} catch (BiffException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();} finally {if (wb != null) {wb.close();}if (in != null) {try {in.close();} catch (IOException e) {e.printStackTrace();}}}return lt;}public static List<String[]> readExcelByFile(File file) {List lt = new ArrayList();Workbook wb = null;try {wb = Workbook.getWorkbook(file);Sheet[] sheets = wb.getSheets();for (int i = 0; i < sheets.length; ++i) {Sheet sheet = sheets[i];for (int j = 0; j < sheet.getRows(); ++j) {Cell[] cells = sheet.getRow(j);if ((cells != null) && (cells.length > 0)) {String[] dataCells = new String[cells.length];for (int k = 0; k < cells.length; ++k) {dataCells[k] = cells[k].getContents();}lt.add(dataCells);}}}} catch (BiffException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();} finally {if (wb != null) {wb.close();}}return lt;}public static List<String[]> readExcelOneSheet(File file) {return readExcelOneSheet(FileUtil.getInputStream(file));}public static List<String[]> readExcelOneSheet(InputStream in) {List lt = new ArrayList();Workbook wb = null;try {wb = Workbook.getWorkbook(in);Sheet[] sheets = wb.getSheets();Sheet sheet = sheets[0];for (int j = 0; j < sheet.getRows(); ++j) {Cell[] cells = sheet.getRow(j);if ((cells != null) && (cells.length > 0)) {String[] dataCells = new String[cells.length];for (int k = 0; k < cells.length; ++k) {dataCells[k] = cells[k].getContents();}lt.add(dataCells);}}} catch (BiffException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();} finally {if (wb != null) {wb.close();}if (in != null) {try {in.close();} catch (IOException e) {e.printStackTrace();}}}return lt;}}
Note: jxl does not support excel2007