Reputation: 1253
I am new to jasper reports
. I am able export data through Jasper reports to an excel sheet. When I created a pie chart in iReports
, it was showing on preview. When I write a below code in jsp
file to view report in JasperViewer
, it shows data along with chart. But when I try to save that document (that is in JasperViewer, which gives many ways of saving a report either in PDF or RTF or XLS) as XLS then error came in console
net.sf.jasperreports.engine.JRException: The cell cannot be added.
however when i remove chart from .jrxml file, then I am able to export data to excel file. I also read some where that JR chart is inserted as an image in excel document. But xls document is not taking any images. Below is my JSP file:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" import="java.sql.*,java.util.*,
net.sf.jasperreports.engine.*,java.io.*,
net.sf.jasperreports.engine.design.*,
net.sf.jasperreports.view.JasperViewer" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3309/jasperdb", "root", "root");
FileInputStream fis=new FileInputStream(new File("C://Documents and Settings//james//report1.jrxml"));
JasperReport jasperreport=JasperCompileManager.compileReport(fis);
JasperPrint jasperprint=JasperFillManager.fillReport(jasperreport,null,con);
JasperViewer jv=new JasperViewer(jasperprint,false);
jv.setTitle("test");
jv.setIconImage(null);
jv.setVisible(true);
}catch(Exception ex){
ex.printStackTrace();
}
%>
</body>
</html>
when I click on save button and choose xls as my report to save then the following error comes in console:
net.sf.jasperreports.engine.JRException: The cell cannot be added.
at net.sf.jasperreports.engine.export.JRXlsExporter.exportImage(JRXlsExporter.java:1683)
at net.sf.jasperreports.engine.export.JRXlsAbstractExporter.exportPage(JRXlsAbstractExporter.java:1047)
at net.sf.jasperreports.engine.export.JRXlsAbstractExporter.exportReportToStream(JRXlsAbstractExporter.java:831)
at net.sf.jasperreports.engine.export.JRXlsAbstractExporter.exportReport(JRXlsAbstractExporter.java:678)
at net.sf.jasperreports.view.save.JRSingleSheetXlsSaveContributor.save(JRSingleSheetXlsSaveContributor.java:123)
at net.sf.jasperreports.swing.JRViewerToolbar.btnSaveActionPerformed(JRViewerToolbar.java:406)
at net.sf.jasperreports.swing.JRViewerToolbar$1.actionPerformed(JRViewerToolbar.java:136)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.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 javax.swing.JComponent.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.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(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)
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/codec/digest/DigestUtils
at org.apache.poi.hssf.usermodel.HSSFWorkbook.addPicture(HSSFWorkbook.java:1610)
at net.sf.jasperreports.engine.export.JRXlsExporter.exportImage(JRXlsExporter.java:1667)
... 43 more
Caused by: java.lang.ClassNotFoundException: org.apache.commons.codec.digest.DigestUtils
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
... 45 more
This is happening just due to the chart image. Guide me how can I export chart as image in xls document with rest of data.
Upvotes: 0
Views: 1364
Reputation: 1253
Oh! I am such a stupid. The console error at very bottom is screaming and telling about class not found exception for Caused by: java.lang.ClassNotFoundException: org.apache.commons.codec.digest.DigestUtils
To resolve it I downloaded commons-codec-1.4.jar
file and placed in web-inf lib folder. Everything is working fine now.
Upvotes: 2