private void printreportinExcel(string strReportPath, DataTable dt)
{
//strReportPath is the report path, dt is the datatable
ReportDocument rptdoc = new ReportDocument();
rptdoc.Load(Server.MapPath(strReportPath));
rptdoc.SetDataSource(dt);
ExportOptions exportOpts1 = rptdoc.ExportOptions;rptdoc.ExportOptions.ExportFormatType =
ExportFormatType.Excel;rptdoc.ExportOptions.ExportDestinationType =
ExportDestinationType.DiskFile;rptdoc.ExportOptions.DestinationOptions =
new DiskFileDestinationOptions();((
DiskFileDestinationOptions)rptdoc.ExportOptions.DestinationOptions).DiskFileName = Server.MapPath("swapt.xls");rptdoc.Export();
rptdoc.Close();
rptdoc.Dispose();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType =
"vendor/ms-excel";Response.AppendHeader(
"Content-Disposition", "attachment; filename=swapt_Report.xls");Response.WriteFile(
"swapt.xls");Response.Flush();
Response.Close();
File.Delete(Server.MapPath("swapt.xls"));}