 |
| J2EE General J2EE (Java 2 Enterprise Edition) discussions. Questions not specific to EE will be redirected elsewhere. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the J2EE section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

April 26th, 2011, 03:57 PM
|
|
Registered User
|
|
Join Date: Apr 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
In addition
After following this conversation.. I am able to product the .xls file but the formatting is completely whacked. Is there anything I can do on the front end to make the reports look a little nicer?
-Conner
Excel Reports
|
|

December 22nd, 2011, 03:55 AM
|
|
Registered User
|
|
Join Date: Dec 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Jasper Report excel with no data,but PDF getting generated properly
Hi, I saw couple of post regarding this subject, but I tried the solutions given but it does not work for me.
I am just trying to generate a XLS report out of Jasper with some test data..PDF file is getting generated properly but in the output excel file, I only see the title and column headers but no data. I have xl 2010.
Here is the code which I am trying.
HashMap params = new HashMap();
params.put("ReportTitle","MDS Operational Reports");
JasperPrint jasperPrint = JasperFillManager.fillReport(reportFile.getPath(), params, new JRBeanCollectionDataSource(report));
// JasperExportManager.exportReportToPdfFile(jasperPr int, report_output_pdf);
if(xls){
JRXlsExporter exporterXLS = new JRXlsExporter();
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
FileOutputStream fout = new FileOutputStream(new File(report_output_xls));
exporterXLS.setParameter(JRXlsExporterParameter.JA SPER_PRINT, jasperPrint);
exporterXLS.setParameter(JRXlsExporterParameter.OU TPUT_STREAM, outStream);
exporterXLS.setParameter(JRXlsExporterParameter.IS _ONE_PAGE_PER_SHEET, Boolean.FALSE);
exporterXLS.setParameter(JRXlsExporterParameter.IS _DETECT_CELL_TYPE, Boolean.TRUE);
exporterXLS.setParameter(JRXlsExporterParameter.IS _WHITE_PAGE_BACKGROUND, Boolean.FALSE);
exporterXLS.setParameter(JRXlsExporterParameter.IS _REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
exporterXLS.exportReport();
byte arr[] = outStream.toByteArray();
fout.write(arr);
fout.flush();
fout.close();
outStream.close();
......
And the test data for the data source is
static List<ReportData> getTestData(){
List<ReportData> report = new ArrayList<ReportData>();
for(int i=100;i < 110; i ++){
ReportData obj = new ReportData();
obj.setSourceSystem("Source" + i);
obj.setInfaCount(i*500);
obj.setPubCount(i*520);
obj.setHubCount(i*510);
obj.setDiff(obj.getPubCount() - obj.getHubCount());
report.add(obj);
}
return report;
}
I have C:\jasperreports-4.5.0 and poi-3.7-20101029.jar in the classpath with all the required libraries..
Can somebody please help?
|
|

December 22nd, 2011, 04:56 AM
|
|
Registered User
|
|
Join Date: Dec 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
In response
exporterXLS.setParameter(JRXlsExporterParameter.IS _IGNORE_GRAPHICS, Boolean.TRUE);
did the magic.. 
I am getting the values now without graphics..
|
|

February 21st, 2012, 05:01 AM
|
|
Registered User
|
|
Join Date: Feb 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
In built feature or function of jasper report to generate report in excel/pdf format
hi friends,
I am using jasper report in my project to generate pdf format reports, but now i want to use inbuilt feature of jasper report which ask to user at run time weather to generate report in PDF or In EXCEL format, without coding for excel format, i.e developer (in this case its me) will write code either for generating reports in PDF or in EXCEL but the Jasper Report will ask the user for both formats, if user choose PDF and code is written for generating EXCEL or vise-verse , then the jasper report inbuilt function will automatically generate the report by converting the code at run time on the basis of user choice..
..
so my question is that "is their is any inbuilt function of jasper report which will ask user to choose the format (EXCEL or PDF) at run time and that function will generate the report on that basis", I don't want to re write the whole code for generating EXCEL format as i have already write a huge code to generate report in PDF because of logic implemented in that.
Please help me out..
i want single code which will generate both excel and PDF format on user choice..
if any one have answer please provide me , you can mail me also at [email protected] or [email protected]
|
|

June 12th, 2012, 01:14 AM
|
|
Registered User
|
|
Join Date: Jun 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
i have a problem with My Code. it does not display the output page.
import java.sql.*;
import java.io.*;
import javax.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.sql.DataSource;
import javax.naming.*;
import javax.naming.directory.*;
import java.lang.*;
import oracle.sql.*;
import oracle.jdbc.*;
import java.util.*;
import java.text.*;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.export.*;
import net.sf.jasperreports.j2ee.servlets.ImageServlet;
import net.sf.jasperreports.engine.JRResultSetDataSource;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.view.JasperViewer;
public class LocstnwtsSrv extends HttpServlet
{
public void doPost(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException
{
HttpSession session=request.getSession(true);
String locfrmdt=request.getParameter("txtfrmdate");
String loctodt=request.getParameter("txttodate");
String locstn=(String)session.getAttribute("stnid");
String locreptyp=request.getParameter("cfrmsg");
String locsub=request.getParameter("btnsubmit");
String msg="";
String loctab="";
String ns="";
int nrows=0;
Connection conn = null;
CallableStatement cstmt = null;
try
{
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/myoracle");
conn = ds.getConnection();
if(locsub.equals("(G)ENERATE"))
{
String rptfilename ="";
if(locreptyp.equals("TR"))
{
rptfilename = "/Reports/TRLOCBOOKWT.jasper";
}
else if(locreptyp.equals("BR"))
{
rptfilename = "/Reports/LOCBOOKWT.jasper";
}
HashMap params = new HashMap();
params.put("FRMDT", locfrmdt);
params.put("TODT", loctodt);
params.put("TRCODE", locstn);
JasperPrint jasperPrint = JasperFillManager.fillReport( getServletContext().getRealPath("/") + rptfilename, params,conn);
/*byte[] pdfasbytes = JasperExportManager.exportReportToPdf(jasperPrint) ;
ServletOutputStream outputStream = response.getOutputStream();
response.setContentType("application/pdf");
response.setContentLength(pdfasbytes.length);*/
ByteArrayOutputStream output = new ByteArrayOutputStream();
//OutputStream outputfile= new FileOutputStream(new File("/opt/tomcat/TRANSSHIPMENT/sampleReport.xls"));
JRXlsExporter exporterXLS = new JRXlsExporter();
exporterXLS.setParameter(JRXlsExporterParameter.JA SPER_PRINT, jasperPrint);
exporterXLS.setParameter(JRXlsExporterParameter.OU TPUT_STREAM, output);
exporterXLS.setParameter(JRXlsExporterParameter.IS _ONE_PAGE_PER_SHEET, Boolean.FALSE);
exporterXLS.setParameter(JRXlsExporterParameter.IS _AUTO_DETECT_CELL_TYPE, Boolean.TRUE);
exporterXLS.setParameter(JRXlsExporterParameter.IS _WHITE_PAGE_BACKGROUND, Boolean.FALSE);
exporterXLS.setParameter(JRXlsExporterParameter.IS _REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
ServletOutputStream outputStream = response.getOutputStream();
response.setContentType("application/vnd.ms-excel");
exporterXLS.exportReport();
outputStream.write(output.toByteArray());
outputStream.close();
/*if(locreptyp.equals("TR"))
{
response.setHeader("Content-disposition","inline; filename=\"TRLOCBOOKWT.pdf\"");
}
else if(locreptyp.equals("BR"))
{
response.setHeader("Content-disposition","inline; filename=\"LOCBOOKWT.pdf\"");
}
outputStream.write(pdfasbytes);*/
}
}
catch(SQLException se)
{
se.printStackTrace();
}
catch (NullPointerException np)
{
response.sendRedirect("locstnwts.jsp");
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
try
{
if(conn!=null)
conn.close();
}
catch(SQLException se)
{
se.printStackTrace();
}
}
}
private byte[] exportReportToBytes(JasperPrint jasperPrint, JRExporter exporter) throws JRException
{
byte[] output;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
exporter.setParameter(JRExporterParameter.JASPER_P RINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_S TREAM, baos);
exporter.exportReport();
output = baos.toByteArray();
return output;
}
}
|
|

June 12th, 2013, 10:18 AM
|
|
Registered User
|
|
Join Date: Jun 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by Sandeep Kumar
HI.. I am using Jasper Reports in my project. I am able to get PDF format but when I try to get output in xls form useing JRXlsExporter i am facing some problem thats given below, my code is just below of problem :-
java.lang.reflect.InvocationTargetException
Caused by: java.lang.NoClassDefFoundError: org/apache/poi/hssf/usermodel/HSSFCellStyle
at com.app.webapp.action.ReportAction.viewReportWithP aram(ReportAction.java:74)
public String viewReportWithParam() throws Exception {
byte[] output;
Map parameters = buildParameters();
JasperPrint jasperPrint = reportsManager.generateReport(id, parameters);
HttpServletResponse response = getResponse();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
JRXlsExporter exporterXLS = new JRXlsExporter();
exporterXLS.setParameter(JRXlsExporterParameter.JA SPER_PRINT, jasperPrint);
exporterXLS.setParameter(JRXlsExporterParameter.IS _DETECT_CELL_TYPE, Boolean.TRUE);
exporterXLS.setParameter(JRXlsExporterParameter.IS _WHITE_PAGE_BACKGROUND, Boolean.FALSE);
exporterXLS.setParameter(JRXlsExporterParameter.OU TPUT_STREAM, byteArrayOutputStream);
exporterXLS.exportReport();
response.setContentType("application/vnd.ms-excel");
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(byteArrayOutputStream.toByteArra y());
ouputStream.flush();
ouputStream.close();
return null;
}
Plz Help its Urgent.
Thanks in advance.
<s></s>
|
Created this account just to point out how inept, incompetent developers like this guy who are swarming our Desi IT industry are killing our country's image and name.
Instead of trying to figure out the problem that is fundamental to Java (Classpath)- we post these ridiculous questions that further accentuates Indian IT industry's overall impression of substandard, untrustworthy developers - foreigners when seeing the term "Indian IT Developer" now just scoff and pile scorn because we dont do
a) Any hard work
b) Are not innovative
c) Via reservations or whatever, undeserving non merit candidates who do not have the acumen or intelligence to be in an industry have now swarmed the IT sector and are taking the name of both the country and the IT sector down with them.
This whole thread is filled with Desis who dont have an iota of intelligence or the proper communication skills and unfortunately - these examples are now everywhere!!
Last edited by SixSigma1978; June 12th, 2013 at 10:24 AM..
|
|

July 13th, 2018, 10:58 AM
|
|
Registered User
|
|
Join Date: Jul 2018
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Excel Report in jasper
I am using Jasper Report 6.5.1
jrxml in jasper studio shows the View correctly and I can generate PDF but excel is not correct
PDF Part
JasperReport jasperReport = JasperCompileManager.compileReport(filename);
Map parameters = new HashMap();
parameters.put("ReportPeriod", "07/10/2102");
JasperPrint jasperPrint=JasperFillManager.fillReport(jasperRep ort, parameters, new JREmptyDataSource());
// Create PDF File
JasperExportManager.exportReportToPdfFile(jasperPr int, "C:\\Users\\ssingh3\\Desktop\\temp\\jasper\\Checks Cancelled.pdf");
Excel
ByteArrayOutputStream outputByteArray = new ByteArrayOutputStream();
OutputStream out = new FileOutputStream(new File("C:\\Users\\ssingh3\\Desktop\\temp\\jasper\\C hecksCancelled.xls"));
SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration();
configuration.setOnePagePerSheet(false);
configuration.setDetectCellType(true);
configuration.setCollapseRowSpan(false);
JRXlsExporter exporter = new JRXlsExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(out));
exporter.setConfiguration(configuration);
exporter.exportReport();
|
|
 |