Export a report to Excel using code-based section report with .vb suffix

Posted by: jim on 24 February 2018, 10:24 am EST

    • Post Options:
    • Link

    Posted 24 February 2018, 10:24 am EST

    Using Visual Studio 2013 and writing Active reports section reports using Visual Basic. Need code that will run from a windows Form in visual basic without dropping a report.rpx in the bin/debug folder. There don’t seem to be any examples of this in the V9 documentation. Would appreciate some help with this.

    Thanks, Jim F

  • Posted 25 February 2018, 3:27 pm EST

    Hello,

    Please refer the attached sample to achieve your requirement.

    Thanks,

    Mohitprj_sqlLiteDatabase.zip

  • Posted 26 February 2018, 12:00 pm EST

    I’m unable to get the example to load and am using SQL Server 14.

    I’m working with the Code based section report and learned from a forum that simple code was all that was required to print without opening viewer:

    Dim rpt = New SectionReport1()

    rpt.Run(False)

    Dim sectionDocument = rpt.Document

    sectionDocument.Print(True, True, False)

    Where SectionReport1 is your vb report.

    Is there simple code to select the report and output it to Excel? I’m sure it may be in the example, but it won’t load.

    Thanks for your assistance.

    Jim F

  • Posted 26 February 2018, 6:06 pm EST

    Hello,

    Please use the following code to export the code based report into excel

    
    
    ' Create reference of a Section report.
    Dim rpt As SectionReport1()
    rpt.Run()
    
    ' Export the report in Excel format.
    Dim XlsExport1 As New GrapeCity.ActiveReports.Export.Excel.Section.XlsExport()
    ' Set a file format of the exported excel file to Xlsx to support Microsoft Excel 2007 and newer versions.
    XlsExport1.FileFormat = GrapeCity.ActiveReports.Export.Excel.Section.FileFormat.Xlsx
    XlsExport1.Export(rpt.Document, Application.StartupPath + "\XLSExpt.xlsx") 
    
    

    Hope it helps.

    Thanks,

    Mohit

  • Posted 26 February 2018, 11:09 pm EST

    Thanks, Mohit! It looks like exactly what will do the job.

    I’ll try it today and let you know the results.

    Thanks, again.

    Jim F

  • Posted 5 March 2018, 2:33 am EST

    I’ve set up the code as follows: (JobTraveller2 is the section report name that is to be exported)

        Dim rpt = New JobTraveller2()
        Dim viewer1 As Form = New ReportViewer()
        rpt.Run()
        Dim XlsExport1 As New GrapeCity.ActiveReports.Export.Excel.Section.XlsExport()
        XlsExport1.FileFormat = GrapeCity.ActiveReports.Export.Excel.Section.FileFormat.Xlsx
        XlsExport1.Export(rpt.Document, Application.StartupPath + "\XLSExpt.xlsx")
        viewer1.loaddocument(New JobTraveller2())
    

    It creates the xlsexpt.xlsx in the bin subdirectory, but there is no content.

    In addition, the viewer1.loaddocument is flagged as not related to viewer1

    I could use some fine tuning, if you’ve got a minute.

    Thanks,

    Jim F

  • Posted 5 March 2018, 10:36 pm EST

    Hello,

    Viewer is inbuilt control of ActiveReport. You can use it to view the report. Please refer the following line of code to use the AR Viewer in the application with excel export:

    
     Create reference of a Section report.
    Dim rpt As SectionReport1()
    rpt.Run()
    
    ' Export the report in Excel format.
    Dim XlsExport1 As New GrapeCity.ActiveReports.Export.Excel.Section.XlsExport()
    ' Set a file format of the exported excel file to Xlsx to support Microsoft Excel 2007 and newer versions.
    XlsExport1.FileFormat = GrapeCity.ActiveReports.Export.Excel.Section.FileFormat.Xlsx
    XlsExport1.Export(rpt.Document, Application.StartupPath + "\XLSExpt.xlsx") 
    
    

    Also, please refer the attached sample.

    Hope it clear.

    Thanks,

    Mohit

    prj_ExcelExport.zip

  • Posted 6 March 2018, 1:53 am EST

    Mohit,

    It worked fine after I put it in the AfterReport section.

    Thanks for all your assistance.

    Jim F

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels