hi everyone,my problem is that i want to export data from bean in excel format,the code below is correct and i have the data in the excel document but the name of columns and ether data is deprecated just 6 first letters are generated! for example i have departement column but it is just depart in my file,and also the width of the columns is short and not suitable to data,plzzz help me it's my fourth day trying to resolve this problem
this is my class Consultationficheexcel
public class Consultationficheexcel implements java.io.Serializable { private String codefiche; private String matricule; private String nom; private String grade; private String departement; private String formation; private String avisdelaprrecie; private String avisdelappreciateur; private String fonction; private String commentairefonction; private String conditionsdetravail; private String commentaireconditionsdetravail; private String deroulementdelentr; private String commentairederoulementdelentr; private String avisn2; private BigDecimal note; public Consultationficheexcel() { } public Consultationficheexcel(String codefiche, String matricule, String nom, String departement) { this.codefiche = codefiche; this.matricule = matricule; this.nom = nom; this.departement = departement; } public Consultationficheexcel(String codefiche, String matricule, String nom, String grade, String departement, String formation, String avisdelaprrecie, String avisdelappreciateur, String fonction, String commentairefonction, String conditionsdetravail, String commentaireconditionsdetravail, String deroulementdelentr, String commentairederoulementdelentr, String avisn2, BigDecimal note) { this.codefiche = codefiche; this.matricule = matricule; this.nom = nom; this.grade = grade; this.departement = departement; this.formation = formation; this.avisdelaprrecie = avisdelaprrecie; this.avisdelappreciateur = avisdelappreciateur; this.fonction = fonction; this.commentairefonction = commentairefonction; this.conditionsdetravail = conditionsdetravail; this.commentaireconditionsdetravail = commentaireconditionsdetravail; this.deroulementdelentr = deroulementdelentr; this.commentairederoulementdelentr = commentairederoulementdelentr; this.avisn2 = avisn2; this.note = note; } @Id @Column(name = "CODEFICHE", nullable = false, length = 500) public String getCodefiche() { return this.codefiche; } public void setCodefiche(String codefiche) { this.codefiche = codefiche; } @Column(name = "MATRICULE", nullable = false, length = 500) public String getMatricule() { return this.matricule; } public void setMatricule(String matricule) { this.matricule = matricule; } @Column(name = "NOM", nullable = false, length = 500) public String getNom() { return this.nom; } public void setNom(String nom) { this.nom = nom; } @Column(name = "GRADE", length = 500) public String getGrade() { return this.grade; } public void setGrade(String grade) { this.grade = grade; } @Column(name = "DEPARTEMENT", nullable = false, length = 500) public String getDepartement() { return this.departement; } public void setDepartement(String departement) { this.departement = departement; } @Column(name = "FORMATION", length = 500) public String getFormation() { return this.formation; } public void setFormation(String formation) { this.formation = formation; } @Column(name = "AVISDELAPRRECIE", length = 500) public String getAvisdelaprrecie() { return this.avisdelaprrecie; } public void setAvisdelaprrecie(String avisdelaprrecie) { this.avisdelaprrecie = avisdelaprrecie; } @Column(name = "AVISDELAPPRECIATEUR", length = 500) public String getAvisdelappreciateur() { return this.avisdelappreciateur; } public void setAvisdelappreciateur(String avisdelappreciateur) { this.avisdelappreciateur = avisdelappreciateur; } @Column(name = "FONCTION", length = 500) public String getFonction() { return this.fonction; } public void setFonction(String fonction) { this.fonction = fonction; } @Column(name = "COMMENTAIREFONCTION", length = 500) public String getCommentairefonction() { return this.commentairefonction; } public void setCommentairefonction(String commentairefonction) { this.commentairefonction = commentairefonction; } @Column(name = "CONDITIONSDETRAVAIL", length = 500) public String getConditionsdetravail() { return this.conditionsdetravail; } public void setConditionsdetravail(String conditionsdetravail) { this.conditionsdetravail = conditionsdetravail; } @Column(name = "COMMENTAIRECONDITIONSDETRAVAIL", length = 500) public String getCommentaireconditionsdetravail() { return this.commentaireconditionsdetravail; } public void setCommentaireconditionsdetravail( String commentaireconditionsdetravail) { this.commentaireconditionsdetravail = commentaireconditionsdetravail; } @Column(name = "DEROULEMENTDELENTR", length = 500) public String getDeroulementdelentr() { return this.deroulementdelentr; } public void setDeroulementdelentr(String deroulementdelentr) { this.deroulementdelentr = deroulementdelentr; } @Column(name = "COMMENTAIREDEROULEMENTDELENTR", length = 500) public String getCommentairederoulementdelentr() { return this.commentairederoulementdelentr; } public void setCommentairederoulementdelentr( String commentairederoulementdelentr) { this.commentairederoulementdelentr = commentairederoulementdelentr; } @Column(name = "AVISN2", length = 500) public String getAvisn2() { return this.avisn2; } public void setAvisn2(String avisn2) { this.avisn2 = avisn2; } @Column(name = "NOTE", precision = 4) public BigDecimal getNote() { return this.note; } public void setNote(BigDecimal note) { this.note = note; } public boolean equals(Object other) { if ((this == other)) return true; if ((other == null)) return false; if (!(other instanceof ConsultationficheexcelId)) return false; ConsultationficheexcelId castOther = (ConsultationficheexcelId) other; return ((this.getCodefiche() == castOther.getCodefiche()) || (this .getCodefiche() != null && castOther.getCodefiche() != null && this .getCodefiche().equals(castOther.getCodefiche()))) && ((this.getMatricule() == castOther.getMatricule()) || (this .getMatricule() != null && castOther.getMatricule() != null && this .getMatricule().equals(castOther.getMatricule()))) && ((this.getNom() == castOther.getNom()) || (this.getNom() != null && castOther.getNom() != null && this.getNom().equals( castOther.getNom()))) && ((this.getGrade() == castOther.getGrade()) || (this .getGrade() != null && castOther.getGrade() != null && this .getGrade().equals(castOther.getGrade()))) && ((this.getDepartement() == castOther.getDepartement()) || (this .getDepartement() != null && castOther.getDepartement() != null && this .getDepartement().equals(castOther.getDepartement()))) && ((this.getFormation() == castOther.getFormation()) || (this .getFormation() != null && castOther.getFormation() != null && this .getFormation().equals(castOther.getFormation()))) && ((this.getAvisdelaprrecie() == castOther .getAvisdelaprrecie()) || (this.getAvisdelaprrecie() != null && castOther.getAvisdelaprrecie() != null && this .getAvisdelaprrecie().equals( castOther.getAvisdelaprrecie()))) && ((this.getAvisdelappreciateur() == castOther .getAvisdelappreciateur()) || (this .getAvisdelappreciateur() != null && castOther.getAvisdelappreciateur() != null && this .getAvisdelappreciateur().equals( castOther.getAvisdelappreciateur()))) && ((this.getFonction() == castOther.getFonction()) || (this .getFonction() != null && castOther.getFonction() != null && this .getFonction().equals(castOther.getFonction()))) && ((this.getCommentairefonction() == castOther .getCommentairefonction()) || (this .getCommentairefonction() != null && castOther.getCommentairefonction() != null && this .getCommentairefonction().equals( castOther.getCommentairefonction()))) && ((this.getConditionsdetravail() == castOther .getConditionsdetravail()) || (this .getConditionsdetravail() != null && castOther.getConditionsdetravail() != null && this .getConditionsdetravail().equals( castOther.getConditionsdetravail()))) && ((this.getCommentaireconditionsdetravail() == castOther .getCommentaireconditionsdetravail()) || (this .getCommentaireconditionsdetravail() != null && castOther.getCommentaireconditionsdetravail() != null && this .getCommentaireconditionsdetravail().equals( castOther.getCommentaireconditionsdetravail()))) && ((this.getDeroulementdelentr() == castOther .getDeroulementdelentr()) || (this .getDeroulementdelentr() != null && castOther.getDeroulementdelentr() != null && this .getDeroulementdelentr().equals( castOther.getDeroulementdelentr()))) && ((this.getCommentairederoulementdelentr() == castOther .getCommentairederoulementdelentr()) || (this .getCommentairederoulementdelentr() != null && castOther.getCommentairederoulementdelentr() != null && this .getCommentairederoulementdelentr().equals( castOther.getCommentairederoulementdelentr()))) && ((this.getAvisn2() == castOther.getAvisn2()) || (this .getAvisn2() != null && castOther.getAvisn2() != null && this .getAvisn2().equals(castOther.getAvisn2()))) && ((this.getNote() == castOther.getNote()) || (this.getNote() != null && castOther.getNote() != null && this.getNote() .equals(castOther.getNote()))); } public int hashCode() { int result = 17; result = 37 * result + (getCodefiche() == null ? 0 : this.getCodefiche().hashCode()); result = 37 * result + (getMatricule() == null ? 0 : this.getMatricule().hashCode()); result = 37 * result + (getNom() == null ? 0 : this.getNom().hashCode()); result = 37 * result + (getGrade() == null ? 0 : this.getGrade().hashCode()); result = 37 * result + (getDepartement() == null ? 0 : this.getDepartement() .hashCode()); result = 37 * result + (getFormation() == null ? 0 : this.getFormation().hashCode()); result = 37 * result + (getAvisdelaprrecie() == null ? 0 : this.getAvisdelaprrecie() .hashCode()); result = 37 * result + (getAvisdelappreciateur() == null ? 0 : this .getAvisdelappreciateur().hashCode()); result = 37 * result + (getFonction() == null ? 0 : this.getFonction().hashCode()); result = 37 * result + (getCommentairefonction() == null ? 0 : this .getCommentairefonction().hashCode()); result = 37 * result + (getConditionsdetravail() == null ? 0 : this .getConditionsdetravail().hashCode()); result = 37 * result + (getCommentaireconditionsdetravail() == null ? 0 : this .getCommentaireconditionsdetravail().hashCode()); result = 37 * result + (getDeroulementdelentr() == null ? 0 : this .getDeroulementdelentr().hashCode()); result = 37 * result + (getCommentairederoulementdelentr() == null ? 0 : this .getCommentairederoulementdelentr().hashCode()); result = 37 * result + (getAvisn2() == null ? 0 : this.getAvisn2().hashCode()); result = 37 * result + (getNote() == null ? 0 : this.getNote().hashCode()); return result; } }
method for export consultationficheexcelList is list of consultationficheexcel
public void viewReportExcel() throws SQLException, JRException, IOException { String sourceFileName = "C:\\Users\\ighachane\\Desktop\\impression.jasper"; String printFileName = null; JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(consultationficheexcelList); Map parameters = new HashMap(); try { printFileName = JasperFillManager.fillReportToFile(sourceFileName, parameters, beanColDataSource); if (printFileName != null) { /** * export to Excel sheet */ JRXlsExporter exporter = new JRXlsExporter(); exporter.setParameter(JRExporterParameter.INPUT_FILE_NAME, printFileName); exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "D://sample_report.xls"); exporter.exportReport(); } } catch (JRException e) { e.printStackTrace(); } }
and this is my template jrxml
<?xml version="1.0" encoding="UTF-8"?> <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="jasper_report_template" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="f05cec4b-347d-4f60-80e8-edbd5e182441"> <property name="ireport.zoom" value="1.0"/> <property name="ireport.x" value="0"/> <property name="ireport.y" value="0"/> <queryString> <![CDATA[]]> </queryString> <field name="matricule" class="java.lang.String"> <fieldDescription><![CDATA[country]]></fieldDescription> </field> <field name="grade" class="java.lang.String"> <fieldDescription><![CDATA[name]]></fieldDescription> </field> <columnHeader> <band height="23" splitType="Stretch"> <staticText> <reportElement uuid="0de49c77-d4dd-4e6e-838f-8482b6ec30bb" mode="Opaque" x="0" y="3" width="535" height="15" backcolor="#70A9A9"/> <box> <bottomPen lineWidth="1.0" lineColor="#CCCCCC"/> </box> <textElement/> <text><![CDATA[ ]]></text> </staticText> <staticText> <reportElement uuid="c0e68a78-452e-41ee-9afa-11b6b5f94605" x="414" y="3" width="121" height="15"/> <textElement textAlignment="Center" verticalAlignment="Middle"> <font isBold="true"/> </textElement> <text><![CDATA[grade]]></text> </staticText> <staticText> <reportElement uuid="82804a62-40ac-4e54-bbbf-821c37e04177" x="0" y="3" width="136" height="15"/> <textElement textAlignment="Center" verticalAlignment="Middle"> <font isBold="true"/> </textElement> <text><![CDATA[matricule]]></text> </staticText> </band> </columnHeader> <detail> <band height="16" splitType="Stretch"> <staticText> <reportElement uuid="0bc8863c-e970-4b53-99ef-69dda8cb1086" mode="Opaque" x="0" y="0" width="535" height="14" backcolor="#E5ECF9"/> <box> <bottomPen lineWidth="0.25" lineColor="#CCCCCC"/> </box> <textElement/> <text><![CDATA[ ]]></text> </staticText> <textField> <reportElement uuid="85c1fd45-31cb-469b-a742-f5a424b5daaf" x="414" y="0" width="121" height="15"/> <textElement textAlignment="Center" verticalAlignment="Middle"> <font size="9"/> </textElement> <textFieldExpression><![CDATA[$F{grade}]]></textFieldExpression> </textField> <textField> <reportElement uuid="dd02aaaa-fe0e-42b4-99fc-cbe97d82d113" x="0" y="0" width="136" height="15"/> <textElement textAlignment="Center" verticalAlignment="Middle"/> <textFieldExpression><![CDATA[$F{matricule}]]></textFieldExpression> </textField> </band> </detail> </jasperReport>
you can the result that i'm getting in the file joint to this message
1 Answer:
I'm not sure if this is going to help, but try exporting to another format such as html to see if the strings are truncated. If so, try decreasing the font size and increasing the width of the text field.
These are the properties which resolved Excel Export Cell Merge issue and these properties will be added in each of our jasper report template.
<property name="net.sf.jasperreports.export.xls.exclude.origin.band.1" value="pageHeader"/>
<property name="net.sf.jasperreports.export.xls.exclude.origin.band.2" value="pageFooter"/>
<property name="net.sf.jasperreports.export.xls.exclude.origin.band.3" value="lastPageFooter"/>
<property name="net.sf.jasperreports.export.xls.ignore.cell.background" value="true"/>
<property name="net.sf.jasperreports.export.xls.white.page.background" value="false"/>
<property name="net.sf.jasperreports.export.xls.ignore.graphics" value="true"/>
<property name="net.sf.jasperreports.export.xls.detect.cell.type=true"/>
<property name="net.sf.jasperreports.export.xls.remove.empty.space.between.rows=true"/>
<property name="net.sf.jasperreports.export.xls.remove.empty.space.between.columns=true"/>
<property name="net.sf.jasperreports.export.xls.collapse.row.span" value="true"/>
<property name="net.sf.jasperreports.export.xls.ignore.page.margins=true"/>
<property name="net.sf.jasperreports.export.xls.one.page.per.sheet=true"/>
<property name="net.sf.jasperreports.export.xls.wrap.text" value="true"/>
<property name="net.sf.jasperreports.export.xls.column.width.ratio" value="1.10f"/>
<property name="net.sf.jasperreports.export.xls.auto.fit.column" value="true"/>
This is working properly.