POI生成Excel如果并发的情况报错This Style does not belong to the supplied Workbook. Are you trying to assign a s

1:POI生成Excel在并发的情况下报错:

 This Style does not belong to the supplied Workbook. Are you trying to assign a style from one workbook to the cell of a differnt workbook? 

2:原因是给单元格设置样式的时候用的HSSFCell下的setCellStyle()方法。
修改成HSSFCellStyle下的cloneStyleFrom()方法可以解决,

Cell  cell = row.createCell(i++);
原始的方法是:
cell.setCellStyle(style);
修改后的方法是:
cell.getCellStyle().cloneStyleFrom(style);

3:修该成上面的代码后,问题又来了,并发的时候,只有其中一个可以下载Excel;

你可能感兴趣的:(学习笔记,java)