2005 IR Help Posted August 26, 2006 Share Posted August 26, 2006 By: gromeroq - gromeroq Urgent Problem exporting to .xls file 2004-06-22 15:13 I need to export to different formats, it works fine for pdf files, and tab delimited files but when I need to export to .xls file I have a java.lang.ClassCastException. Here is the code: String fileName = c.getSelectedFile().getAbsolutePath(); FileFilter filter = c.getFileFilter(); String ext = getExtension(c.getSelectedFile()); if (ext.equals("pdf") || filter == pdf) { setBusy(true); try { JasperExportManager.exportReportToPdfFile(_screen.getJasperPrint(), fileName); } catch (JRException e1) { e1.printStackTrace(); } setBusy(false); break; } else if (ext.equals("xls") || filter == xls) { setBusy(true); try{ JRXlsExporter exporter = new JRXlsExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, _screen.getJasperPrint()); //exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, fileName); exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE); exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, new File(fileName + ".xls") ); exporter.exportReport(); }catch (JRException e1){ e1.printStackTrace(); } setBusy(false); break; } else if (ext.equals("dat") || filter == tab) { setBusy(true); try { PrintWriter pw = new PrintWriter(new FileOutputStream(fileName)); _ds.export(DataStoreBuffer.EXPORT_TAB_DELIMITED, true, pw); pw.close(); } catch (FileNotFoundException e1) { e1.printStackTrace(); } setBusy(false); break; } When I run the application I have the following error: java.lang.ClassCastException at dori.jasper.engine.export.JRXlsExporter.exportReport(JRXlsExporter.java:251) at com.salmonllc.jasperReports.SJasperViewToolBar$ExportAction.actionPerformed(SJasperViewToolBar.java:209) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source) Am I missing something? Please I need your help. By: Gregory A. Swarthout - gswarthout RE: Urgent Problem exporting to .xls file 2004-06-22 15:28 My guess is that this line is the problem: exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, new File(fileName + ".xls") ); I think the OUTPUT_FILE_NAME is suppsed to be a String, but you are passing in a File By: gromeroq - gromeroq RE: Urgent Problem exporting to .xls file 2004-06-24 06:58 Thanks that was the problem. I run again my application but I have another error: java.lang.NoSuchMethodError: org.apache.poi.hssf.usermodel.HSSFSheet.createRow(S)Lorg/apache/poi/hssf/usermodel/HSSFRow; at dori.jasper.engine.export.JRXlsExporter.exportPage(JRXlsExporter.java:386) at dori.jasper.engine.export.JRXlsExporter.exportReportToStream(JRXlsExporter.java:319) at dori.jasper.engine.export.JRXlsExporter.exportReport(JRXlsExporter.java:282) at com.salmonllc.jasperReports.SJasperViewToolBar$ExportAction.actionPerformed(SJasperViewToolBar.java:209) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source) I am using POI jar version: 1.5.1-final-20020615!! That version is correct? 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