Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 14th, 2006, 09:15 AM
Authorized User
 
Join Date: Aug 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Exporting into Excel format using jasper reports

Hi I am Using Jasper Reports In my project and i have created .jrxml file and i am able to Export the report in to PDF ( with data) but same code i am not able export in EXCel . The File is getting generated with No data .

Please Guide me Regarding this.

This Is My File (stockroom.jrxml)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport name="DataSourceReport" pageWidth="595" pageHeight="842" columnWidth="515" leftMargin="40" rightMargin="40" topMargin="50" bottomMargin="50">
<style name="Arial_Normal" isDefault="true" fontName="Arial" fontSize="12" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
<style name="Arial_Bold" isDefault="false" fontName="Arial" fontSize="12" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica-Bold" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
<style name="Arial_Italic" isDefault="false" fontName="Arial" fontSize="12" isBold="false" isItalic="true" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica-Oblique" pdfEncoding="Cp1252" isPdfEmbedded="false"/>

<field name="STOCKROOM_ID" class="java.lang.Integer">
</field>
<field name="STOCKROOM_NAME" class="java.lang.String">
</field>
<field name="STOCKROOM_DESC" class="java.lang.String">
</field>

<pageHeader>
<band height="20">

<staticText>
<reportElement mode="Opaque" x="0" y="5" width="55" height="15" forecolor="#ffffff" backcolor="#333333" style="Arial_Bold"/>
<textElement textAlignment="Center"/>
<text><![CDATA[STOCKROOM_ID]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="55" y="5" width="205" height="15" forecolor="#ffffff" backcolor="#333333" style="Arial_Bold"/>
<text><![CDATA[STOCKROOM_NAME]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="260" y="5" width="255" height="15" forecolor="#ffffff" backcolor="#333333" style="Arial_Bold"/>
<text><![CDATA[STOCKROOM_DESC]]></text>
</staticText>

</band>

</pageHeader>
<detail>
<band height="15">
<textField bookmarkLevel="2">
<reportElement x="0" y="0" width="50" height="15"/>
<box leftBorder="Thin" bottomBorder="Thin" leftPadding="10" rightPadding="10"/>
<textElement textAlignment="Right"/>
<textFieldExpression class="java.lang.Integer"><![CDATA[$F{STOCKROOM_ID}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement positionType="Float" x="50" y="0" width="200" height="15"/>
<box leftBorder="Thin" bottomBorder="Thin" leftPadding="10" rightPadding="10"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{STOCKROOM_NAME}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement positionType="Float" x="250" y="0" width="265" height="15"/>
<box leftBorder="Thin" bottomBorder="Thin" rightBorder="Thin" leftPadding="10" rightPadding="10"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{STOCKROOM_DESC}]]></textFieldExpression>
</textField>




</band>
</detail>
</jasperReport>
------------------------------------------------------------------

And This My Java Jasper Program for PDF:

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;

import net.sf.jasperreports.engine.JRResultSetDataSource;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.view.JasperViewer;

public class JasperReportDemo
{
public static void main(String[] args) throws SQLException, FileNotFoundException,
IllegalAccessException, ClassNotFoundException,Exception
{

try
{

final String driverClass = "xxxxxxxxxxxxxxxxxx";
final String connectionURL = "xxxxxxxxxxxx ";
final String userID = "xxxxxxxxxxx";
final String userPassword = "zzzzzzzzzzzz";
Connection con = null;
Statement stmt = null;
ResultSet rset = null;
Class.forName(driverClass).newInstance();
con = DriverManager.getConnection(connectionURL, userID, userPassword);
String queryString = "SELECT STOCKROOM_ID, STOCKROOM_NAME, STOCKROOM_DESC "
+ "FROM stockroom ";
stmt = con.createStatement();
rset = stmt.executeQuery(queryString);
InputStream input = new FileInputStream(new File("c:/stockroom.xml"));
JasperDesign design = JRXmlLoader.load(input);
JasperReport report = JasperCompileManager.compileReport(design);
JRResultSetDataSource jasperReports = new JRResultSetDataSource(rset);
JasperPrint print = JasperFillManager.fillReport(report, new HashMap(), jasperReports);
long start = System.currentTimeMillis();

OutputStream output = new FileOutputStream(new File("c:/output/JasperReport.pdf"));
JasperExportManager.exportReportToPdfStream(print, output);

// coding For Excel:


JRXlsExporter exporterXLS = new JRXlsExporter();
exporterXLS.setParameter(JRXlsExporterParameter.JA SPER_PRINT, print);
exporterXLS.setParameter(JRXlsExporterParameter.OU TPUT_STREAM, output);
exporterXLS.setParameter(JRXlsExporterParameter.IS _ONE_PAGE_PER_SHEET, Boolean.TRUE);
exporterXLS.setParameter(JRXlsExporterParameter.IS _AUTO_DETECT_CELL_TYPE, Boolean.TRUE);
exporterXLS.setParameter(JRXlsExporterParameter.IS _WHITE_PAGE_BACKGROUND, Boolean.FALSE);
exporterXLS.setParameter(JRXlsExporterParameter.IS _REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
exporterXLS.exportReport();



---------------------------------------------------------------
I want to know why it is generating an empty Excel file without data.
Please help me.


 
Old February 14th, 2006, 07:50 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default

I personally don't use Jasper, but have used the items mentioned at http://www.greggriffiths.org/webdev/both/excel/ before and they work, also there are plenty of hits in Google for searches containing XML and Excel which should get you started.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting data into Excel using jasper reports raj_plkd J2EE 16 July 13th, 2018 10:58 AM
Reports in excel using jasper mohanasrini J2EE 1 July 1st, 2009 11:15 AM
Crystal Reports not exporting to Word & Excel anand7642 Crystal Reports 1 October 28th, 2006 09:31 AM
jasper reports hrishi BOOK: Beginning JavaServer Pages 0 May 29th, 2006 04:51 AM
New to jasper reports venz98 J2EE 4 March 9th, 2006 10:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.