如何使用spring boot生成excel文件并在响应中发送
我在表中有一个员工记录列表,我想从中生成报告。是否有方法生成生成的报告,并将其以excel格式发送到浏览器作为响应。仅供参考,我使用的是Spring boot和reactjs,您可能想看看 这里有一些在其文件夹中创建XLS[X]文件的示例 一个简单的例子如何使用spring boot生成excel文件并在响应中发送,excel,spring-boot,Excel,Spring Boot,我在表中有一个员工记录列表,我想从中生成报告。是否有方法生成生成的报告,并将其以excel格式发送到浏览器作为响应。仅供参考,我使用的是Spring boot和reactjs,您可能想看看 这里有一些在其文件夹中创建XLS[X]文件的示例 一个简单的例子 Workbook wb = new HSSFWorkbook(); //Workbook wb = new XSSFWorkbook(); CreationHelper createHelper = wb.getCreationHelper()
Workbook wb = new HSSFWorkbook();
//Workbook wb = new XSSFWorkbook();
CreationHelper createHelper = wb.getCreationHelper();
Sheet sheet = wb.createSheet("new sheet");
// Create a row and put some cells in it. Rows are 0 based.
Row row = sheet.createRow(0);
// Create a cell and put a value in it.
Cell cell = row.createCell(0);
cell.setCellValue(1);
// Or do it on one line.
row.createCell(1).setCellValue(1.2);
row.createCell(2).setCellValue(
createHelper.createRichTextString("This is a string"));
row.createCell(3).setCellValue(true);
// Write the output to a file
try (OutputStream fileOut = new FileOutputStream("workbook.xls")) {
wb.write(fileOut);
}
你试过什么吗?让我们看看你的作品,这样我们就可以帮助你了?