2002 JI Open Discussion Posted August 18, 2006 Share Posted August 18, 2006 By: Kjetil T. - kjetolle How do I make XLS of this? 2003-06-24 05:35 Hi, all! I'm still trying to convert an existing report into XLS format. Below are the basic code elements of my report. The point is that this report works fine, but when I try to use the code samples for converting/filling to XLS, the whole thing stops. As you probably notice, this report creates a PDF file, and I'm using a JRBeanCollectionDataSource instead of a Connection. An object of this report is made from my UI with "TestReport report = new TestReport(date_1, date_2) report.fillReport(); //BASIC CODE ELEMENTS public class TestReport{ public static final String REPORT_NAME = "/reports/TestReport.xml"; public static final String PDF_FILE_NAME = "H:/TestReport.pdf"; JasperReport jasperReport = null; java.sql.Date start; java.sql.Date stop; public TestReport(java.sql.Date startDate, java.sql.Date stopDate) { this(REPORT_NAME); start = startDate; stop = stopDate; } public TestReport(String reportName) { InputStream in = TestReport.class.getResourceAsStream(reportName); if (in == null) { throw new IllegalArgumentException("Can't find report " + reportName); } try { jasperReport = JasperCompileManager.compileReport(in); } catch (JRException jre) { throw new IllegalStateException("Error while compiling report: " + jre); } } public void fillReport() throws EjbHomeFactoryException, javax.ejb.CreateException, javax.ejb.FinderException, java.rmi.RemoteException { Map parameters = new HashMap(); parameters.put("periode", start + " - " + stop); try { EjbHomeFactory ejbHomeFactory = EjbHomeFactory.getFactory(); // In this section I create a collection from JBoss/EJB // skipping the EJB setup code..... List collector = new ArrayList(); List reportCollection = (ArrayList)workFlow.findEJBInfo(start, stop); MyEJB.EJBInfo ejbInfo = new MyEJB.getInfo(); for (int j = 0; j < reportCollection.size(); j++) { ejbInfo = (MyEJB.EJBInfo) reportCollection.get(j); collector.add(ejbInfo); } JasperPrint jasperPrint = JasperManager.fillReport(jasperReport, parameters, new JRBeanCollectionDataSource(collector)); JasperPrintManager.printReportToPdfFile(jasperPrint,PDF_FILE_NAME); JasperViewer.viewReport(jasperPrint, false); } catch (JRException jre) { throw new IllegalStateException("Can't fill report:" + jre); } } Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now