Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > J2EE
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old April 26th, 2011, 03:57 PM
Registered User
 
Join Date: Apr 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
Reply With Quote
  #12 (permalink)  
Old December 22nd, 2011, 03:55 AM
Registered User
Points: 6, Level: 1
Points: 6, Level: 1 Points: 6, Level: 1 Points: 6, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?
Reply With Quote
  #13 (permalink)  
Old December 22nd, 2011, 04:56 AM
Registered User
Points: 6, Level: 1
Points: 6, Level: 1 Points: 6, Level: 1 Points: 6, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default In response

exporterXLS.setParameter(JRXlsExporterParameter.IS _IGNORE_GRAPHICS, Boolean.TRUE);

did the magic..
I am getting the values now without graphics..
Reply With Quote
  #14 (permalink)  
Old February 21st, 2012, 05:01 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Post 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 hitesh.kumar@wheebox.com or hitesh.kumar2187@gmail.com
Reply With Quote
  #15 (permalink)  
Old June 12th, 2012, 01:14 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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;

}

}
Reply With Quote
  #16 (permalink)  
Old June 12th, 2013, 10:18 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Sandeep Kumar View Post
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..
Reply With Quote
  #17 (permalink)  
Old July 13th, 2018, 10:58 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2018
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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();
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting data to Excel lrickett Beginning VB 6 3 February 10th, 2011 01:27 AM
Reports in excel using jasper mohanasrini J2EE 1 July 1st, 2009 11:15 AM
help exporting data to excel MarkGT Classic ASP Basics 5 April 29th, 2008 06:13 PM
Crystal Reports not exporting to Word & Excel anand7642 Crystal Reports 1 October 28th, 2006 09:31 AM
Exporting into Excel format using jasper reports raj_plkd Classic ASP Basics 1 February 14th, 2006 07:50 PM



All times are GMT -4. The time now is 02:13 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.