diff --git a/java/api/build.gradle b/java/api/build.gradle index e988d47b..c0363657 100644 --- a/java/api/build.gradle +++ b/java/api/build.gradle @@ -12,6 +12,10 @@ repositories { dependencies { implementation 'org.jsoup:jsoup:1.16.1' implementation 'com.google.code.gson:gson:2.10.1' + implementation 'org.apache.poi:poi:5.2.3' + implementation 'org.apache.poi:poi-ooxml:5.2.3' + + implementation 'org.apache.logging.log4j:log4j-core:2.20.0' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' diff --git a/java/api/example.xlsx b/java/api/example.xlsx new file mode 100644 index 00000000..dee30297 Binary files /dev/null and b/java/api/example.xlsx differ diff --git a/java/api/src/main/java/poi/ExcelEx.java b/java/api/src/main/java/poi/ExcelEx.java new file mode 100644 index 00000000..8b5cf76a --- /dev/null +++ b/java/api/src/main/java/poi/ExcelEx.java @@ -0,0 +1,63 @@ +package poi; + +import org.apache.poi.ss.usermodel.*; + +import java.io.FileInputStream; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class ExcelEx { + + public static void main(String[] args) { + try { + FileInputStream file = new FileInputStream("example.xlsx"); + Workbook workbook = WorkbookFactory.create(file); + Sheet sheet = workbook.getSheetAt(0); + + for (Row row : sheet) { + for (Cell cell : row) { + + switch (cell.getCellType()) { + case NUMERIC: + if (DateUtil.isCellDateFormatted(cell)) { + Date date = cell.getDateCellValue(); + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); + String dateValue = format.format(date); + System.out.print(dateValue + "\t"); + } else { + double numericValue = cell.getNumericCellValue(); + if (numericValue == Math.floor(numericValue)) { + int intValue = (int) numericValue; + System.out.print(intValue + "\t"); + } else { + System.out.print(numericValue + "\t"); + } + } + break; + case STRING: + String stringValue = cell.getStringCellValue(); + System.out.print(stringValue + "\t"); + break; + case BOOLEAN: + boolean booleanValue = cell.getBooleanCellValue(); + System.out.print(booleanValue + "\t"); + break; + case FORMULA: + String formulaValue = cell.getCellFormula(); + System.out.print(formulaValue + "\t"); + case BLANK: + default: + System.out.print("\t"); + break; + } + } + System.out.println(); + } + file.close(); + System.out.println("엑셀 데이터 읽어오기 완료"); + } catch (IOException e) { + e.printStackTrace(); + } + } +}