Closed gumuqing closed 3 weeks ago
You’ll need to create a template file that suits your requirements. You can Google the specific file format if needed.
获取 Outlook for iOShttps://aka.ms/o0ukef
发件人: gumuqing @.> 发送时间: Wednesday, September 4, 2024 11:25:13 AM 收件人: alibaba/easyexcel @.> 抄送: Subscribed @.***> 主题: [alibaba/easyexcel] easyExcel怎样下载模版呢? (Issue #3974)
easyExcel下载模版是要自己写去实现吗? public void downloadTemplate(HttpServletResponse response) throws IOException { // 模板文件路径,这里假设模板放在resources目录下 String templatePath = "classpath:template.xlsx"; // 获取文件输入流 InputStream inputStream = getClass().getResourceAsStream(templatePath); if (inputStream == null) { throw new FileNotFoundException("模板文件未找到"); } // 设置响应头 response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); response.setHeader("Content-Disposition", "attachment;filename=template.xlsx"); // 写入响应流 OutputStream outputStream = response.getOutputStream(); byte[] buffer = new byte[1024]; int bytesRead; while ((bytesRead = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); } outputStream.flush(); outputStream.close(); inputStream.close(); }
还是在easyExcel.write里面有现成的代码?
― Reply to this email directly, view it on GitHubhttps://github.com/alibaba/easyexcel/issues/3974, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACRXFDWJ3PBFXZJBSSDTQ63ZUZ4RTAVCNFSM6AAAAABNTMGOI6VHI2DSMVQWIX3LMV43ASLTON2WKOZSGUYDIMRSGA3TKMA. You are receiving this because you are subscribed to this thread.Message ID: @.***>
This issue has been completed, I will close this issue.
easyExcel下载模版是要自己写去实现吗? public void downloadTemplate(HttpServletResponse response) throws IOException { // 模板文件路径,这里假设模板放在resources目录下 String templatePath = "classpath:template.xlsx"; // 获取文件输入流 InputStream inputStream = getClass().getResourceAsStream(templatePath); if (inputStream == null) { throw new FileNotFoundException("模板文件未找到"); } // 设置响应头 response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); response.setHeader("Content-Disposition", "attachment;filename=template.xlsx"); // 写入响应流 OutputStream outputStream = response.getOutputStream(); byte[] buffer = new byte[1024]; int bytesRead; while ((bytesRead = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); } outputStream.flush(); outputStream.close(); inputStream.close(); }
还是在easyExcel.write里面有现成的代码?