• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    해결됨

엑셀 프로그램이 없는 경우

20.04.19 23:33 작성 조회수 242

0

4.12 최신버전으로 다운로드

아래 다운로드

http://commons.apache.org/proper/commons-compress/download_compress.cgi

아래 다운로드https://mvnrepository.com/artifact/org.apache.commons/commons-collections4/4.1

image.png

package com.company;

import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
//import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
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;

import java.io.FileInputStream;
import java.util.Iterator;

public class Project03_C {
public static void main(String[] args) {
String fileName = "cellDataType.xlsx";
try(FileInputStream fis = new FileInputStream(fileName)) {
// HSSFWorkbook workbook = new HSSFWorkbook(fis); // xls
// HSSFSheet sheet = workbook.getSheetAt(0); // xls
XSSFWorkbook workbook = new XSSFWorkbook(fis); // xlsx
XSSFSheet sheet = workbook.getSheetAt(0); // xlsx
Iterator<Row> rows = sheet.rowIterator();
while (rows.hasNext()) {
// HSSFRow row = (HSSFRow) rows.next(); // xls
XSSFRow row = (XSSFRow) rows.next();
Iterator<Cell> cells = row.cellIterator();
while (cells.hasNext()) {
// HSSFCell cell = (HSSFCell) cells.next(); // xls
XSSFCell cell = (XSSFCell) cells.next(); // xlsx
CellType type = cell.getCellType();
if(type == CellType.STRING) {
System.out.println("[" +
cell.getRowIndex() +
"," +
cell.getColumnIndex() +
"] = STRING; Value=" +
cell.getRichStringCellValue().toString());
} else if(type == CellType.NUMERIC) {
System.out.println("[" +
cell.getRowIndex() +
"," +
cell.getColumnIndex() +
"] = NUMERIC; Value=" +
cell.getNumericCellValue());
} else if(type == CellType.BOOLEAN) {
System.out.println("[" +
cell.getRowIndex() +
"," +
cell.getColumnIndex() +
"] = BOOLEAN; Value=" +
cell.getBooleanCellValue());
} else if(type == CellType.BLANK) {
System.out.println("[" +
cell.getRowIndex() +
"," +
cell.getColumnIndex() + "] = BLANK CELL");
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

답변 0

답변을 작성해보세요.

답변을 기다리고 있는 질문이에요.
첫번째 답변을 남겨보세요!