jxl读excel

一、根据文件名filepath获得一个Sheet
//拿到excel表格
		Workbook workbook = null;
		try {
			workbook = Workbook.getWorkbook(new File(path));
		} catch (BiffException e) {
			
			e.printStackTrace();
			error.add("文件不存在");
			pushError(0, error);
			return false;
		} catch (IOException e) {
			e.printStackTrace();
			error.add("文件不存在");
			pushError(0, error);
			return false;
		}
		
		Sheet sheet = workbook.getSheet(getSheetIndex());


二、把sheet的每一行解析成一个List
//处理excel表格
		int row = 1;
		int cols = cells.length;
		
		//处理每一行
		for(;row <sheet.getRows(); row++) {
			List tempList = new ArrayList();
			Object tempObject = null;
			
			//处理每一列
			for(int col=0; col < cols; col++) {
				String content = null;;
				try {
					content = sheet.getCell(col, row).getContents();
				} catch (Exception e) {
					e.printStackTrace();
				}
				tempList.add(content);
			}
			
			list.add(tempList);



三、关闭sheet
workbook.close();

你可能感兴趣的:(java,Excel)