Export CR to Excel problem

A

Alison Givens

Hi there,
I am using VB.NET2003 with CR.
I have a good working webform that exports the CR to pdf when I hit the
print button.
Now what I want is that it exports the CR to Excel instead of Pdf.
I have tried some options but it always goes wrong with the parameters.

Can anybody help me to modify my code that works for pdf so that it will
work for excel.
I really like it to be modified, so please no completely different solution
with the chance that it will not work for the parameters.
(When possible ofcourse)


This is the code:
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.CrystalReports.Engine.ReportDocument
Imports CrystalDecisions.Shared
Imports System.IO


Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
Dim BeginPeriode As Date
Dim EindPeriode As Date

BeginPeriode = Session("BeginPeriode")
EindPeriode = Session("EindPeriode")

Dim myReport As New _Rapport_KO_ZonderContract

Dim myParameterFields As New ParameterFields
Dim myParameterField As New ParameterField
Dim myRangeValues As New ParameterRangeValue
Dim myRangeValue As New ParameterRangeValue
myParameterField.ParameterFieldName = "Periode"
myRangeValue.StartValue = BeginPeriode
myRangeValue.EndValue = EindPeriode

myReport.SetParameterValue("Periode", myRangeValue)

crViewer.ReportSource = myReport


'export to pdf
Dim myExportOptions As CrystalDecisions.Shared.ExportOptions
Dim myDiskFileDestinationOptions As
CrystalDecisions.Shared.DiskFileDestinationOptions
Dim myExportFile As String

myExportFile = "\\192.168.2.106\syn2sql$\PDF_" &
Session.SessionID.ToString & ".pdf"
myDiskFileDestinationOptions = New
CrystalDecisions.Shared.DiskFileDestinationOptions
myDiskFileDestinationOptions.DiskFileName = myExportFile
myExportOptions = myReport.ExportOptions
With myExportOptions
.DestinationOptions = myDiskFileDestinationOptions
.ExportDestinationType = .ExportDestinationType.DiskFile
.ExportFormatType = .ExportFormatType.PortableDocFormat


End With

Try
myReport.Export()
Catch err As Exception
Response.Write("<BR>")
Response.Write(err.Message.ToString)
End Try

Session("exportbestand") = myExportFile

End Sub


Kind regards,
Alison
 
S

Sanjib Biswas

Hi Alison,

myExportFile = exportPath & "myExcel.xls"
Instead of ExportFormatType.PortableDocFormat use ExportFormatType.Excel

Sanjib
 
A

Alison Givens

I tried that but that doesn't work.
Btw, I saw that I forgot to post the printbutton code.
This is it:
Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdPrint.Click
Response.ClearContent()
Response.ClearHeaders()
'Response.ContentType = "application/pdf"
Response.ContentType = "application/xls"

Dim myExportFile As String = CType(Session.Item("exportbestand"),
String)

Response.WriteFile(myExportFile)
Response.Flush()
Response.Close()

System.IO.File.Delete(myExportFile)
End Sub

As you can see I also changed the Response.ContentType but that doesn't do
the trick aswell.

Alison.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top