bug#22333
dev:lucas qua: git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@107055 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
3a15527249
commit
1bcfc76b71
|
@ -1,5 +1,6 @@
|
|||
package com.rjconsultores.ventaboletos.relatorios.impl;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
|
@ -26,6 +27,7 @@ import net.sf.jasperreports.engine.JRException;
|
|||
import net.sf.jasperreports.engine.JRField;
|
||||
import net.sf.jasperreports.engine.JRLineBox;
|
||||
import net.sf.jasperreports.engine.JasperCompileManager;
|
||||
import net.sf.jasperreports.engine.JasperExportManager;
|
||||
import net.sf.jasperreports.engine.JasperFillManager;
|
||||
import net.sf.jasperreports.engine.JasperPrint;
|
||||
import net.sf.jasperreports.engine.JasperReport;
|
||||
|
@ -42,6 +44,8 @@ import net.sf.jasperreports.engine.design.JRDesignStyle;
|
|||
import net.sf.jasperreports.engine.design.JRDesignTextField;
|
||||
import net.sf.jasperreports.engine.design.JRDesignVariable;
|
||||
import net.sf.jasperreports.engine.design.JasperDesign;
|
||||
import net.sf.jasperreports.engine.export.JExcelApiExporter;
|
||||
import net.sf.jasperreports.engine.export.JExcelApiExporterParameter;
|
||||
import net.sf.jasperreports.engine.export.JRPdfExporter;
|
||||
import net.sf.jasperreports.engine.export.JRPdfExporterParameter;
|
||||
import net.sf.jasperreports.engine.export.JRXlsExporterParameter;
|
||||
|
@ -105,6 +109,29 @@ public class RelatorioPdfAndExcel {
|
|||
|
||||
}
|
||||
|
||||
public byte[] generateReportRender(boolean isPdf) throws Exception {
|
||||
|
||||
JasperDesign jasperDesign = createDesign();
|
||||
JasperReport jasperReport = JasperCompileManager
|
||||
.compileReport(jasperDesign);
|
||||
|
||||
byte[] conteudo = null;
|
||||
|
||||
JRDataSource jrDataSource = prepareDataSource();
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
|
||||
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,
|
||||
params, jrDataSource);
|
||||
|
||||
if (isPdf) {
|
||||
conteudo = this.renderPdf(jasperPrint);
|
||||
} else {
|
||||
conteudo = this.renderXls(false, jasperPrint);
|
||||
}
|
||||
return conteudo;
|
||||
|
||||
}
|
||||
|
||||
private JRDataSource prepareDataSource() {
|
||||
List<Map<String, ?>> preparedData = new ArrayList<Map<String, ?>>();
|
||||
Map<String, Object> map;
|
||||
|
@ -264,4 +291,35 @@ public class RelatorioPdfAndExcel {
|
|||
staticText.setText(nomeColuna);
|
||||
return staticText;
|
||||
}
|
||||
|
||||
|
||||
private byte[] renderXls(boolean isCustomXls, JasperPrint jasperPrint) throws Exception {
|
||||
JExcelApiExporter exporterXLS = new JExcelApiExporter();
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
|
||||
// As duas propriedades são para quando o arquivo xls chegar no máximo de linhas pular para a próxima aba do arquivo mantis #11294
|
||||
exporterXLS.setParameter(JExcelApiExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE);
|
||||
exporterXLS.setParameter(JExcelApiExporterParameter.MAXIMUM_ROWS_PER_SHEET, 65500);
|
||||
|
||||
exporterXLS.setParameter(JExcelApiExporterParameter.JASPER_PRINT, jasperPrint);
|
||||
exporterXLS.setParameter(JExcelApiExporterParameter.OUTPUT_STREAM, output);
|
||||
|
||||
if (!isCustomXls) {
|
||||
exporterXLS.setParameter(JExcelApiExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
|
||||
exporterXLS.setParameter(JExcelApiExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
|
||||
exporterXLS.setParameter(JExcelApiExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
|
||||
exporterXLS.setParameter(JExcelApiExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
|
||||
exporterXLS.setParameter(JExcelApiExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS, Boolean.TRUE);
|
||||
}
|
||||
|
||||
// collapseRowSpan
|
||||
// JRXlsExporterParameter.
|
||||
exporterXLS.exportReport();
|
||||
return output.toByteArray();
|
||||
}
|
||||
|
||||
private byte[] renderPdf(JasperPrint jasperPrint) throws Exception {
|
||||
return JasperExportManager.exportReportToPdf(jasperPrint);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*/
|
||||
package com.rjconsultores.ventaboletos.web.gui.controladores.catalogos;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
|
@ -36,6 +37,7 @@ import com.rjconsultores.ventaboletos.entidad.Empresa;
|
|||
import com.rjconsultores.ventaboletos.entidad.PuntoVenta;
|
||||
import com.rjconsultores.ventaboletos.enums.SistemaEnum;
|
||||
import com.rjconsultores.ventaboletos.relatorios.impl.RelatorioPdfAndExcel;
|
||||
import com.rjconsultores.ventaboletos.relatorios.utilitarios.SaidaRelatorio;
|
||||
import com.rjconsultores.ventaboletos.service.DispositivoEmbarcadaService;
|
||||
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
||||
import com.rjconsultores.ventaboletos.web.utilerias.MyComboboxEstandar;
|
||||
|
@ -209,17 +211,19 @@ public class BusquedaDispositivoVendaEmbarcadaController extends MyGenericForwar
|
|||
|
||||
// Map<String, Object> parametros = new HashMap<String, Object>();
|
||||
RelatorioPdfAndExcel r = new RelatorioPdfAndExcel(dispositivoVendaEmbarcadaList);
|
||||
File file = r.generateReport(isPdf);
|
||||
// File file = r.generateReport(isPdf);
|
||||
|
||||
InputStream mediais = new ByteArrayInputStream(r.generateReportRender(isPdf));
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm");
|
||||
String nomeRelatorioDownload = NOME_RELATORIO + "_" + sdf.format(Calendar.getInstance().getTime());
|
||||
|
||||
if(isPdf) {
|
||||
InputStream mediais = new FileInputStream(file);
|
||||
// InputStream mediais = new FileInputStream(file);
|
||||
AMedia conteudoRelatorioXLS = new AMedia("relatorio.pdf", "pdf", null, mediais);
|
||||
Filedownload.save(conteudoRelatorioXLS.getStreamData(), "application/pdf", nomeRelatorioDownload + ".pdf");
|
||||
}else {
|
||||
InputStream mediais = new FileInputStream(file);
|
||||
// InputStream mediais = new FileInputStream(file);
|
||||
AMedia conteudoRelatorioXLS = new AMedia("relatorio.xls", "xls", null, mediais);
|
||||
Filedownload.save(conteudoRelatorioXLS.getStreamData(), "application/xls", nomeRelatorioDownload + ".xlsx");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue