当前位置: 首页> 汽车> 报价 > Java导出Excel并邮件发送

Java导出Excel并邮件发送

时间:2025/8/23 9:10:07来源:https://blog.csdn.net/diyangxia/article/details/78562644 浏览次数: 0次

一、导出Excel

添加maven依赖

 <dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>3.10-FINAL</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml-schemas</artifactId><version>3.10-FINAL</version></dependency>

exportExcel()这个方法有两个参数,第一个是导出文件的保存全路径,比如/Users/admin/Desktop/result.xlsx,第二个是从sql查询出来的结果集

    public void exportExcel(String excelFileName,List<DataBean> result) {try {String sheetName = "统计报表";// 工作表名XSSFWorkbook wb = new XSSFWorkbook();XSSFSheet sheet = wb.createSheet(sheetName);// 生成一个样式XSSFCellStyle style = wb.createCellStyle();//样式字体居中style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
//            style.setWrapText(true);//自动换行XSSFRow first = sheet.createRow(0);XSSFCell headCell = first.createCell((short) 0);headCell.setCellValue("序号");headCell.setCellStyle(style);headCell = first.createCell( (short) 1);headCell.setCellValue("姓名");headCell.setCellStyle(style);headCell = first.createCell((short) 2);headCell.setCellValue("年龄");headCell.setCellStyle(style);headCell = first.createCell((short) 3);headCell.setCellValue("性别");headCell.setCellStyle(style);headCell = first.createCell(4);headCell.setCellValue("参加次数");headCell.setCellStyle(style);headCell = first.createCell((short) 5);headCell.setCellValue("pb");headCell.setCellStyle(style);// 循环写入每条收入记录的主码和盈利额for (int r = 1; r < result.size()+1; r++) {XSSFRow row = sheet.createRow(r);XSSFCell contentCell = row.c
关键字:Java导出Excel并邮件发送

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: