我正在使用Visual Studio 2008中的WinForms中的CrystalDecisions.CrystalReports.Engine.ReportDocument。现在,当用户单击导出按钮时,该对话框默认将报表另存为CrystalReports格式的文件。可以将选择器更改为PDF,但是我已经给出的特定请求 - 我已经搜索了太多时间试图查找 - 是将“导出报告”对话框默认为PDF格式选项。
有谁知道怎么做?
答案 0 :(得分:1)
从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方法。这样,您可以将对话框的标题和文件名设置为有用的东西,当然也可以设置默认的导出类型。