导航

Java读取excel

Posted on 2012-07-05 10:54  baiyangliu  阅读(122)  评论(0)    收藏  举报
public static List<List<String>> readxls(String fileName) throws BiffException, IOException {
		List<List<String>> list = new ArrayList<List<String>>();
		File file = new File(fileName);
		Workbook workbook = Workbook.getWorkbook(file);
		int sheets = workbook.getNumberOfSheets();
		for (int i = 0; i < sheets; i++) {
			Sheet sheet = workbook.getSheet(i);
			int rows = sheet.getRows();
			for (int j = 0; j < rows; j++) {
				List<String> strings = new ArrayList<String>();
				for (int y = 0; y < sheet.getRow(j).length; y++) {
					strings.add(sheet.getCell(y, j).getContents());
				}
				list.add(strings);
			}
		}
		return list;
	}

下载jar包