1. The request does not include the request and the HttpServletResponse response.
Use ExcelData and ExportExcelUtils tool class to combine XSSFWorkbook to achieve Excel file export
ExcelData data = new ExcelData(); ("Tag Name"); // TitleList<String> titles = new ArrayList(); ("First Column"); ("Second Column"); ("Third Column"); (titles); // contentList<List<Object>> rows = new ArrayList(); for(int i=0; i<10; i++){ List<Object> row = new ArrayList(); (The+"i"+行The一列); (The+"i"+行The二列); (The+"i"+行The三列); (row); } (rows); XSSFWorkbook wb = (data); ByteArrayOutputStream outByteStream = new ByteArrayOutputStream(); (outByteStream); (); HttpHeaders headers = new HttpHeaders(); ("Content-Type", "application/-excel"); ("Connection", "close"); ("file", "type"); ("Content-Disposition", "attachment; filename=" + new String(("utf-8"), "ISO-8859-1")); return new ResponseEntity<byte[]>((), headers, );
2. The HttpServletResponse response is included in the request.
Use XSSFWorkbook to implement Excel file export
("application/"); ("UTF-8"); ("file", "type"); ("Connection", "close"); ("Content-disposition", "attachment;filename=" + ExcelUtil.toUtf8String("file name")); String filePath = "/docs/"; InputStream inputStream = new ClassPathResource(filePath).getInputStream(); XSSFWorkbook xssfWorkbook = new XSSFWorkbook(inputStream); // sheet XSSFSheet sheetAt = (0); (0, 15000); // Cell formatXSSFCellStyle cellStyle = (); (); (); (); (); (); (); // TitlewriteValue(sheetAt, cellStyle, 0, 0, "First Column"); writeValue(sheetAt, cellStyle, 0, 0, "Second Column"); writeValue(sheetAt, cellStyle, 0, 0, "Third Column"); // contentfor(int i=1; i=10; i++){ writeValue(sheetAt, cellStyle, i, 0, "Third"+i+"Road first column"); writeValue(sheetAt, cellStyle, i, 1, "Third"+i+"Road Second Column"); writeValue(sheetAt, cellStyle, i, 2, "Third"+i+"Road Third Column"); } (()); if (null != xssfWorkbook) { (); }
This is the end of this article about Java exporting Excel files. For more related Java exporting Excel files, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!