Отключить кнопку экспорта CrystalReportViewer
<CR:CrystalReportViewer .... HasExportButton="false" ... />
Добавить панель инструментов экспорта
<asp:Panel ID="exportPanel" ClientIDMode="Static" runat="server" CssClass="inLinePanel" >
<table style="height: 22px; margin-top: 1px; margin-right: 1px; margin-bottom: 1px; margin-left: 1px; display: block; cursor: pointer; " id="CrystalReportViewer1_toptoolbar_addedButtons" class="" cellspacing="0" cellpadding="0" border="0" >
<tr>
<td title="PDF">
<asp:ImageButton ID="btnPdf" runat="server" OnClick="btnExport_Click" ImageUrl="~/Images/PDF.png" CssClass="AddedButton" />
</td>
<td title="word">
<asp:ImageButton ID="btnDoc" runat="server" OnClick="btnExport_Click" ImageUrl="~/Images/DOC.png" />
</td>
<td title="excel">
<asp:ImageButton ID="btnXls" runat="server" OnClick="btnExport_Click" ImageUrl="~/Images/XLS.png" />
</td>
<td title="excel no stile">
<asp:ImageButton ID="btnCsv" runat="server" OnClick="btnExport_Click" ImageUrl="~/Images/CSV.png" />
</td>
</tr>
</table>
</asp:Panel>
И это код-позади
protected void btnExport_Click(object sender, EventArgs e)
{
ReportDocument reportDocument = CrystalReportViewer1.ReportSource ;
// Stop buffering the response
Response.Buffer = false;
// Clear the response content and headers
Response.ClearContent();
Response.ClearHeaders();
try
{
string senderID = ((ImageButton)sender).ID;
if (senderID == "btnPdf")
reportDocument.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, Page.Title);
else if (senderID == "btnXls")
reportDocument.ExportToHttpResponse(ExportFormatType.Excel, Response, true, Page.Title);
else if (senderID == "btnCsv")
reportDocument.ExportToHttpResponse(ExportFormatType.ExcelRecord, Response, true, Page.Title);
else if (senderID == "btnDoc")
reportDocument.ExportToHttpResponse(ExportFormatType.EditableRTF, Response, true, Page.Title);
// There are other format options available such as Word, Excel, CVS, and HTML in the ExportFormatType Enum given by crystal reports
}
catch (Exception ex)
{
Compliance.SmtpHelper.SendErrorMessage("Reportform.Aspx - QueryString: '" + clearQueryString + "' - Dettaglio errore: " + ex.ToString());
Response.Write(ex.StackTrace);
}
}