Gerar Relatório de Arquivo Pronto Crystal Reports

Boa noite pessoal!

To aqui desdas 15:00 da tarde mas não consigo gerar um relatório “.rpt” do crystal reports…
Tenho os “.jar” mas não consigo achar maneira de fazer isto.

Alguem poderia me dar uma força.

Dede ja agradeço.

O Tópico é antigo mas caso alguém tenha o mesmo problema …


import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;

import com.crystaldecisions.sdk.occa.report.application.ReportClientDocument;
import com.crystaldecisions.sdk.occa.report.exportoptions.ReportExportFormat;


public class Crystal {


	public static void main(String[] args){


		String reportname = "teste10.rpt";
		String exportfilename = "exportedrptfile.xls";


		//Open report.
		ReportClientDocument reportClientDoc = new ReportClientDocument();
		try {
			reportClientDoc.open(reportname, 0);

			
			ByteArrayInputStream byteArrayInputStream = (ByteArrayInputStream) reportClientDoc.getPrintOutputController().export(ReportExportFormat.MSExcel);

			//Release report.
			reportClientDoc.close();

			//Use the Java I/O libraries to write the exported content to the file system.
			byte byteArray[] = new byte[byteArrayInputStream.available()];

			//Create a new file that will contain the exported result.
			File file = new File(exportfilename);
			FileOutputStream fileOutputStream = new FileOutputStream(file);

			ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(byteArrayInputStream.available());
			int x = byteArrayInputStream.read(byteArray, 0, byteArrayInputStream.available());

			byteArrayOutputStream.write(byteArray, 0, x);
			byteArrayOutputStream.writeTo(fileOutputStream);

			//Close streams.
			byteArrayInputStream.close();
			byteArrayOutputStream.close();
			fileOutputStream.close();	

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
  • Ele esta gerando um xls, caso queira um PDF, basta mudar “ReportExportFormat.MSExcel” para “ReportExportFormat.PDF” e mudar a extensão do arquivo de saída.

** Se estiver usando o Eclipse, baixe o plugin “Crystal Reports for Eclipse”…
ele possui todas as libs que você precisa… adicione essas libs no projeto e seja feliz :slight_smile:

Eu coloquei esse código em uma JSP

e esta dando a mensagem There is no server specified

Alguém sabe pq ? já estou a semanas tentando gerar um rpt para Excel… em pdf funciona normalmente.