InputStream is = null;
        try {
            is = new FileInputStream(filePath);
        } catch (FileNotFoundException e1) {
            System.out.println("file not found");
        }
        XSSFWorkbook xwb =null;
        try {
            xwb= new XSSFWorkbook(is);//新建workbook时需要文件流的方式读入
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
        xwb.setForceFormulaRecalculation(true);//设置更新内容后自动触发计算
XSSFSheet sheet
=xwb.getSheetAt(0); sheet.getRow(2).getCell(col).setCellValue(1);//对于excel的写操作,此处仅用一行代码表示 try { FileOutputStream fos = new FileOutputStream(filePath);//用文件流的方式将修改后的workbook输出到原文件中 xwb.write(fos); System.out.println("写入成功"); fos.close(); } catch (IOException e) { e.printStackTrace(); }

 

posted on 2018-01-09 14:33  程序员丁先生  阅读(341)  评论(0编辑  收藏  举报