poi下载excel
时间: 2023-10-30 07:07:02 浏览: 169
您可以使用Apache POI库来下载Excel文件。以下是一个简单的Java代码示例,可以将数据写入Excel文件并将其下载到本地计算机:
// 创建工作簿对象
Workbook workbook = new XSSFWorkbook();
// 创建工作表对象
Sheet sheet = workbook.createSheet("Sheet1");
// 创建行对象
Row row = sheet.createRow(0);
// 创建单元格对象
Cell cell = row.createCell(0);
// 设置单元格的值
cell.setCellValue("Hello World!");
// 将工作簿写入输出流
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
workbook.write(outputStream);
// 设置响应头信息
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;filename=test.xlsx");
// 将Excel文件下载到本地计算机
ServletOutputStream servletOutputStream = response.getOutputStream();
servletOutputStream.write(outputStream.toByteArray());
servletOutputStream.flush();
servletOutputStream.close();
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044901.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![java](https://img-home.csdnimg.cn/images/20250102104920.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![text/plain](https://img-home.csdnimg.cn/images/20250102104920.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)