Home All Groups Group Topic Archive Search About

Export CR to Excel problem

Author
9 Jun 2006 10:19 AM
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

Author
15 Jun 2006 7:25 AM
Alison Givens
Nobody?



Show quoteHide quote
"Alison Givens" <i***@cross-it.nl> wrote in message
news:OmS8m46iGHA.4716@TK2MSFTNGP03.phx.gbl...
> 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
>
Author
15 Jun 2006 1:34 PM
Sanjib Biswas
Hi Alison,

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

Sanjib

Show quoteHide quote
"Alison Givens" <i***@cross-it.nl> wrote in message
news:eSDhQzEkGHA.1000@TK2MSFTNGP04.phx.gbl...
> Nobody?
>
>
>
> "Alison Givens" <i***@cross-it.nl> wrote in message
> news:OmS8m46iGHA.4716@TK2MSFTNGP03.phx.gbl...
>> 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
>>
>
>
Author
16 Jun 2006 2:34 PM
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.






Show quoteHide quote
"Sanjib Biswas" <sanjib.bis***@ieee.org> wrote in message
news:%23X3DECIkGHA.3496@TK2MSFTNGP02.phx.gbl...
> Hi Alison,
>
> myExportFile = exportPath & "myExcel.xls"
> Instead of ExportFormatType.PortableDocFormat use ExportFormatType.Excel
>
> Sanjib
>
> "Alison Givens" <i***@cross-it.nl> wrote in message
> news:eSDhQzEkGHA.1000@TK2MSFTNGP04.phx.gbl...
>> Nobody?
>>
>>
>>
>> "Alison Givens" <i***@cross-it.nl> wrote in message
>> news:OmS8m46iGHA.4716@TK2MSFTNGP03.phx.gbl...
>>> 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
>>>
>>
>>
>
>