关于ireport 导出xls的问题.记录数多的时候可以出现XLS文件下载框,记录数少的时候一闪而过什么都没有,调试的时候每次都都出现下载框,但是一运行就不行了. 怎么回事/**
 * 导出Excel
 * 
 * @param jasperPrint
 * @param response
 * @throws JRException
 * @throws IOException
 */
public static void exportExcel(String jasperName, JasperPrint jasperPrint,
HttpServletResponse response) throws JRException, IOException { response.reset();
// response.setContentType("application/x-msdownload;charset=GBK");
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("UTF-8");
String filename = "";
SimpleDateFormat dateformat1 = new SimpleDateFormat("HHmmss");
filename = jasperName + dateformat1.format(new Date()) + ".xls";
String docName = java.net.URLEncoder.encode(filename, "UTF-8");
response.setHeader("Content-disposition", "attachment;filename="
+ new String(docName.getBytes("UTF-8"), "iso8859-1")); // BufferedOutputStream ouputStream = new BufferedOutputStream(response
// .getOutputStream());
// ServletOutputStream ouputStream = response.getOutputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JRXlsExporter exporter = new JRXlsExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
exporter.setParameter(
JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,
Boolean.TRUE);
exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET,
Boolean.FALSE);
exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND,
Boolean.FALSE);
exporter.setParameter(JRXlsExporterParameter.IS_AUTO_DETECT_CELL_TYPE,
Boolean.TRUE);
exporter.setParameter(
JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,
Boolean.TRUE); try {
exporter.exportReport(); byte[] bytes = baos.toByteArray();
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
response.flushBuffer();
ouputStream.flush();
ouputStream.close();
} catch (JRException e) {
e.printStackTrace();
} finally { }
}