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

giulio.carlacci

Members
  • Posts

    4
  • Joined

  • Last visited

 Content Type 

Profiles

Forum

Events

Featured Visualizations

Knowledge Base

Documentation (PDF Downloads)

Blog

Documentation (Test Area)

Documentation

Dr. Jaspersoft Webinar Series

Downloads

Posts posted by giulio.carlacci

  1. I need to generate a report using JasperReports API only, and I can't find a way to create a JasperReport's table object from Java code. Seems that not exists a way to create a table using JRDesign classes. Maybe I am just searching in the wrong place. I can't use a designer like iReport or JasperStudio due to project requirement. Some help?

    I've made some progress, but it still not works... here's my code:

     private static JasperDesign getJasperDesign() throws JRException {  JasperDesign jasperDesign = JRXmlLoader.load(new File("Template.jrxml"));  JRDesignParameter parameter = new JRDesignParameter();  parameter.setName("parameter");    parameter.setValueClassName("net.sf.jasperreports.engine.JRDataSource");  jasperDesign.addParameter(parameter);  JRDesignDataset subDataset = new JRDesignDataset(false);  subDataset.setName("subDataSet");  JRDesignField field = new JRDesignField();  field.setName("field");  field.setValueClass(java.lang.String.class);   subDataset.addField(field);  jasperDesign.addDataset(subDataset);  // datasource  JRDesignDatasetParameter param = new JRDesignDatasetParameter();  param.setName("REPORT_DATA_SOURCE");    JRDesignExpression exp = new JRDesignExpression("$P{parameter}");  param.setExpression(exp);  // datasetrun  JRDesignDatasetRun dsr = new JRDesignDatasetRun();  dsr.setDatasetName(subDataset.getName());  dsr.addParameter(param);  // table  JRDesignStaticText staticText = new JRDesignStaticText();  staticText.setText("static");  DesignCell columnHeader = new DesignCell();  columnHeader.setHeight(80);  columnHeader.addElement(staticText);  StandardColumn column = new StandardColumn();  column.setDetailCell(columnHeader);  column.setWidth(100);  StandardTable table = new StandardTable();  table.addColumn(column);  table.setDatasetRun(dsr);  // reportElement  JRDesignComponentElement reportElement = new JRDesignComponentElement();  reportElement.setComponentKey(new ComponentKey("http://jasperreports.sourceforge.net/jasperreports/components","jr", "table"));  reportElement.setHeight(200);  reportElement.setWidth(200);  reportElement.setX(140);  reportElement.setY(40);  reportElement.setComponent(table);  JRDesignBand band = new JRDesignBand();  band.addElement(reportElement);  band.setSplitType(SplitTypeEnum.PREVENT);  band.setHeight(250);  ((JRDesignSection) jasperDesign.getDetailSection()).addBand(band);  return jasperDesign; }[/code]

     

×
×
  • Create New...