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

vaibhav.lather

Members
  • Posts

    8
  • Joined

  • Last visited

vaibhav.lather's Achievements

Rookie

Rookie (2/14)

  • Week One Done
  • One Month Later
  • One Year In
  • First Post Rare
  • Conversation Starter Rare

Recent Badges

0

Reputation

  1. hi, i have a report in which 4 subreports , i want to export 2 subreports in same tab and other report in different tabs in xls format .
  2. right click cross tab-->crosstabdata-->select the checkbox "data is pre-sorted".
  3. right click cross tab-->crosstabdata-->select the checkbox "data is pre-sorted".
  4. hi, by seeing your design i have only words to say is please look at some video or book before practical. Ireport-ultimateguide.pdf is best for beginners.
  5. yes anjumAbbas is right pass parameter . here is example code JRDesignQuery query = new JRDesignQuery(); query.setText("SELECT * FROM Address $P!{OrderByClause}"); jasperDesign.setQuery(query); or u can set this type of query in query editor.
  6. package com.innoeye.crosstab; import java.awt.Color; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JRExporter; import net.sf.jasperreports.engine.JRExporterParameter; import net.sf.jasperreports.engine.JROrigin; import net.sf.jasperreports.engine.JasperCompileManager; import net.sf.jasperreports.engine.JasperExportManager; import net.sf.jasperreports.engine.JasperFillManager; import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.JasperRunManager; import net.sf.jasperreports.engine.design.*; import net.sf.jasperreports.engine.export.JRXlsExporter; import net.sf.jasperreports.engine.export.JRXlsExporterParameter; import net.sf.jasperreports.engine.type.BandTypeEnum; import net.sf.jasperreports.engine.type.PositionTypeEnum; import net.sf.jasperreports.engine.util.JRLoader; import com.mysql.*; public class DesignJasperWithJava { private static Connection getConnection() throws ClassNotFoundException, SQLException { //Change these settings according to your local configuration String driver = "com.mysql.jdbc.Driver"; String connectString = "jdbc:mysql://localhost:3306/jasper"; String user = "root"; String password = "root"; Class.forName(driver); Connection conn = DriverManager.getConnection(connectString, user, password); return conn; } public JasperDesign getDesign() { JasperDesign jasperDesign=null; try{ jasperDesign = new JasperDesign(); jasperDesign.setName("NewJasper"); jasperDesign.setPageHeight(842); jasperDesign.setPageWidth(595); jasperDesign.setColumnWidth(515); jasperDesign.setColumnSpacing(0); jasperDesign.setLeftMargin(40); jasperDesign.setRightMargin(40); jasperDesign.setTopMargin(50); jasperDesign.setBottomMargin(50); // Parameters JRDesignParameter parameter=new JRDesignParameter(); parameter.setName("Year"); parameter.setValueClass(java.lang.String.class); jasperDesign.addParameter(parameter); parameter=new JRDesignParameter(); parameter.setName("Department"); parameter.setValueClass(java.lang.String.class); jasperDesign.addParameter(parameter); parameter=new JRDesignParameter(); parameter.setName("Amount"); parameter.setValueClass(java.lang.Double.class); jasperDesign.addParameter(parameter); //Style JRDesignStyle style=new JRDesignStyle(); style.setName("vaibhav"); style.setFontName("Aerial"); style.setFontSize(10); jasperDesign.addStyle(style); //Query JRDesignQuery query = new JRDesignQuery(); query.setText("select * from myDepartment"); jasperDesign.setQuery(query); //Fields JRDesignField field = new JRDesignField(); field.setName("id"); field.setValueClass(java.lang.Integer.class); jasperDesign.addField(field); field = new JRDesignField(); field.setName("department"); field.setValueClass(java.lang.String.class); jasperDesign.addField(field); field = new JRDesignField(); field.setName("year"); field.setValueClass(java.lang.String.class); jasperDesign.addField(field); field = new JRDesignField(); field.setName("budget_amount"); field.setValueClass(java.lang.Double.class); jasperDesign.addField(field); field = new JRDesignField(); field.setName("months"); field.setValueClass(java.lang.String.class); jasperDesign.addField(field); //Band JROrigin origin=new JROrigin(BandTypeEnum.COLUMN_HEADER); JRDesignBand band=new JRDesignBand(); band.setHeight(20); // JRDesignSection designSection = (JRDesignSection) jasperDesign.getColumnHeader(); JRDesignSection designSection = new JRDesignSection(origin); JRDesignTextField textField=new JRDesignTextField(); textField.setBlankWhenNull(true); textField.setBold(true); textField.setFontSize(12); textField.setX(0); textField.setY(4); textField.setWidth(50); textField.setHeight(19); textField.setPositionType(PositionTypeEnum.FIX_RELATIVE_TO_BOTTOM); JRDesignExpression expression = new JRDesignExpression(); expression.setText("$P{Year}"); textField.setExpression(expression); band.addElement(textField); textField=new JRDesignTextField(); textField.setBlankWhenNull(true); textField.setBold(true); textField.setFontSize(12); textField.setX(55); textField.setY(4); textField.setWidth(200); textField.setHeight(19); textField.setPositionType(PositionTypeEnum.FIX_RELATIVE_TO_BOTTOM); expression = new JRDesignExpression(); expression.setText("$P{Department}"); textField.setExpression(expression); band.addElement(textField); textField=new JRDesignTextField(); textField.setBlankWhenNull(true); textField.setBold(true); textField.setFontSize(12); textField.setX(260); textField.setY(4); textField.setWidth(255); textField.setHeight(19); textField.setPositionType(PositionTypeEnum.FIX_RELATIVE_TO_BOTTOM); expression = new JRDesignExpression(); expression.setText("$P{Amount}"); textField.setExpression(expression); band.addElement(textField); System.out.println(" Design "+designSection+" Band "+band); designSection.addBand(band); //Detail origin=new JROrigin(BandTypeEnum.DETAIL); designSection = new JRDesignSection(origin); band = new JRDesignBand(); band.setHeight(20); textField = new JRDesignTextField(); textField.setX(0); textField.setY(4); textField.setWidth(50); textField.setHeight(19); textField.setPositionType(PositionTypeEnum.FIX_RELATIVE_TO_TOP); // textField.setTextAlignment(JRTextElement.TEXT_ALIGN_RIGHT); // textField.setFont(normalFont); expression = new JRDesignExpression(); expression.setText("$F{year}"); textField.setExpression(expression); band.addElement(textField); textField = new JRDesignTextField(); textField.setStretchWithOverflow(true); textField.setX(55); textField.setY(4); textField.setWidth(200); textField.setHeight(19); textField.setPositionType(PositionTypeEnum.FIX_RELATIVE_TO_TOP); // textField.setFont(normalFont); expression = new JRDesignExpression(); // expression.setValueClass(java.lang.String.class); expression.setText("$F{department_name}"); textField.setExpression(expression); band.addElement(textField); textField = new JRDesignTextField(); textField.setStretchWithOverflow(true); textField.setX(260); textField.setY(4); textField.setWidth(255); textField.setHeight(19); textField.setPositionType(PositionTypeEnum.FIX_RELATIVE_TO_TOP); // textField.setFont(normalFont); expression = new JRDesignExpression(); // expression.setValueClass(java.lang.String.class); expression.setText("$F{budget_amount}"); textField.setExpression(expression); band.addElement(textField); System.out.println(" Design "+designSection+" Band "+band); designSection.addBand(band); designSection.addBand(band); }catch(Exception e){ e.printStackTrace(); } return jasperDesign; } public static void main(String args[]) throws JRException{ try{ DesignJasperWithJava obj=new DesignJasperWithJava(); String fileName="c:/myReport"; JasperDesign jasperDesign =obj.getDesign(); JasperCompileManager.compileReportToFile(jasperDesign, fileName); System.err.println("Compile time : " + (System.currentTimeMillis())); System.out.println(" export file "); Map parameters = new HashMap(); parameters.put("Year", "Year"); parameters.put("Department", "Department"); parameters.put("Amount", "Amount"); Connection conn=DesignJasperWithJava.getConnection(); JasperPrint jprint = (JasperPrint)JasperFillManager.fillReport(fileName, parameters,conn); System.err.println("Filling time : " + (System.currentTimeMillis())); JRExporter exporter = new net.sf.jasperreports.engine.export.JRPdfExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jprint); exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,"c:/myReport.pdf"); exporter.exportReport(); System.out.println("PDF creation time : " + (System.currentTimeMillis())); System.exit(0); }catch(Exception e){ e.printStackTrace(); } } }
  7. thanks alara_1 . great reply. hope u will help us in future.... thanks a lot
×
×
  • Create New...