/
progghop
/
excelRead
Обзор
Документация
Войти
/
progghop
/
excelRead
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/main/java/org/example/Main.java
54 строки
2 KB
Моисеев Михаил Вячеславович
Initial commit
28 авг 2025, 13:35
28 авг 2025, 13:35
a18e8e6
Код
Авторство
О чём код?
package org.example; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import java.io.FileInputStream; import java.io.IOException; //TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or // click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter. public class Main { public static void main(String[] args) { String filePath = "/Users/m.moiseev/IdeaProjects/fileUpTest/upload-dir/testExcel.xlsx"; try (FileInputStream fis = new FileInputStream(filePath); Workbook workbook = new XSSFWorkbook(fis)) { Sheet sheet = workbook.getSheetAt(0); // Get the first sheet for (Row row : sheet) { for (Cell cell : row) { // System.out.println( cell.getStringCellValue()); // ; // Handle different cell types switch (cell.getCellType()) { case STRING: System.out.print(cell.getStringCellValue()); break; case NUMERIC: System.out.print(String.valueOf((cell.getNumericCellValue())) + "\t"); break; case BOOLEAN: System.out.print(cell.getBooleanCellValue() + "\t"); break; case FORMULA: System.out.print(cell.getCellFormula() + "\t"); break; default: System.out.print("\t"); // Handle other types or blank } } System.out.println(); // New line for each row } } catch (IOException e) { e.printStackTrace(); } } }