如何将 PDF 设置为 Crystal Report 的默认导出选项?

发布于 2024-07-26 05:06:13 字数 235 浏览 5 评论 0原文

我正在 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.

Does anyone know how to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

养猫人 2024-08-02 05:06:13

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

下面是用您自己的按钮/事件处理程序替换导出按钮的 vb.net 代码...

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 方法。 通过这种方式,您可以将对话框的标题和文件名设置为有用的内容,当然还可以设置默认导出类型。

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.

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文