一、引入包

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>5.0.0</version>
</dependency>

二、代码

public class TestTable {
    public static void main(String[] args) throws IOException {
        String path = "F:\\web\\vue-ts\\back_web_page\\public/workTable.xlsx";
        FileInputStream fileInputStream = new FileInputStream(path);
        XSSFWorkbook excel = new XSSFWorkbook(fileInputStream);
        fileInputStream.close();
        XSSFSheet sheet = excel.getSheetAt(0);

        sheet.getRow(0).getCell(0).setCellValue(30);
        sheet.getRow(1).getCell(0).setCellValue(30);

        FileOutputStream fileOutputStream = new FileOutputStream(path);
        excel.write(fileOutputStream);
        fileOutputStream.close();
        excel.close();
    }
}

三、注意

编辑后的excel需要【公式 -> 重算工作簿】