带有空值的碧玉报告 pdf
jasper report pdf with null values
我使用以下代码创建了一个 jasper 报告
JasperPrint print = null;
Map<String, Object> datosReporte = new HashMap<String, Object>();
JasperReport reporteJasper = crearReporteJasper();
String rutaPDF = "C:\AAPG\algo.pdf";
try {
for (int i =0; i< lista.size(); i++) {
Fin700PDFVO r = (Fin700PDFVO)lista.get(i);
datosReporte.put("PROVEEDOR", r.getProveedor());
datosReporte.put("RUT", Integer.toString(r.getRut()));
datosReporte.put("TIPO", r.getTipo());
datosReporte.put("CANTREGISTROS", Integer.toString(r.getCantRegistros()));
datosReporte.put("SUMTOTUF", Integer.toString(r.getSumTotUF()));
datosReporte.put("SUMTOTPESOS", Integer.toString(r.getSumTotPesos()));
}
print = JasperFillManager.fillReport(reporteJasper, datosReporte, new JREmptyDataSource());
JasperExportManager.exportReportToPdfFile(print, rutaPDF);
和
private JasperReport crearReporteJasper() {
JasperReport report = null;
String sourceFileName = "ReporteFin700";
InputStream is = null;
try {
is = this.getClass().getResourceAsStream("/resources/" + sourceFileName + ".jrxml");
report = JasperCompileManager.compileReport(is);
} catch (Exception e) {
logger.error("Error al compilar plantilla: " + sourceFileName, e);
throw new ServiceException("Error al compilar plantilla: " + sourceFileName);
}
return report;
但是当我尝试 运行 这段代码时,我得到了一个只有 de 列 header 且值为 null 的 pdf。
我解决了这个问题,正如 Alex K 提到的那样更改 JREmptyDataSource,更改为:
print = JasperFillManager.fillReport(reporteJasper, datosReporte, new JREmptyDataSource());
为此
print = JasperFillManager.fillReport(reporteJasper, datosReporte, new JRMapArrayDataSource(new Object[] { datosReporte }));
我使用以下代码创建了一个 jasper 报告
JasperPrint print = null;
Map<String, Object> datosReporte = new HashMap<String, Object>();
JasperReport reporteJasper = crearReporteJasper();
String rutaPDF = "C:\AAPG\algo.pdf";
try {
for (int i =0; i< lista.size(); i++) {
Fin700PDFVO r = (Fin700PDFVO)lista.get(i);
datosReporte.put("PROVEEDOR", r.getProveedor());
datosReporte.put("RUT", Integer.toString(r.getRut()));
datosReporte.put("TIPO", r.getTipo());
datosReporte.put("CANTREGISTROS", Integer.toString(r.getCantRegistros()));
datosReporte.put("SUMTOTUF", Integer.toString(r.getSumTotUF()));
datosReporte.put("SUMTOTPESOS", Integer.toString(r.getSumTotPesos()));
}
print = JasperFillManager.fillReport(reporteJasper, datosReporte, new JREmptyDataSource());
JasperExportManager.exportReportToPdfFile(print, rutaPDF);
和
private JasperReport crearReporteJasper() {
JasperReport report = null;
String sourceFileName = "ReporteFin700";
InputStream is = null;
try {
is = this.getClass().getResourceAsStream("/resources/" + sourceFileName + ".jrxml");
report = JasperCompileManager.compileReport(is);
} catch (Exception e) {
logger.error("Error al compilar plantilla: " + sourceFileName, e);
throw new ServiceException("Error al compilar plantilla: " + sourceFileName);
}
return report;
但是当我尝试 运行 这段代码时,我得到了一个只有 de 列 header 且值为 null 的 pdf。
我解决了这个问题,正如 Alex K 提到的那样更改 JREmptyDataSource,更改为:
print = JasperFillManager.fillReport(reporteJasper, datosReporte, new JREmptyDataSource());
为此
print = JasperFillManager.fillReport(reporteJasper, datosReporte, new JRMapArrayDataSource(new Object[] { datosReporte }));