자바 poi 작업 2. Excel. xlsx 읽 기

1607 단어
package com.tanruyu.demo;

import java.io.File;

import java.io.FileInputStream;

import java.util.Iterator;

import org.apache.poi.ss.usermodel.Cell;

import org.apache.poi.ss.usermodel.Row;

import org.apache.poi.xssf.usermodel.XSSFRow;

import org.apache.poi.xssf.usermodel.XSSFSheet;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class ReadXlsx {

    public static void main(String[] args) throws Exception {

        XSSFRow row = null;

        // 1.        

        FileInputStream fis = new FileInputStream(new File("f:/WriteSheet.xlsx"));

        XSSFWorkbook workbook = new XSSFWorkbook(fis);

        // 2.    sheet

        XSSFSheet spreadsheet = workbook.getSheetAt(0);

        Iterator rowIterator = spreadsheet.iterator();

        while (rowIterator.hasNext()) {

            //       

            row = (XSSFRow) rowIterator.next();

            //      

            Iterator cellIterator = row.cellIterator();

            while (cellIterator.hasNext()) {

                Cell cell = cellIterator.next();

                //        

                switch (cell.getCellType()) {

                // case Cell.CELL_TYPE_NUMERIC:

                // System.out.print(cell.getNumericCellValue() + " \t\t ");

                // break;

                case Cell.CELL_TYPE_STRING:

                    System.out.print(cell.getStringCellValue() + " \t\t ");

                    break;

                }

            }

            System.out.println();

        }

        fis.close();

    }

}

좋은 웹페이지 즐겨찾기