Answer the question
In order to leave comments, you need to log in
How to get data from cell in excel format?
An excel table is given. The first column contains the scores for the exams, and the second and third two classes. How to make it so that the class number and the result are entered, after which it displays the result of the exam? Below is the code that prints the entire excel table. If anyone can give me an idea on how to do it, I'd be grateful.
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("");
}
}
}
Answer the question
In order to leave comments, you need to log in
The first column contains the scores for the exams, and the second and third two classes.
How to make it so that the class number and the result are entered, after which it displays the result of the exam?
<code></code>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question