I'm using JasperViewer
to show the report to the user and to be able to export to pdf
, word
and Excel
.
The problem is while saving to Excel
, and error prompts saying:
Exception in thread "AWT-EventQueue-0" java.lang.VerifyError: (class: net/sf/jasperreports/engine/export/JRXlsExporter,
method: createMergeRegion signature: (Lnet/sf/jasperreports/engine/export/JRExporterGridCell;IILorg/apache/poi/hssf/usermodel/HSSFCellStyle;)V) Incompatible argument to function
at net.sf.jasperreports.view.save.JRSingleSheetXlsSaveContributo开发者_Go百科r.save(JRSingleSheetXlsSaveContributor.java:104)
at net.sf.jasperreports.swing.JRViewerToolbar.btnSaveActionPerformed(JRViewerToolbar.java:407)
Here's the code I'm using to show my report:
public void showReport() throws SQLException {
RNVehicle rnVehicle = new RNVehicle();
vehicles.clear();
vehicles= rnVehicle.getVehiculos();
//Path to your .jasper file in your package
String reportName = "reports/ReportVehicles.jasper";
//Get a stream to read the file
InputStream is = this.getClass().getClassLoader().getResourceAsStream(reportName);
try {
JasperPrint jp = JasperFillManager.fillReport(is, null, new JRBeanCollectionDataSource(vehicles));
//Viewer for JasperReport
JRViewer jv = new JRViewer(jp);
//Insert viewer to a JFrame to make it showable
JFrame jf = new JFrame();
jf.getContentPane().add(jv);
jf.validate();
jf.setVisible(true);
jf.setSize(new Dimension(1020, 755));
jf.setLocation(0, 0);
jf.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
} catch (JRException ex) {
ex.printStackTrace();
}
}
I'm desperate :( , why is not running? What changes should I make? Or what libraries should I import to the project to make it run?
At the moment I have: poi-3.6.jar
(the one that comes with the JR distribution), I also tried with previous versions, 3.5 and 3.2 and with all of them everything works fine, but just for html, pdf and word, not for Excel.
Any insight on this regard will be helpful.
You need to add "poi-3.10.1.jar" in your project.
If you can get it into a CSV and open it in notepad++ or something similar, do a find and replace for ,, (two commas in a row) and replace it with something like a dash as a place holder. That's messed me up before. after that, you can pull it into an array in the language of your choice and manipulate it from there.
for Excel exporting needed jxl library. Commonly JasperReports want commons-collections, commons-beanutils and commons-digester
As Adel said, works good with specific "poi-3.10.1.jar" version.
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.10.1</version>
</dependency>
精彩评论