我是jasper reports
的新手。我可以通過Jasper報告將數據導出到Excel表格。當我在iReports
中創建餅圖時,它在預覽中顯示。當我在jsp
文件中編寫以下代碼以查看JasperViewer
中的報告時,它會顯示數據以及圖表。但是,當我試圖保存文件(即在JasperViewer,這給節能無論是在PDF或RTF或XLS報告的許多方面)爲XLS然後在控制檯來到錯誤使用jasper報告無法在xls文檔中顯示圖表
net.sf.jasperreports.engine.JRException: The cell cannot be added.
然而,當我從刪除圖表.jrxml文件,然後我能夠將數據導出到excel文件。我還讀了一些在Excel文檔中插入JR圖表作爲圖像的位置。但xls文件沒有拍攝任何圖像。下面是我的JSP文件:
<%@ 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>
當我點擊保存按鈕,然後選擇XLS爲我的報告,以節省那麼下面的錯誤出現在控制檯:
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
這只是由於圖表圖像而發生的。指導我如何將圖表導出爲xls文檔中的圖像和其餘數據。