C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Convert a Crystal Report to Word


Posted Date: 20 Jun 2007    Resource Type: Code Snippets    Category: Crystal Reports

Posted By: lavanya       Member Level: Gold
Rating:     Points: 10



This Code shows how to convert a Crystal Report to Word Document.




'First Create a crystal Report.
' Drag and drop the Crystal Report Viewer in the form
' copy this code on top of the code
Imports System.Data
Imports System.Data.SqlClient
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Private myDS As New Dataset1() ' Dataset you created.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim rpt As New CrystalReport1() 'The report you created.
Dim myConnection As SqlConnection
Dim MyCommand As New SqlCommand()
Dim myDA As New SqlDataAdapter()

Try

myConnection = New SqlConnection("Data Source=localhost;Integrated Security=SSPI;" & _
"Initial Catalog=pubs;")
MyCommand.Connection = myConnection
MyCommand.CommandText = "SELECT * FROM authors"
MyCommand.CommandType = CommandType.Text
myDA.SelectCommand = MyCommand

myDA.Fill(myDS, "authors")
rpt.SetDataSource(myDS)
CrystalReportViewer1.ReportSource = rpt

Catch Excep As Exception
MessageBox.Show(Excep.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'This Code is used to Convert to word document
Dim reportWord As New CrystalReport1() ' Report Name
Dim strExportFile As String = "d:\TestWord.doc"
reportWord.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile
reportWord.ExportOptions.ExportFormatType = ExportFormatType.WordForWindows
Dim objOptions As DiskFileDestinationOptions = New DiskFileDestinationOptions()
objOptions.DiskFileName = strExportFile
reportWord.ExportOptions.DestinationOptions = objOptions
reportWord.SetDataSource(myDS)
reportWord.Export()
objOptions = Nothing
reportWord = Nothing
End Sub





Responses

Author: Jagadevi basawaraj    27 May 2008Member Level: Silver   Points : 2
how to convert a datagrid to Word Document?


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Convert a Crystal Report to Excel
Previous Resource: Create pdf from crystal report
Return to Discussion Resource Index
Post New Resource
Category: Crystal Reports


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

budget conference call

Contact Us    Privacy Policy    Terms Of Use