poi生成excel,office打开报错,wps没事

ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try {
workbook.write(byteArrayOutputStream);
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
//加上设置大小 下载下来的excel文件office在打开前不会提示修复
response.setHeader("Content-Length", String.valueOf(byteArrayInputStream.available()));
//获取响应的流对象
OutputStream os = response.getOutputStream();
byte[] b = new byte[1024];
int length;
while ((length = byteArrayInputStream.read(b)) > 0) {
os.write(b, 0, length);
}
//关流
byteArrayOutputStream.close();
byteArrayInputStream.close();
//将响应输出流中的数据刷新到浏览器
os.flush();
os.close();
} catch (IOException e) {
e.printStackTrace();
}