POI获取excel表中首行标题名称

public static void load(String excelPath,String sheetname) {
		Class clazz=Case.class;
		try {
			Workbook workbook=WorkbookFactory.create(new File(excelPath));
			Sheet sheet=workbook.getSheet(sheetname);
			//获取第一行
			Row titlerow=sheet.getRow(0);
			//有多少列
			int cellNum=titlerow.getLastCellNum();
			for (int i = 0; i < cellNum; i++) {
				//根据索引获取对应的列
				Cell cell=titlerow.getCell(i, MissingCellPolicy.CREATE_NULL_AS_BLANK);
				//设置列的类型是字符串
				cell.setCellType(CellType.STRING);
				String titleValue=cell.getStringCellValue();
				String actuallValue=titleValue.substring(0, titleValue.indexOf("("));
				System.out.println(actuallValue);
			}
			
		} catch (EncryptedDocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvalidFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

POI获取excel表中首行标题名称_第1张图片

 

你可能感兴趣的:(接口自动化测试(Java))