In fact, in a Windows form, the Crystal Report crystalreportviewer itself provides the export function, so you do not need to write anyCode.
However, in Asp.net, the export function of Crystal Reports is slightly different. A small amount of code is required. Below is a code template:
Public Void Export ( String Filename, String EXT)
{
ReportDocument reportdocument = Getreportdocument ();
Exportoptions = New Exportoptions ();
Diskfiledestinationoptions diskoptions = Exportoptions. creatediskfiledestinationoptions ();
Exportoptions. exportformattype = Getexportformattype (EXT );
Exportoptions. exportdestinationtype = Exportdestinationtype. diskfile;
Diskoptions. diskfilename = Filename + " . " + EXT;
Exportoptions. exportdestinationoptions = Diskoptions;
ReportDocument. Export (exportoptions );
}
The implementation of getexportformattype () is as follows:
Private Exportformattype getexportformattype ( String EXT)
{
Switch (EXT)
{
Case " PDF " :
Return Exportformattype. portabledocformat;
Case " RTF " :
Return Exportformattype. richtext;
Case " Doc " :
Return Exportformattype. wordforwindows;
Case " Xls " :
Return Exportformattype. Excel;
Case " Html " :
Return Exportformattype. html32;
Default :
Return Exportformattype. noformat;
}
}
Getreportdocument () is a function that returns the reportdocument object of the report to be exported. You can implement this function at will.
Note that the filename format must be "C: \ crystalreport.
You can use this code template to export reports in five formats;