java数据处理数据生成excel表幽2024-12-062025-03-31导包 1234567891011<!-- poi --> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.16</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>3.16</version> </dependency> 实现代码 12345678910111213141516171819202122232425262728293031323334public static void write() throws Exception { //在内存中创建excel XSSFWorkbook excel = new XSSFWorkbook(); //在excel文件中创建Sheet页 XSSFSheet sheet = excel.createSheet("info"); XSSFSheet sheet1 = excel.createSheet("wqe"); //在sheet页中创建行对象,rownum从0开始 XSSFRow row = sheet.createRow(1); //创建单元格并写入文件内容 row.createCell(1).setCellValue("姓名"); row.createCell(2).setCellValue("城市"); //创建新行 row = sheet.createRow(2); row.createCell(1).setCellValue("张三"); row.createCell(2).setCellValue("长沙"); row = sheet.createRow(3); row.createCell(1).setCellValue("李四"); row.createCell(2).setCellValue("南京"); //通过输出流把excel文件写入到磁盘 FileOutputStream out = new FileOutputStream(new File("F:\\info.xlsx")); excel.write(out); //关闭资源 out.close(); excel.close(); } 效果