How to use the XSSFWorkbook class to save modified Excel files to the file system

To save the modified Excel file to the file system using the XSSFWorkbook class, you need to add a dependency on Apache POI. Please ensure that Maven has been installed and add the following dependencies to the pom.xml file of the project: <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>4.1.2</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>4.1.2</version> </dependency> Next, I will provide a simple Excel sample that includes two columns of data: "Name" and "Age", along with some sample data. The Excel file will be saved as' example. xlsx '. |Name | Age| |---- | ----| |Zhang San | 20| |Li Si | 30| |Wang Wu | 25| The following is a Java code example that demonstrates how to use the XSSFWorkbook class to save a modified Excel file to the file system: import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import java.io.FileOutputStream; import java.io.IOException; public class ExcelWriter { public static void main(String[] args) { //Create Workbook Workbook workbook = new XSSFWorkbook(); //Create a worksheet Sheet sheet = workbook.createSheet("Sheet1"); //Write data Row headerRow = sheet.createRow(0); HeaderRow. createCell (0). setCellValue ("Name"); HeaderRow. createCell (1). setCellValue ("age"); Row dataRow1 = sheet.createRow(1); DataRow1. createCell (0). setCellValue ("Zhang San"); dataRow1.createCell(1).setCellValue(20); Row dataRow2 = sheet.createRow(2); DataRow2. createCell (0). setCellValue ("Li Si"); dataRow2.createCell(1).setCellValue(30); Row dataRow3 = sheet.createRow(3); DataRow3. createCell (0). setCellValue ("Wang Wu"); dataRow3.createCell(1).setCellValue(25); //Save Workbook to File System try (FileOutputStream outputStream = new FileOutputStream("example.xlsx")) { workbook.write(outputStream); } catch (IOException e) { e.printStackTrace(); } System. out. println ("Excel file saved successfully!"); } } After running the above code, an Excel file named "example. xlsx" will be generated in the root directory of the project, which contains the modified data.