Sunday, December 03, 2006

Exporting Crystal Reports

Here's an example how to easily export your Crystal Report to xls, pdf...
First thing, you need to have:
using CrystalDecisions;
using CrystalDecisions.Shared;

And, here's a code that exports to xls:

CrystalReport0 crReport0 = new CrystalReport0();

ExportOptions crExpOpt0 = crReport0.ExportOptions;
DiskFileDestinationOptions crExpDest0 = new DiskFileDestinationOptions();

crExpDest0.DiskFileName = sPath;

crExpOpt0.ExportDestinationType = ExportDestinationType.DiskFile;
crExpOpt0.ExportFormatType = ExportFormatType.Excel;
crExpOpt0.DestinationOptions = crExpDest0;

try
{
crReport0.Export();
}
catch
{
throw new Exception ("Error");
}


You can just change ExportFormatType and get rtf, pdf...