java poi 3.17 to read excel 2003

 

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.17</version>
        </dependency>

  

 

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.Row;

import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;

public class ExcelUtils {

    public static void main(String[] args) {
        String excelPath = "/Users/walker/work/private-project/project/excel_process_module/doc/武汉-枣庄-20200322.xls";
        try {
            readExcel2003(excelPath);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
//    List<List<String>>
    static void readExcel2003 public (String fileName) throws Exception { 
// create a stream input 
        the FileInputStream = new new inputStream the FileInputStream (fileName); 
// Create a Workbook 
        HSSFWorkbook Workbook = new new HSSFWorkbook (inputStream); 
// Create a sheet object parameters sheet the index 
        HSSFSheet sheet = workbook.getSheetAt (0); 
// create a second set of digits to store a table of 
        List <List <String >> allDataList = new new ArrayList <> (); 

        for (Row Row: sheet) { 
            List <String > = new new oneRowList the ArrayList <> (); 
// not read header 
            IF (row.getRowNum () == 0) { 
                Continue; 
            }  
            for (the Cell Cell: Row) {
                cell.setCellType (cell.CELL_TYPE_STRING);
                oneRowList.add(cell.getStringCellValue().trim());
            }
            allDataList.add(oneRowList);
        }

        for(int i = 0; i <allDataList.size(); i++){
            System.out.println(allDataList.get(i));
        }
//      关闭workbook
//        return allDataList;
    }
}

 

Guess you like

Origin www.cnblogs.com/wooluwalker/p/12565026.html