zoukankan      html  css  js  c++  java
  • 水晶报表导出操作及动态更改报表中的文本字段

    Imports CrystalDecisions.CrystalReports.Engine
    Imports CrystalDecisions.Shared
    Public Class Form1
        Dim ExOPS As ExportOptions
        Dim ReportDoc As ReportDocument = New ReportDocument
        Dim logOnInfo As ReportInfo = New ReportInfo
        Dim FileOPS As DiskFileDestinationOptions = New DiskFileDestinationOptions

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim ds As DataSet1 = New DataSet1
            ds.temptable.AddtemptableRow("熊川湘", 12)
            ds.temptable.AddtemptableRow("唐沙", 24)
            Dim cry As CrystalReport1 = New CrystalReport1
            '程序外控制报表的标题
            Dim to1 As CrystalDecisions.CrystalReports.Engine.TextObject
            to1 = CType(cry.ReportDefinition.ReportObjects("text3"), CrystalDecisions.CrystalReports.Engine.TextObject)
            to1.Text = "tttt"
            cry.SetDataSource(ds.Tables("temptable"))
            'cry.ExportToDisk(ExportFormatType.PortableDocFormat, "d:\\c.pdf") ''转换成PDF
            'cry.ExportToDisk(ExportFormatType.WordForWindows, "d:\\c.doc")''转换成doc
            cry.ExportToDisk(ExportFormatType.Excel, "d:\\c.xls") ''转换成xls
            CrystalReportViewer1.ReportSource = cry
            table1 = ds.Tables("temptable")
        End Sub
        Dim table1 As DataTable = New DataTable

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            ' ExportToPDF("d:\\CrystalReport1.rpt", Me.table1, "d:\\c.doc")

            ExportToExcel("d:\\CrystalReport1.rpt", Me.table1, "d:\\c.xls")

        End Sub
      
        ''' <summary>
        ''' 导出报表文件为PDF格式
        ''' </summary>
        ''' <param name="ReportFile">报表文件名称,调用时请使用Server.MapPath("报表文件.rpt")这样来给这个参数</param>
        ''' <param name="ReportDataSource">报表文件所使用的数据源,是一个Dataset</param>
        ''' <param name="PDFFileName">你要导成的目标文件名称,注意不要放在wwwroot等目录中,iis会不让你导出的</param>
        ''' <returns>bool成功返回true,失败返回false</returns>
        Public Function ExportToPDF(ByVal ReportFile As String, ByVal ReportDataSource As Object, ByVal PDFFileName As String) As Boolean
          
            Try
                ReportDoc.Load(ReportFile)
                ReportDoc.SetDataSource(ReportDataSource)
                FileOPS.DiskFileName = PDFFileName
                ExOPS = ReportDoc.ExportOptions
                ExOPS.DestinationOptions = FileOPS
                ExOPS.ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile
                ExOPS.ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat
                ReportDoc.Export()
                Return True
            Catch
                Return False
            End Try
        End Function

        ''' <summary>
        ''' 导出报表文件到Excel格式
        ''' </summary>
        ''' <param name="ReportFile">报表文件名称,调用时请使用Server.MapPath("报表文件.rpt")这样来给这个参数</param>
        ''' <param name="ReportDataSource">报表文件所使用的数据源,是一个Dataset</param>
        ''' <param name="ExcelFileName">你要导成的目标文件名称,注意不要放在wwwroot等目录中,iis会不让你导出的</param>
        ''' <returns>成功返回true失败返回false</returns>
        Public Function ExportToExcel(ByVal ReportFile As String, ByVal ReportDataSource As Object, ByVal ExcelFileName As String) As Boolean
            Try
                ReportDoc.Load(ReportFile)
                ReportDoc.SetDataSource(ReportDataSource)
                FileOPS.DiskFileName = ExcelFileName
                ExOPS = ReportDoc.ExportOptions
                ExOPS.DestinationOptions = FileOPS
                ExOPS.ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile
                ExOPS.ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.Excel
                ReportDoc.Export()
                Return True
            Catch
                Return False
            End Try
        End Function

    End Class


       本人博客的文章大部分来自网络转载,因为时间的关系,没有写明转载出处和作者。所以在些郑重的说明:文章只限交流,版权归作者。谢谢

  • 相关阅读:
    RDA安装
    关闭SELinux
    Linux下开启关闭防火墙
    长事务管理
    增加复制表
    Python使用property函数定义的属性名与其他实例变量重名会怎么样?
    Python使用property函数定义属性访问方法如果不定义fget会怎么样?
    Python使用property函数和使用@property装饰器定义属性访问方法的异同点分析
    第8.18节 Python类中内置析构方法__del__
    Python中的列表解析和列表推导是一回事吗?
  • 原文地址:https://www.cnblogs.com/wzg0319/p/1344159.html
Copyright © 2011-2022 走看看