在ASP.Net的Crystal Reports Viewer(2008)中,当您单击“导出”按钮时,“导出”对话框将显示“文件格式”选项:
等。
有谁知道如何删除其中一些选项,以便最终用户不会看到它?
答案 0 :(得分:3)
我们遇到了同样的问题,并最终滚动了我们自己的导出页面并限制了那里的选择。
效果很好,但我对Crystal Reports的期望更高!
答案 1 :(得分:1)
从我能够找到的内容中,您可以尝试创建自己的导出按钮选项,删除给定的按钮选项并将自己的选项添加到asp页面。您需要首先将按钮拖到页面上,然后双击它以自动生成代码。从那里添加代码
crystalReportViewer1.ExportReport ()
一旦进入此代码,它将使用导出选项的默认设置,但是如果要更改该按钮中的导出选项,则必须手动编码。
' Declare variables and get the export options.
Dim exportOpts As New ExportOptions()
Dim diskOpts As New DiskFileDestinationOptions()
Dim excelFormatOpts As New ExcelFormatOptions()
exportOpts = Report.ExportOptions
' Set the excel format options.
excelFormatOpts.ExcelTabHasColumnHeadings = true
exportOpts.ExportFormatType = ExportFormatType.Excel
exportOpts.FormatOptions = excelFormatOpts
' Set the export format.
exportOpts.ExportFormatType = ExportFormatType.Excel
exportOpts.ExportDestinationType = ExportDestinationType.DiskFile
' Set the disk file options.
diskOpts.DiskFileName = fileName
exportOpts.DestinationOptions = diskOpts
Report.Export()
此链接为您提供上面发布的相同代码。它显示了如何在Visual Basic代码中执行此操作。因此,在您的aspx.vb代码中,您必须手动输入所需的格式类型。
答案 2 :(得分:1)
您可以通过删除导出DLL来控制导出选项。在Business Objects \ Common \\ bin目录中搜索crxf _ * .dll。
答案 3 :(得分:1)
<asp:ImageButton Width="20px" Height="20px" ID="btnPdf" runat="server"
OnClick="btnExport_Click" ImageUrl="~/Images/PDF.png" AlternateText="Export To PDF" CssClass="AddedButton" />
<asp:ImageButton Width="20px" Height="20px" ID="btnXls" runat="server"
OnClick="btnExport_Click" ImageUrl="~/Images/XLS.png" AlternateText="Export To Excel" />
<asp:ImageButton Width="20px" Height="20px" ID="btnDoc" runat="server"
OnClick="btnExport_Click" ImageUrl="~/Images/DOC.png" AlternateText="Export To Word" />
试试这个:
<CR:CrystalReportViewer ... HasExportButton="false" HasPrintButton="False" >
<asp:ImageButton Width="20px" Height="20px" ID="btnPdf" runat="server"
OnClick="btnExport_Click" ImageUrl="~/Images/PDF.png" AlternateText="Export To PDF" CssClass="AddedButton" />
<asp:ImageButton Width="20px" Height="20px" ID="btnXls" runat="server"
OnClick="btnExport_Click" ImageUrl="~/Images/XLS.png" AlternateText="Export To Excel" />
<asp:ImageButton Width="20px" Height="20px" ID="btnDoc" runat="server"
OnClick="btnExport_Click" ImageUrl="~/Images/DOC.png" AlternateText="Export To Word" />
C# code:
protected void btnExport_Click(object sender, EventArgs e)
{
// 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.ExcelRecord, Response, true, Page.Title);
else if (senderID == "btnDoc")
reportDocument.ExportToHttpResponse(ExportFormatType.WordForWindows, 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 (System.Threading.ThreadAbortException)
{
//The issue has been identified and logged under Problem Report ID
//ADAPT00765364. The error is likely caused because Response.End() is used inside the
//ExportToHttpResponse() method.
//It is a known issue that Reponse.End() causes the thread to abort. This is by design.
//See Microsoft KB312629 Article for more info.
}
catch (Exception ex)
{
//error management
}
}
答案 4 :(得分:1)
请参阅下面的答案以从Crystal Reports中删除不需要的导出选项
答案 5 :(得分:0)
using (ReportClass rptH = new ReportClass())
{
rptH.FileName = @"C:/Report/crJournal.rpt"; //Your rpt file path
// if you put your rpt file on Bin then you need to write only rpt file name
rptH.Load();
rptH.SetDataSource( ds );// Provide Dataset for report : Ds is DataSet
rptH.ExportToDisk(ExportFormatType.Excel, "Give Output file path");
}
这段代码肯定有用:
答案 6 :(得分:0)
显然,更高版本(13.0?)会向AllowedExportFormats
类添加CrystalReportViewer
属性。
我没有那个更新的版本(我只有12.0),但显然你需要这样的东西:
int exportFormatFlags = (int)
(CrystalDecisions.Shared.ViewerExportFormats.PdfFormat |
CrystalDecisions.Shared.ViewerExportFormats.ExcelFormat |
// any other desired formats
);
crystalReportViewer1.AllowedExportFormats = exportFormatFlags;