这篇文章将为大家详细讲解有关怎么在Java中使用jasperReport对动态列进行打印,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
public ActionResult projectPrint() {
String[] printValue = null;
// 从页面中获得要查询的字段
String reqPrintValue = getRequest().getParameter("printValue");
// 没有选择则默认全打印
if (null == reqPrintValue || StringUtils.isEmpty(reqPrintValue)) {
printValue = new String[] { "pnumber", "pname", "pdepart", "pdecision", "pthrow", "plastmonth", "pfund", "ploan" };
} else {
printValue = reqPrintValue.split(",");
}
// 查询统计数据
List
public static void export(JasperPrint jasperPrint, HttpServletResponse response, HttpServletRequest request,
String type) throws IOException {
if (EXCEL_TYPE.equals(type)) {
exportExcel(jasperPrint, response, request);
} else if (PDF_TYPE.equals(type)) {
exportPDF(jasperPrint, response, request);
} else if (HTML_TYPE.equals(type)) {
exportHTML(jasperPrint, response, request);
} else {
exportPrint(jasperPrint, response, request);
}
}
public static void exportExcel(JasperPrint jasperPrint, HttpServletResponse response, HttpServletRequest request)
throws IOException {
response.setContentType("application/vnd.ms-excel");
String filename = DownloadHelper.encodeFilename("未命名.xls", request);
response.setHeader("Content-disposition", "attachment;filename=" + filename);
ServletOutputStream ouputStream = response.getOutputStream();
JRXlsExporter exporter = new JRXlsExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
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);
try {
exporter.exportReport();
} catch (JRException e) {
e.printStackTrace();
}
ouputStream.flush();
ouputStream.close();
}
public static void exportPDF(JasperPrint jasperPrint, HttpServletResponse response, HttpServletRequest request)
throws IOException {
response.setContentType("application/pdf");
String filename = DownloadHelper.encodeFilename("未命名.pdf", request);
response.setHeader("Content-disposition", "attachment;filename=" + filename);
ServletOutputStream ouputStream = response.getOutputStream();
try {
JasperExportManager.exportReportToPdfStream(jasperPrint, ouputStream);
} catch (JRException e) {
e.printStackTrace();
}
ouputStream.flush();
ouputStream.close();
}
关于怎么在Java中使用jasperReport对动态列进行打印就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。