操作excel

    static void create(String path) throws Exception {

        //读取文件
        FileInputStream in = new FileInputStream(path);
        XSSFWorkbook wb = new XSSFWorkbook(in);
        // 获得该工作区的第一个sheet
        XSSFSheet sheet = wb.getSheetAt(0);
        int rowNum = sheet.getLastRowNum();//
        int columnNum = sheet.getRow(0).getPhysicalNumberOfCells();//
        System.out.println(rowNum + "条数据," + columnNum + "列");

        XSSFRow row;

        String bm;
        String mm;
        for (int i = 1; i <= rowNum; i++) {
            row = sheet.getRow(i);
            //读取值
            bm = (long) row.getCell(0).getNumericCellValue() + "";
            mm = jia(bm);
            //设置值
            row.getCell(4).setCellValue(mm);
            System.out.println(mm);
        }
        //另存为
        FileOutputStream out = new FileOutputStream("/Users/1111/Desktop/112000000.xlsx");
        //写出
        wb.write(out);
        out.close();
    }

以上程序使用poi读取excel表2007,修改值,另存一份。 

 

posted @ 2018-01-18 21:07  路迢迢  阅读(154)  评论(0编辑  收藏  举报