Jump to content
We've recently updated our Privacy Statement, available here ×

Problem while exporting report to HTML format


Recommended Posts

By: Gopalakrishnan - gopkrish3

Problem while exporting report to HTML format

2004-07-14 21:18

Hai Giulio

I tried creating a report using XML as the datasource.

The report contains two columns 'name' and 'job'.

I used JRXMLDataSource class to load the xml and i exported report to HTML and PDF format. Both the files are created successfully, but only 'job' column is displayed in the HTML file and both the columns are displayed in the PDF file. I don't know how it missed out the 'name' column. i tried to figure it out but i can't able to.

Please help me to resolve this.

 

Java file

=========

import dori.jasper.engine.export.JRPdfExporter;

import dori.jasper.engine.export.JRHtmlExporter;

import dori.jasper.engine.*;

import java.util.HashMap;

 

 

public class XMLTester {

 

public static void main(String[] args) throws dori.jasper.engine.JRException {

String reportFileName = "/XMLTest.jasper";

String outFileName = "/XMLTest.html";

String xmlFileName = "/XMLTest.xml";

String recordPath = "/employees/employee/";

 

try

{

HashMap hm = new HashMap();

JasperCompileManager.compileReportToFile("/XMLTest.jrxml");

JRXMLDataSource jrxmlds = new JRXMLDataSource(xmlFileName,recordPath);

JasperPrint print = JasperFillManager.fillReport(

reportFileName,

hm,

jrxmlds);

JasperExportManager.exportReportToHtmlFile(print, "D:/XMLTest.html");

JasperExportManager.exportReportToPdfFile(print, "D:/XMLTest.pdf");

System.out.println("Completed");

}

catch (JRException e)

{

e.printStackTrace();

System.exit(1);

}

catch (Exception e)

{

e.printStackTrace();

System.exit(1);

}

 

}

 

}

 

JRXML File

==========

 

<?xml version="1.0" encoding="UTF-8" ?>

<!-- Created with iReport - A designer for JasperReports -->

<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd";>

<jasperReport

name="XMLTest"

columnCount="1"

printOrder="Vertical"

orientation="Portrait"

pageWidth="595"

pageHeight="842"

columnWidth="535"

columnSpacing="0"

leftMargin="30"

rightMargin="30"

topMargin="20"

bottomMargin="20"

whenNoDataType="NoPages"

isTitleNewPage="false"

isSummaryNewPage="false">

<property name="ireport.scriptlethandling" value="2" />

<queryString><![CDATA[sELECT ENAME,JOB FROM EMP]]></queryString>

<field name="ENAME" class="java.lang.String">

<fieldDescription><![CDATA[/employees/employee@ename]]></fieldDescription>

</field>

<field name="JOB" class="java.lang.String">

<fieldDescription><![CDATA[/employees/employee+JOB]]></fieldDescription>

</field>

<background>

<band height="0" isSplitAllowed="true" >

</band>

</background>

<title>

<band height="50" isSplitAllowed="true" >

</band>

</title>

<pageHeader>

<band height="50" isSplitAllowed="true" >

</band>

</pageHeader>

<columnHeader>

<band height="30" isSplitAllowed="true" >

</band>

</columnHeader>

<detail>

<band height="25" isSplitAllowed="true" >

<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" >

<reportElement

mode="Opaque"

x="55"

y="0"

width="173"

height="18"

forecolor="#000000"

backcolor="#FFFFFF"

key="element-1"

stretchType="NoStretch"

positionType="FixRelativeToTop"

isPrintRepeatedValues="true"

isRemoveLineWhenBlank="false"

isPrintInFirstWholeBand="false"

isPrintWhenDetailOverflows="false"/>

<textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single">

<font fontName="Arial" pdfFontName="Helvetica" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1252" isStrikeThrough="false" />

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA[$F{ENAME}]]></textFieldExpression>

</textField>

<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" >

<reportElement

mode="Opaque"

x="200"

y="0"

width="100"

height="18"

forecolor="#000000"

backcolor="#FFFFFF"

key="element-5"

stretchType="NoStretch"

positionType="FixRelativeToTop"

isPrintRepeatedValues="true"

isRemoveLineWhenBlank="false"

isPrintInFirstWholeBand="false"

isPrintWhenDetailOverflows="false"/>

<textElement textAlignment="Left" verticalAlignment="Top" rotation="None" lineSpacing="Single">

<font fontName="Arial" pdfFontName="Helvetica" size="10" isBold="false" isItalic="false" isUnderline="false" isPdfEmbedded ="false" pdfEncoding ="Cp1252" isStrikeThrough="false" />

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA[$F{JOB}]]></textFieldExpression>

</textField>

</band>

</detail>

<columnFooter>

<band height="30" isSplitAllowed="true" >

</band>

</columnFooter>

<pageFooter>

<band height="50" isSplitAllowed="true" >

</band>

</pageFooter>

<summary>

<band height="28" isSplitAllowed="true" >

</band>

</summary>

</jasperReport>

 

 

XML file

========

<employees>

<employee ename="Gopal">

<JOB>Manager</JOB>

</employee>

<employee ename="Krishnan">

<JOB>President</JOB>

</employee>

<employee ename="GopKrish">

<JOB>Clerk</JOB>

</employee>

</employees>

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...