我在VB 2008中创建了一个水晶报表,它在Crystal Report Viewer中生成一个MS Access文件,我希望将我的工作导出为水晶报表查看器中的excel文件。这可能吗???
答案 0 :(得分:0)
我同意@Andrew关于MS Access文件,这没有多大意义。下面是一些示例代码,演示如何将报表导出为.xls文件。代码(显然)分配给一个按钮。
Private Sub ButtonExport_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
Try
Dim CrExportOptions As ExportOptions
Dim CrDiskFileDestinationOptions As New _
DiskFileDestinationOptions()
Dim CrFormatTypeOptions As New ExcelFormatOptions
CrDiskFileDestinationOptions.DiskFileName = _
"c:\crystalExport.xls"
CrExportOptions = cryRpt.ExportOptions
With CrExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.Excel
.DestinationOptions = CrDiskFileDestinationOptions
.FormatOptions = CrFormatTypeOptions
End With
cryRpt.Export()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
您确实知道CrystalReportViewer有一个带有导出按钮的工具栏,可以导出到Excel而无需任何额外的代码。您可以在CrystalReportViewer属性中启用/禁用该按钮,也可以使用以下代码:
<CR:CrystalReportViewer .... HasExportButton="true" ... />