java read the new version of Excel

origin

read java excel when different versions of excel, read mode will vary. In line to see many of which are based on older versions of excel, the new version will be used in error. This tutorial is based on the new version (I was office2016).

public static void main(String[] args) throws IOException {
    File file = new File("E:\\dz.xlsx");
    XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(file));
    //读取第一个sheet
    XSSFSheet st = wb.getSheetAt(0);
    DecimalFormat decimalFormat = new DecimalFormat("0");
    Map<String,String> map = new HashMap<>();
    for (int rowIndex = 0; rowIndex <= st.getLastRowNum(); rowIndex++) {
        //循环读取当前sheet的每一行
        XSSFRow row = st.getRow(rowIndex);
        //getCell(0)代表读取当前行第一个单元格的值
        map.put(decimalFormat.format(row.getCell(0).getNumericCellValue()),row.getCell(1).getStringCellValue());
    }
}
Published 114 original articles · won praise 146 · Views 350,000 +

Guess you like

Origin blog.csdn.net/qq32933432/article/details/103913197