Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > .NET Framework 1.x
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
.NET Framework 1.x For discussing versions 1.0 and 1.1 of the Microsoft .NET Framework.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 1.x section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 11th, 2008, 02:20 AM
Registered User
Join Date: Aug 2007
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem in exporting crystal report to excel.

Am getting this error
"System.NullReferenceException: Object reference not set to an instance of an object."

This error comes when i am trying to export crystal report in excel format.
Exporting to pdf works fine though.

On local development machine, exporting to pdf and excel works.
On server, only exporting to pdf works..exporting to excel throws this error.

can anyone pls help. Below is my code sample for export button click.
Private Sub Btn_Export_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_Export.Click
            Dim oStream As New MemoryStream
            Me.Crystalreportviewer1.ReportSource = Server.MapPath("Capex_Summary.rpt")
            Dim ParamFields As ParameterFields = Me.Crystalreportviewer1.ParameterFieldInfo
            Dim Per As New ParameterField
            Per.ParameterFieldName = "Period"
            Dim ParamCurrentValues As New ParameterValues
            Dim Period_Value As New ParameterRangeValue
            Period_Value.StartValue = Me.txtSTdate.Text
            Period_Value.EndValue = Me.txtCLdate.Text

            'Set Division Paramter                
            Dim GetDivisionValues As String
            GetDivisionValues = Trim(Request.Form(ddl_division.UniqueID))
            Per = New ParameterField
            ParamCurrentValues = New ParameterValues
            Per.ParameterFieldName = "Division"
            Dim Division_Value As New ParameterDiscreteValue
            If GetDivisionValues = "Select All" Then
                Division_Value.Value = "*"
                Division_Value.Value = GetDivisionValues
            End If

            'Set Department Parameter
            Dim GetDeptValues As String
            GetDeptValues = Trim(Request.Form(ddl_department.UniqueID))
            Per = New ParameterField
            ParamCurrentValues = New ParameterValues
            Per.ParameterFieldName = "Department"
            Dim Department_Value As New ParameterDiscreteValue
            If GetDeptValues = "Select All" Then
                Department_Value.Value = "*"
                Department_Value.Value = GetDeptValues
            End If

            Dim GetCategory As String
            GetCategory = Trim(Request.Form(ddl_Category.UniqueID))
            Per = New ParameterField
            ParamCurrentValues = New ParameterValues
            Per.ParameterFieldName = "Category"
            Dim Category_Value As New ParameterDiscreteValue
            If GetCategory = "Select All" Then
                Category_Value.Value = "*"
                Category_Value.Value = GetCategory
            End If
            'crReportDocument.SetDatabaseLogon(gbVariables.strUsrName, gbVariables.strUsrPwd, gbVariables.strServerName, gbVariables.strDBName)
            Dim ExportFormatType As String
            ExportFormatType = Trim(Request.Form(ddl_export.UniqueID))
            Select Case ExportFormatType
                Case "Portable Document (PDF)"
                    crReportDocument.SetDatabaseLogon(gbVariables.strUsrName, gbVariables.strUsrPwd, gbVariables.strServerName, gbVariables.strDBName)
                    'oStream = crReportDocument.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat)
                    oStream = DirectCast(crReportDocument.ExportToStream(CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat), MemoryStream)
                    Response.Buffer = True
                    Response.ContentType = "application/pdf"
                Case "MS Excel (XLS)"
                    crReportDocument.SetDatabaseLogon(gbVariables.strUsrName, gbVariables.strUsrPwd, gbVariables.strServerName, gbVariables.strDBName)
                    'oStream = crReportDocument.ExportToStream(CrystalDecisions.Shared.ExportFormatType.Excel)
                    oStream = DirectCast(crReportDocument.ExportToStream(CrystalDecisions.[Shared].ExportFormatType.Excel), MemoryStream)
                    Response.Buffer = True
                    Response.ContentType = "application/vnd.ms-excel"
            End Select            
        Catch ex As Exception
            lblError.Text = ex.Message.ToString
        End Try

Thanks to help.

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting Crystal Report To Excel mohithmohith VB.NET 1 July 12th, 2008 12:36 AM
Code for Exporting Crystal Report to Excel or PDF shakti_2505270 ASP.NET 2.0 Professional 1 October 4th, 2007 01:00 AM
Crystal Report Export problem to excel spmano1983 VB.NET 0 August 17th, 2007 01:33 AM
Exporting Crystal Report Harinder.Dhamija ASP.NET 2.0 Professional 1 July 24th, 2007 02:45 AM
problem in Exporting Crystal report to PDF cat_net Crystal Reports 0 October 3rd, 2005 11:49 PM

All times are GMT -4. The time now is 02:45 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.