java对于07excel的读、改、写、并触发计算

时间:2023-03-09 01:27:44
java对于07excel的读、改、写、并触发计算
     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();
}