2004 IR Help Posted September 2, 2006 Share Posted September 2, 2006 By: Gopalakrishnan - gopkrish3 Problem while exporting report to HTML format 2004-07-14 02:40 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> By: olivier849 - olivier849 RE: Problem while exporting report to HTML format 2004-07-15 00:35 In order to have an HTML output with all the elements of the report thoses elements must be disposed without overlaping another element (a table display, each element has it's own zone to display), when I look to your report I see that the ENAME field begins at 55 and is 173 long, it means that the JOB begining at 200 overlap it (55 + 173 = 228), so when the JOB zone is drawn it overlaps the ENAME zone (wich makes it disappear in an HTML output, but is correctly displayed in a PDF output). Try having no crossing zone between the elements and then you'll get a correct HTML output. I hope that helps, Olivier By: Gopalakrishnan - gopkrish3 RE: Problem while exporting report to HTML format 2004-07-15 20:56 Thanks Now its working Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now