Link to home
Start Free TrialLog in
Avatar of Victor  Charles
Victor CharlesFlag for United States of America

asked on

Help with exporting data from DataGrid View to PDF format

Hi,

How do you export data from DataGridView to PDF format using VB.NET?

Thanks,

Victor
Avatar of ElrondCT
ElrondCT
Flag of United States of America image

Probably the easiest way would be to create output using Crystal Reports, then use its PDF export function. So you wouldn't be directly going from the DataGridView to PDF, but you'd send the DataTable to CR to create the report, then use code something like the following to create the PDF:

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.IO

                crDiskFileDestinationOptions = New DiskFileDestinationOptions
                crExportOptions = rptOut.ExportOptions
                'Export to PDF
                sfdReport.DefaultExt = ".pdf"
                sfdReport.Filter = "Portable Document Format (*.pdf)|*.pdf|All files (*.*)|*.*"
                'set the required report ExportOptions properties
                With crExportOptions
                    .DestinationOptions = crDiskFileDestinationOptions
                    .ExportDestinationType = ExportDestinationType.DiskFile
                    .ExportFormatType = ExportFormatType.PortableDocFormat
                End With
                dlgResult = sfdReport.ShowDialog
                If dlgResult = DialogResult.Cancel Then
                    Exit Sub
                End If
                crDiskFileDestinationOptions.DiskFileName = sfdReport.FileName
               Try
                   ' Export the report
                   rptOut.Export()
                   MsgBox("Report exported successfully.")
               Catch err As Exception
                   MsgBox(err.Message.ToString)
               End Try

Open in new window

Avatar of Victor  Charles

ASKER

Hi,

Where in the code are you sending data from the DataTable to CR to create the report?

Thanks,

Victor
ASKER CERTIFIED SOLUTION
Avatar of ElrondCT
ElrondCT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank You.