Solved

Help with exporting data from DataGrid View to PDF format

Posted on 2013-11-04
4
512 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

635 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