Solved

Help with exporting data from DataGrid View to PDF format

Posted on 2013-11-04
4
497 Views
Last Modified: 2013-11-07
Hi,

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

Thanks,

Victor
0
Comment
Question by:vcharles
  • 2
  • 2
4 Comments
 
LVL 20

Expert Comment

by:ElrondCT
ID: 39623410
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

0
 

Author Comment

by:vcharles
ID: 39624228
Hi,

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

Thanks,

Victor
0
 
LVL 20

Accepted Solution

by:
ElrondCT earned 500 total points
ID: 39624364
I'm not showing the creation of a report. I'm just showing how, after you've created a report, you can send it to PDF.

A good introduction to creating a Crystal Report in VB is at http://www.emoreau.com/Entries/Articles/2006/09/Feeding-Crystal-Reports-from-your-application.aspx (Eric Moreau, the author, is a regular here on EE). A follow-up column, http://www.emoreau.com/Entries/Articles/2006/10/Crystal-Reports--Part-II.aspx, actually has a more succinct way to output the report to PDF.
0
 

Author Closing Comment

by:vcharles
ID: 39631730
Thank You.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Icons and Colors for Terms 3 24
Linq Help 1 35
I need help embedding an image as HTML in my vb.net application 3 50
Problem to error 4 46
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now