Jump to content
We've recently updated our Privacy Statement, available here ×

not showing image when exporting to excel


Recommended Posts

By: sanforum - sanforum

not showing image when exporting to excel

2006-01-05 01:24

The following is the code to generate report in excel format.

It works fine for reports having texts only..

But when it produce reports having image it is not showing the image...

the image file path is written in the .JRXML file which is compiled to .JASPER file from which the report is generated in Excel in jsp

 

The code for generating the reports in Jsp in Excel format......

 

<%@page contentType="application/vnd.ms-excel"%>

<%@ page errorPage="error.jsp" %>

<%@ page import="net.sf.jasperreports.engine.*" %>

<%@ page import="net.sf.jasperreports.engine.util.*" %>

<%@ page import="net.sf.jasperreports.engine.export.*" %>

<%@ page import="java.util.*" %>

<%@ page import="java.io.*" %>

<%@ page import="java.sql.*" %>

 

<%

//response.setHeader("CACHE-CONTROL","NO-CACHE");

//response.setHeader("EXPIRES","0");

//response.setHeader("PRAGMA","NO-CACHE");

//CreateXml cml=(CreateXml) request.getAttribute("REPORT_BEAN");

//String reportName = cml.getReportName();

String reportName=request.getParameter("reportName");

 

try

{

Class.forName("org.gjt.mm.mysql.Driver");

Connection conn=DriverManager.getConnection("jdbc:mysql://sfindiajv4:3306/track_master","root","admin");

// File reportFile = new File("./usertemplates/test.jasper");

File reportFile = new File("./usertemplates/"+reportName+".jasper");

String abspath = reportFile.getAbsolutePath(); //tried getAbsolutePath()

String path = reportFile.getPath();

System.out.println("Absolute Path = " + reportFile.getAbsolutePath());

System.out.println(" Path = " + reportFile.getPath());

Map parameters = new HashMap();

parameters.put("BaseDir", reportFile.getParentFile());

//parameters.put("myparam",new Integer(2));

JasperPrint jasperPrint = JasperManager.fillReport ( path,parameters, new net.sf.jasperreports.engine.JREmptyDataSource());

byte bytes[] = new byte[10000];

//String result = JasperRunManager.runReportToHtmlFile("./usertemplates/test.jasper" , parameters, conn);

JRXlsExporter exporter = new JRXlsExporter();

 

ByteArrayOutputStream xlsReport = new ByteArrayOutputStream();

exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, xlsReport);

exporter.exportReport();

System.out.println("Size of byte array:"+xlsReport.size());

bytes = xlsReport.toByteArray();

response.setContentType("application/vnd.ms-excel");

System.out.println("After JasperPrint = 1");

response.setContentLength(bytes.length);

System.out.println("After JasperPrint = 2");

xlsReport.close();

System.out.println("After JasperPrint = 3");

 

OutputStream ouputStream = response.getOutputStream();

System.out.println("After JasperPrint = 4");

ouputStream.write(bytes, 0, bytes.length);

ouputStream.flush();

ouputStream.close();

}

catch(Exception e)

{e.printStackTrace();}

 

%>

 

 

 

 

 

 

 

By: Lucian Chirita - lucianc

RE: not showing image when exporting to excel

2006-01-05 03:13

http://jasperreports.sourceforge.net/faq.html#faq5

 

You could try the JExcelApi based exporter provided as sample.

 

HTH,

Lucian

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...