def basePath = request.getSession().getServletContext().getRealPath(".") def outFile = basePath+"/export/8D.xls" InputStream input =new BufferedInputStream(new FileInputStream(outFile)) def results = get8DData(record.problemSubId) response.reset(); response.setContentType('APPLICATION/OCTET-STREAM') response.setHeader('Content-Disposition', 'Attachment;Filename="problemReport.zip"') ZipOutputStream zip = new ZipOutputStream(response.outputStream); def file1Entry = new ZipEntry('8D.xls'); zip.putNextEntry(file1Entry); def workbook = new XLSTransformer().transformXLS(input, results.data) //将EXCEL写入到zip输出流中 workbook.write(zip) results.files.each{it -> // InputStream fileBytes = new FileInputStream("D:/logo1.png") def fileBytes = new ByteArrayInputStream(it.image) def files= new ZipEntry(it.image_filename); // def file1Entry = new ZipEntry("logo1.png"); zip.putNextEntry(files); def buf = new byte[1024 * 1024] int len = 0 // 循环将输入流中的内容读取到缓冲区中 while ((len = fileBytes.read(buf)) > 0) { // 输出缓冲区内容到浏览器,实现文件下载 // response.outputStream.write(buf, 0, len) zip.write(buf, 0, len) } fileBytes.close() } input.close() zip.close();