카테고리 없음
자바 엑셀 파일 읽기
xemaker
2021. 12. 21. 14:40
package sele;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ExcelLoad {
public List<String> getReply() throws InvalidFormatException, IOException{
String pathFile="C\\sele\\reply.xlsx";
List<String> replyList=new ArrayList<String>();
XSSFWorkbook workbook=null;
File excelFile=new File(pathFile);
workbook=new XSSFWorkbook(excelFile);
XSSFSheet sheet=workbook.getSheetAt(0);
int rowCount=sheet.getLastRowNum();
for (int i = 0; i <rowCount; i++) {
XSSFRow row=sheet.getRow(i);
String reply=row.getCell(0).toString();
replyList.add(reply);
}
return replyList;
}
public static void main(String[] args) throws InvalidFormatException, IOException {
ExcelLoad excel=new ExcelLoad();
List<String> replyList=excel.getReply();
}
}