implementation 'org.apache.poi:poi-ooxml:4.1.2'
package com.example.test.jsonparsing;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ExcelParser {
public static void main(String[] args) throws IOException {
FileInputStream file = new FileInputStream("xlsx νμΌ μμΉ\\xlsx νμΌ μ΄λ¦"); // νμΌ μ½κΈ°
XSSFWorkbook workbook = new XSSFWorkbook(file); // μμ
νμΌ νμ±
XSSFSheet sheet = workbook.getSheetAt(0); // μμ
νμΌμ 첫λ²μ§Έ (0) μνΈμ§
int rows = sheet.getPhysicalNumberOfRows(); // νμ μ
for (int r = 1; r < rows; r++) {
XSSFRow row = sheet.getRow(r); // 0 ~ rows
if (row != null) { // νμ΄ λΉμ΄μμ§ μμ λ
int cells=row.getPhysicalNumberOfCells(); // μ΄μ μ
for (int c = 0; c < cells; c++) {
XSSFCell cell = row.getCell(c); // 0 ~ cell
String value = "";
if (cell == null) { // rμ΄ cνμ cellμ΄ λΉμ΄μμ λ
continue;
} else { // νμ
λ³λ‘ λ΄μ© μ½κΈ°
switch (cell.getCellType()) {
case FORMULA:
value = cell.getCellFormula();
break;
case NUMERIC:
value = cell.getNumericCellValue() + "";
break;
case STRING:
value = cell.getStringCellValue() + "";
break;
case BLANK:
value = cell.getBooleanCellValue() + "";
break;
case ERROR:
value = cell.getErrorCellValue() + "";
break;
}
}
System.out.println(r + "λ² ν : " + c + "λ² μ΄ κ°μ: " + value);
}
}
}
}