자바

yes24 데이터 DB 넣기

chantleman 2024. 8. 19. 11:02

 

테이블 우클릭 - 익스포트

 

엑셀 파일 들어가서 데이터 입력 후 파일(book.xlsx)을 eclipse 프로젝트- excel 폴더에 저장

 

 

 


<ExcelRead.java>

    public class ExcelRead {
        public static void main(String[] args) {
            ExcelRead er = new ExcelRead();
            er.process();
        }
        public void process() {
            try {
                File file = new File("excel/book.xls");
                FileInputStream fis = new FileInputStream(file);

                Workbook workbook = null;
                if(file.getName().endsWith(".xls")) workbook = new HSSFWorkbook(fis);

                Sheet sheet = workbook.getSheetAt(0);

                int startRow = sheet.getFirstRowNum();
                int endRow = sheet.getLastRowNum();
                for(int i=startRow;i<=endRow;i++)
                {
                    Row row = sheet.getRow(i);
                    int startCell = row.getFirstCellNum();
                    int endCell = row.getLastCellNum();
                    for(int j=startCell;j<=endCell;j++)
                    {
                        Cell cell = row.getCell(j);
                        String data = ExcelUtil.getCellData(cell);
                        System.out.println(data+"\t");
                    }
                    System.out.println();
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

 

참고로 xls 파일이면 HSSFWorkbook

xlsx파일이면 XSSFWorkbook 

import해주면 되는데 XSSFWorkbook import가 안되면 

https://mvnrepository.com/

여기서 poi ooxml 검색 후 코드 복사해서 pom.xml에 붙여넣으세요

 

 

 

 

 

결과 출력

'자바' 카테고리의 다른 글

parameterMap 과 sessionStorage 차이  (0) 2024.09.01
JDBCUtil  (0) 2024.08.26
File  (0) 2024.08.11
데이터 크롤링  (0) 2024.08.09
maven  (0) 2024.08.09