1393942 - How to modify a Crystal Report section using the CR Java RAS SDK

SAP Knowledge Base Article - Public

1393942 - How to modify a Crystal Report section using the CR Java RAS SDK

Symptom

How to modify a Crystal Report section using CR Java RAS SDK

Reproducing the Issue

  • Crystal Reports XI R2 and later
  • Java

Resolution

package exportsubreport;

import com.crystaldecisions.sdk.occa.report.application.*;
import com.crystaldecisions.sdk.occa.report.definition.Area;
import com.crystaldecisions.sdk.occa.report.definition.IArea;
import com.crystaldecisions.sdk.occa.report.definition.ISection;
import com.crystaldecisions.sdk.occa.report.definition.ISectionFormat;
import com.crystaldecisions.sdk.occa.report.definition.Section;
import com.crystaldecisions.sdk.occa.report.exportoptions.ReportExportFormat;
import com.crystaldecisions.sdk.occa.report.lib.ReportSDKException;
import java.awt.Color;
import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Main {

String reportPath = "c:\\SubTest.rpt";
String subreportName ="SubTest";
ReportClientDocument oReportClientDoc;
ReportClientDocument oTESTReportClientDoc;
ISubreportClientDocument oSubReportClientDoc;
FileOutputStream file;
ByteArrayInputStream byteArrayStream;
byte[] byteArray;

int byteread;

/**
* @param args the command line arguments
*/

public static void main(String[] args) {

Main app = new Main();

app.oReportClientDoc = new ReportClientDocument();

try{

app.oReportClientDoc.setReportAppServer(ReportClientDocument.inprocConnectionString);
app.oReportClientDoc.open(app.reportPath, OpenReportOptions._openAsReadOnly);
app.oSubReportClientDoc =app.oReportClientDoc.getSubreportController().getSubreport(app.subreportName);

IArea area =app.oSubReportClientDoc.getReportDefController().getReportDefinition().getReportHeaderArea();

Section sec =(Section)area.getSections().getSection(1);

//the section cannot be modifyed it need to be cloned
// and added to the report in place of the origianal section

ISection newSection =(ISection)sec.clone(true);

//also clone the section format to keep preexsisting formatting

ISectionFormat format =sec.getFormat();
ISectionFormat newformat =(ISectionFormat)format.clone(true);

//apply the format change to the new section

newformat.setBackgroundColor(Color.blue);
newSection.setFormat(newformat);

//remove the original section and add the new one

app.oSubReportClientDoc.getReportDefController().getReportSectionController().remove(sec);
app.oSubReportClientDoc.getReportDefController().getReportSectionController().add(newSection, area, -1);

 

app.file= new FileOutputStream("c:\\subexport.pdf");

app.byteArrayStream =(ByteArrayInputStream)app.oReportClientDoc.getPrintOutputController().export(ReportExportFormat.PDF);

app.byteArray =new byte[1024];

while((app.byteread =app.byteArrayStream.read(app.byteArray)) !=-1){

app.file.write(app.byteArray);

}

app.file.flush();

app.file.close();

app.byteArrayStream.close();

}

catch(ReportSDKException repex){

System.out.println(repex.getMessage());

}

catch(FileNotFoundException FNF){

System.out.println(FNF.getMessage());

}

catch(IOException ioex){

System.out.println(ioex.getMessage());

}

}

}

Keywords

How modify a Crystal Report section using CR Java RAS SDK , KBA , BI-DEV-JAV , BI Software Development Kits (SDKs) - Java , How To

Product

SAP Crystal Reports XI R2