반응형
엑셀 파일 읽기 시 아래 에러 발생시 해결 방법입니다.
라이브러리 추가
apache poi 라이브러리를 추가합니다.
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.3</version>
</dependency>
엑셀 파일 읽기 소스 코드
public static void readExcel() {
try {
FileInputStream file = new FileInputStream("file_path.xlsx");
IOUtils.setByteArrayMaxOverride(Integer.MAX_VALUE);
//Create Workbook instance holding reference to .xlsx file
XSSFWorkbook workbook = new XSSFWorkbook(file);
//Get first/desired sheet from the workbook
XSSFSheet sheet = workbook.getSheetAt(0);
//Iterate through each rows one by one
Iterator<Row> rowIterator = sheet.iterator();
while (rowIterator.hasNext()) {
Row row = rowIterator.next();
//For each row, iterate through all the columns
Iterator<Cell> cellIterator = row.cellIterator();
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
//Check the cell type and format accordingly
switch (cell.getCellType()) {
case NUMERIC:
System.out.print(cell.getNumericCellValue() + "\t");
break;
case STRING:
System.out.print(cell.getStringCellValue() + "\t");
break;
case BLANK :
System.out.print("\t");
break;
default:
throw new IllegalStateException("Unexpected value: " + cell.getCellType());
}
}
System.out.println("");
}
file.close();
} catch (Exception e) {
e.printStackTrace();
}
}
에러 발생
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.logging.log4j.Logger.atDebug()Lorg/apache/logging/log4j/LogBuilder;
해결 방법
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-to-slf4j -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
<version>2.17.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.17.2</version>
</dependency>
반응형
'프로그래밍 > Java' 카테고리의 다른 글
java 소수점 처리 (1) | 2023.10.10 |
---|---|
Java Stream 설명 (0) | 2023.05.26 |
Stream reduce 간단 설명 (0) | 2023.05.20 |
java file.encoding (0) | 2022.07.12 |
[JAVA] java.lang.UnsatisfiedLinkError: no net in java.library.path (1) | 2021.06.25 |