在ASPNET中水晶报表没有象在Windows Form中那样提供报表的导出和打印功能需要我们自己动手添加代码来控制下面给个DEMO
导出
myReport ReportDoc = new myReport();//表表的名称
private void btnExport_Click(object sender SystemEventArgs e)
{
CrystalDecisionsSharedDiskFileDestinationOptions DiskOpts = new CrystalDecisionsSharedDiskFileDestinationOptions();
ReportDocExportOptionsExportDestinationType = CrystalDecisionsSharedExportDestinationTypeDiskFile;
switch (DropDownListSelectedItemText)
{
case Rich Text (RTF):
ReportDocExportOptionsExportFormatType = CrystalDecisionsSharedExportFormatTypeRichText;
DiskOptsDiskFileName = d:\\demortf;
break;
case Portable Document (PDF):
ReportDocExportOptionsExportFormatType = CrystalDecisionsSharedExportFormatTypePortableDocFormat;
DiskOptsDiskFileName = d:\\demopdf;
break;
case MS Word (DOC):
ReportDocExportOptionsExportFormatType = CrystalDecisionsSharedExportFormatTypeWordForWindows;
DiskOptsDiskFileName = d:\\demodoc;
break;
case MS Excel (XLS):
ReportDocExportOptionsExportFormatType = CrystalDecisionsSharedExportFormatTypeExcel;
DiskOptsDiskFileName = d:\\demoxls;
break;
default:
break;
}
ReportDocExportOptionsDestinationOptions = DiskOpts;
ReportDocExport();
}
打印
private void btnPrint_Click(object sender SystemEventArgs e)
{
string strPrinterName; // 指定打印机名称
strPrinterName = @Canon BubbleJet BJCSP;
PageMargins margins;// 设置打印页边距
margins = ReportDocPrintOptionsPageMargins;
marginsbottomMargin = ;
marginsleftMargin = ;
marginsrightMargin = ;
marginstopMargin = ;
ReportDocPrintOptionsApplyPageMargins(margins);
ReportDocPrintOptionsPrinterName = strPrinterName;//应用打印机名称
// 打印报表startPageN 和 endPageN
// 参数设置为 表示打印所有页
ReportDocPrintToPrinter( false);
}