Crystal Reports for Eclipse Developer Guide

To create a report wizard

  1. Add the doFinish method.
    This method is called when the wizard is finished. It creates the report, either by loading a report or by modifying the default blank report with the SDK.
    The following code snippet shows how to load an existing report. Replace "c:\MyReport.rpt" with the path to the report.
    import java.io.File;
    import com.crystaldecisions.sdk.occa.report.application.ReportClientDocument;
    protected void doFinish ()
    {
      try
      {
        File reportFile = new File("C:\\MyReport.rpt");
        ReportClientDocument rcd = ReportClientDocument.openReport(reportFile);
        setReport(rcd);
      }
      catch (Exception e)
      {
        e.printStackTrace();
      }
    }
    The following code snippet uses the SDK to modify the default blank report. It adds a text object to the report header and the print date to the page header.
    import com.crystaldecisions.sdk.occa.report.application.ReportDefController;
    import com.crystaldecisions.sdk.occa.report.data.SpecialField;
    import com.crystaldecisions.sdk.occa.report.data.SpecialFieldType;
    import com.crystaldecisions.sdk.occa.report.definition.IArea;
    import com.crystaldecisions.sdk.occa.report.definition.ISection;
    import com.crystaldecisions.sdk.occa.report.definition.FieldObject;
    import com.crystaldecisions.sdk.occa.report.definition.TextObject;
    
    protected void doFinish ()
    {
      int REPORT_HEADER = 0;
      int PAGE_HEADER = 1;
      try
      {
        ReportDefController defCon = getReport().getReportDefController();
      
        IArea reportHeader = defCon.getReportDefinition().getAreas().getArea(REPORT_HEADER);
        ISection rhSection = reportHeader.getSections().getSection(0);
    
        TextObject textObj = new TextObject("My Report");
        textObj.setHeight(360);
        textObj.setWidth(1440);
        textObj.setTop (rhSection.getHeight() - textObj.getHeight());
        defCon.getReportObjectController().add(textObj, rhSection, -1);
    
        IArea pageHeader = defCon.getReportDefinition().getAreas().getArea(PAGE_HEADER);
        ISection phSection = pageHeader.getSections().getSection(0);
         
        SpecialField dateField = new SpecialField(SpecialFieldType.printDate);
        FieldObject dateObj = new FieldObject();
        dateObj.setFieldValueType(dateField.getType());
        dateObj.setDataSource(dateField.getFormulaForm());
    
        dateObj.setHeight(360);
        dateObj.setWidth(1440);
        dateObj.setTop (phSection.getHeight() - dateObj.getHeight());
    
        defCon.getReportObjectController().add(dateObj, phSection, -1);
      }
      catch(ReportSDKException e)
      {
        e.printStackTrace();
      }
    }
Example: A report wizard class
The following code snippet shows the report wizard class that is created in this example:
import com.businessobjects.crystalreports.designer.sdk.wizard.ReportWizard;
import com.crystaldecisions.sdk.occa.report.application.ReportDefController;
import com.crystaldecisions.sdk.occa.report.data.SpecialField;
import com.crystaldecisions.sdk.occa.report.data.SpecialFieldType;
import com.crystaldecisions.sdk.occa.report.definition.IArea;
import com.crystaldecisions.sdk.occa.report.definition.ISection;
import com.crystaldecisions.sdk.occa.report.definition.FieldObject;
import com.crystaldecisions.sdk.occa.report.definition.TextObject;
import com.crystaldecisions.sdk.occa.report.lib.ReportSDKException;

public class MyReportWizard extends ReportWizard 
{
  public MyReportWizard() throws ReportSDKException
  {
  }

  protected void doFinish ()   
  {
    int REPORT_HEADER = 0;
    int PAGE_HEADER = 1;
    try
    {
      ReportDefController defCon = getReport().getReportDefController();
  
      IArea reportHeader = defCon.getReportDefinition().getAreas().getArea(REPORT_HEADER);
      ISection rhSection = reportHeader.getSections().getSection(0);

      TextObject textObj = new TextObject("My Report");
      textObj.setHeight(360);
      textObj.setWidth(1440);
      textObj.setTop (rhSection.getHeight() - textObj.getHeight());
      defCon.getReportObjectController().add(textObj, rhSection, -1);

      IArea pageHeader = defCon.getReportDefinition().getAreas().getArea(PAGE_HEADER);
      ISection phSection = pageHeader.getSections().getSection(0);
       
      SpecialField dateField = new SpecialField(SpecialFieldType.printDate);
      FieldObject dateObj = new FieldObject();
      dateObj.setFieldValueType(dateField.getType());
      dateObj.setDataSource(dateField.getFormulaForm());

      dateObj.setHeight(360);
      dateObj.setWidth(1440);
      dateObj.setTop (phSection.getHeight() - dateObj.getHeight());

      defCon.getReportObjectController().add(dateObj, phSection, -1);
    }
    catch(ReportSDKException e)
    {
      e.printStackTrace();
    }
  }
}



SAP BusinessObjects
http://www.sap.com/sapbusinessobjects/
Support services
http://service.sap.com/bosap-support/
Product Documentation on the Web
http://help.sap.com/