如何使PDF成为Crystal报表的默认导出选项? [英] How do I make PDF the default export option for a Crystal Report?

查看:355
本文介绍了如何使PDF成为Crystal报表的默认导出选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Studio 2008的WinForms中使用CrystalDecisions.CrystalReports.Engine.ReportDocument。现在,当用户单击导出按钮时,对话框默认将报表保存为CrystalReports格式的文件。可以将选择器更改为PDF,但是我已经给出的具体请求 - 我搜索太多小时试图找到 - 是使导出报告对话框默认为PDF格式选项。

I am working with CrystalDecisions.CrystalReports.Engine.ReportDocument in WinForms in Visual Studio 2008. Right now when the users click the export button the dialog defaults to saving the report as a CrystalReports formatted file. It's possible to change the selector to PDF, but the specific request that I've been given -- and I've searched for too many hours trying to find -- is to make the 'export report' dialog default to PDF format option.

有没有人知道如何做?

推荐答案

CR XI,我知道的唯一方法是用您自己的替换导出对话框。您可以将自己的按钮添加到CrystalReportViewer控件并隐藏其导出按钮。

As of CR XI, the only way I know is to replace the export dialog with your own. You can add your own button to the CrystalReportViewer control and hide their export button.

这里是vb.net代码,用您自己的按钮/ eventhandler替换导出按钮...

Here's vb.net code to replace the export button with your own button/eventhandler...

Public Shared Sub SetCustomExportHandler(ByVal crv As CrystalDecisions.Windows.Forms.CrystalReportViewer, ByVal export_click_handler As EventHandler)
        For Each ctrl As Control In crv.Controls
            'find the toolstrip
            If TypeOf ctrl Is ToolStrip Then
                Dim ts As ToolStrip = DirectCast(ctrl, ToolStrip)

                For Each tsi As ToolStripItem In ts.Items

                    'find the export button by it's image index
                    If TypeOf tsi Is ToolStripButton AndAlso tsi.ImageIndex = 8 Then

                        'CRV export button
                        Dim crXb As ToolStripButton = DirectCast(tsi, ToolStripButton)

                        'clone the looks of the export button
                        Dim tsb As New ToolStripButton
                        With tsb
                            .Size = crXb.Size
                            .Padding = crXb.Padding
                            .Margin = crXb.Margin
                            .TextImageRelation = crXb.TextImageRelation

                            .Text = crXb.Text
                            .ToolTipText = crXb.ToolTipText
                            .ImageScaling = crXb.ImageScaling
                            .ImageAlign = crXb.ImageAlign
                            .ImageIndex = crXb.ImageIndex
                        End With

                        'insert custom button in it's place
                        ts.Items.Insert(0, tsb)

                        AddHandler tsb.Click, export_click_handler

                        Exit For
                    End If
                Next

                Exit For
            End If
        Next

        'hide the default export button
        crv.ShowExportButton = False
    End Sub

然后在点击处理程序中显示一个自定义的SaveFileDialog并最终调用ReportDocument.ExportToDisk方法。这样,您可以将对话框的标题和文件名设置为有用的,当然设置默认导出类型。

Then in the click handler you'd show a customized SaveFileDialog and eventually call the ReportDocument.ExportToDisk method. This way you can set the dialog's title and filename to something useful and of course set the default export type.

这篇关于如何使PDF成为Crystal报表的默认导出选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆