vb.net Crystal Report 将报表导出为 excel 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20558158/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 16:07:35  来源:igfitidea点击:

Crystal Report exporting a report as excel file

vb.netcrystal-reports

提问by EysAce

I am creating a crystal report in VB 2008 which generate a MS Access file in the Crystal Report Viewer, and i want to export my work in crystal report viewer as excel file. Can this be possible???

我正在 VB 2008 中创建一个水晶报表,它在水晶报表查看器中生成一个 MS Access 文件,我想将水晶报表查看器中的工作导出为 excel 文件。这可能吗???

回答by campagnolo_1

I agree with @Andrew about the MS Access file, that doesn't quite make sense. Here is some sample code that shows how to export a report as an .xls file. The code is (obviously) assigned to a button.

我同意@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

You do know that the CrystalReportViewer has a toolbar with an export button, which can export to Excel without the need of any extra code. You can enable/disable that button in the CrystalReportViewer properties or using code like:

您确实知道 CrystalReportViewer 有一个带有导出按钮的工具栏,无需任何额外代码即可导出到 Excel。您可以在 CrystalReportViewer 属性中或使用以下代码启用/禁用该按钮:

<CR:CrystalReportViewer  ....    HasExportButton="true" ... />