excel多文件压缩导出问题 目前只导出了一个 但打开压缩包是这些东西 这是什么原因
public void exportTransactionExcel(HttpServletResponse res,Long id)throws Exception{
OutputStream out = res.getOutputStream();
ZipOutputStream zipOutputStream = new ZipOutputStream(out);
try {
res.setContentType("application/octet-stream; charset=utf-8");
res.setHeader("Content-Disposition", "attachment; filename=" + Encodes.urlEncode("xxx.zip"));
List<List<String>> data = new ArrayList<List<String>>();
ExportExcelUtils eeu = new ExportExcelUtils();
File file=new File("C:/Users/MXG/Desktop/xxx.xlsx");
FileInputStream fis=new FileInputStream(file);
//Workbook workbook = new XSSFWorkbook(OPCPackage.open(fis));
XLSTransformer transformer = new XLSTransformer();
Map<Object, Object> beans=new HashMap<>();
// Workbook workbook = transformer.transformXLS(new FileInputStream(file), beans);
Query query =em.createQuery("From Transaction where 1=1"+((id!=null&&id>0)?" and id="+id:"") );
List<Transaction> transactionList =query.getResultList();
int j=0;
for (Transaction transaction : transactionList) {
Workbook workbook = new XSSFWorkbook(OPCPackage.open(fis));
// HSSFSheet mySheet = workbook.createSheet();
Sheet mySheet = workbook.getSheetAt(0);
//创建第一行,标题行
int rowNomber=-1;
Row row= mySheet.getRow(2);
Cell cell=row.getCell(3);
cell.setCellValue("123456");
//重点开始,创建压缩文件
ZipEntry z = new ZipEntry(transaction.getServiceName()+j+++ ".xlsx");
zipOutputStream.putNextEntry(z);
//写入一个压缩文件
workbook.write(zipOutputStream);
}
zipOutputStream.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
//注意关闭顺序,否则可能文件错误
if (zipOutputStream != null) {
zipOutputStream.close();
}
if (out != null) {
out.close();
}
}
}