我在做Excel文件导出的时候,业务 和 实现 不是写在一个系统里面的,所以输出的时候用的是以字节流的形式输出
try {
ByteArrayOutputStream os = new ByteArrayOutputStream();
workBook.write(os);
bytes = os.toByteArray();
os.close();
} catch (IOException e) {
return null;
}
try {
downloadFileName = "aps-mch-cls" + "-" + sdf.format(startDate) + "-" + sdf.format(endDate) + ".xlsx";
String[] titles = { "结算编号", "商户编号", "商户名称","结算净额(元)","银行名称","账户类别","户名","账号","结果" };
//response.setHeader("Content-Disposition", "attachment;filename="+fileName);
byte[] bytes = mechSettlementQueryAppService.exportToExcel(titles, clearSettleSearch);
inputStream = new ByteArrayInputStream(bytes);
} catch (Exception e) {
e.printStackTrace();
}
测试的时候,导出的数据都是完整的,就是每一行每一列都是有数据的,没有考虑其他情况,所以当发布到生产环境上的时候,数据库的数据不完整,也就是说不是每一行每一列都有数据,这时候就出现了一个问题,就是Can not find a java.io.InputStream with the name [inputStream] in the invocation stack。
查看下官方源码:
if (inputStream == null) {
// Find the inputstream from the invocation variable stack
inputStream = (InputStream) invocation.getStack().findValue(conditionalParse(inputName, invocation));
}
if (inputStream == null) {
String msg = ("Can not find a java.io.InputStream with the name [" + inputName + "] in the invocation stack. " +
Check the <param name=\"inputName\"> tag specified for this action.");
LOG.error(msg);
throw new IllegalArgumentException(msg);
}
当inputStream有null的时候就会抛出异常。
所以我在设置有可能为空的 cell的时候做了判空处理,将null 设置为""字符,这样就不会出现异常了。