Как получить данные из ячейки в формате excel?
Дана таблица формата excel. В первом столбце написаны баллы по экзаменам, а во втором и третьем два класса. Как сделать так чтобы вводились номер класса и результат после чего выводило результат экзамена? Ниже представлен код, который печатает всю таблицу excel. Кто сможет подсказать хотя бы идею как сделать, буду благодарен.
public class excel {
public static void main(String[] args) throws IOException {
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(new File("C:\\Users\\Super Sany\\IdeaProjects\\asd\\Сила.xlsx"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
XSSFWorkbook workbook = null;
try {
workbook = new XSSFWorkbook(inputStream);
} catch (IOException e) {
e.printStackTrace();
}
XSSFSheet sheet = workbook.getSheetAt(0);
Iterator<Row> rowIterator = sheet.iterator();
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
if (rowIterator.hasNext()) {
Row row = rowIterator.next();
Iterator<Cell> cellIterator = row.cellIterator();
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
CellType cellType = cell.getCellType();
switch (cellType) {
case _NONE:
System.out.print("");
System.out.print("\t");
break;
case BOOLEAN:
System.out.print(cell.getBooleanCellValue());
System.out.print("\t");
break;
case BLANK:
System.out.print("");
System.out.print("\t");
break;
case FORMULA:
System.out.print(cell.getCellFormula());
System.out.print("\t");
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
System.out.print(evaluator.evaluate(cell).getNumberValue());
break;
case NUMERIC:
System.out.print(cell.getNumericCellValue());
System.out.print("\t");
break;
case STRING:
System.out.print(cell.getStringCellValue());
System.out.print("\t");
break;
case ERROR:
System.out.print("!");
System.out.print("\t");
break;
}
}
System.out.println("");
}
}
}