CrystalReport.NET exporting to Excel Problem

Discussion in 'ASP .Net' started by Mustufa Baig, May 16, 2005.

  1. Mustufa Baig

    Mustufa Baig Guest

    I have an ASP.NET website where I am showing off crystal reports to users by
    exporting them to pdf format. Following is the code:
    ----------------
    1 Private Sub ExportReport()
    2 Dim oStream As System.IO.MemoryStream =
    3 myReport.ExportToStream(
    ExportFormatType.PortableDocFormat)

    4 Response.Clear()
    5 Response.Buffer() = True
    6 Response.ContentType = "application/pdf"
    7 Try
    8 Response.BinaryWrite(oStream.ToArray())
    9 Catch err As Exception
    10 Response.Write("< BR >")
    11 Response.Write(err.Message.ToString)
    12 End Try
    13 oStream.Close()
    14 Response.End()
    15 End Sub
    -----------------------
    This code working absolutely fine. But if I want to export the reports to
    EXCEL format then I just need to change lines 3 and 6:

    3 ==> myReport.ExportToStream(
    ExportFormatType.Excel)

    6 ==> Response.ContentType = "application/vnd.ms-excel"

    After the above alterations the should work fine but it doesn't. I even
    tried to export to MS Word but it didn't work as well. Following is the
    explaination what actually happening:

    So after user clicks View Report, what happening is the excel application
    opens in the browser but showing no report just saying : "You are curently
    not logged in.
    Please Log in first!". This is kind of weird to me because this message only
    comes when somebody tries to access my website's any page without Logging
    In. So to find out whats going wrong I put a break point at Page_Init
    procedure. So I step through each line and just after executing
    Response.End() statement I found that the page loads itself and as result of
    that it breaks again at Page_Init procedure. But as I am checking at the
    begining whether user is logged in or not and apparently when this page gets
    executed 2nd time, it doesn't have any session information thus resulting
    "You are curently not logged in. Please Log in first!" message but displays
    in the excel application opened in the browser. One more thing I also
    observed that whenever I clicked to get the report, I always see a small
    window appearing for very short period of time at the top left corner with a
    progress bar stating "Transfering...
    http://localhost/webreadfile/report.aspx". I really don't know whats causing
    this twice execution because it only happens when I try to export cystal
    report to some MS Office format such as MS Excel.

    I also tried to put trace on and there I also confirmed it that this page is
    getting executed twice in case of exporting to Excel format. Exporting to
    PDF works perfect.

    I would really really appreciate your help.

    thanks.
     
    Mustufa Baig, May 16, 2005
    #1
    1. Advertising

  2. Hi Mustufa,

    I suppose you are using Office 2000 in client-side. I think there is a bug
    in Office 2000 that causes IE cannot show Excel (or Word) file properly. In
    my experience, you use 'attachment' to get exported office file:

    Private Sub ExportReport()
    Dim oStream As System.IO.MemoryStream =
    myReport.ExportToStream(
    ExportFormatType.Excel)
    Response.Clear()
    Response.AddHeader("content-disposition", "attachment;
    filename="exported.xls");
    Response.Buffer() = True
    Response.ContentType = application/vnd.ms-excel"
    Try
    Response.BinaryWrite(oStream.ToArray())
    Catch err As Exception
    Response.Write("< BR >")
    Response.Write(err.Message.ToString)
    End Try
    oStream.Close()
    Response.End()
    End Sub

    HTH

    Elton Wang



    "Mustufa Baig" wrote:

    > I have an ASP.NET website where I am showing off crystal reports to users by
    > exporting them to pdf format. Following is the code:
    > ----------------
    > 1 Private Sub ExportReport()
    > 2 Dim oStream As System.IO.MemoryStream =
    > 3 myReport.ExportToStream(
    > ExportFormatType.PortableDocFormat)
    >
    > 4 Response.Clear()
    > 5 Response.Buffer() = True
    > 6 Response.ContentType = "application/pdf"
    > 7 Try
    > 8 Response.BinaryWrite(oStream.ToArray())
    > 9 Catch err As Exception
    > 10 Response.Write("< BR >")
    > 11 Response.Write(err.Message.ToString)
    > 12 End Try
    > 13 oStream.Close()
    > 14 Response.End()
    > 15 End Sub
    > -----------------------
    > This code working absolutely fine. But if I want to export the reports to
    > EXCEL format then I just need to change lines 3 and 6:
    >
    > 3 ==> myReport.ExportToStream(
    > ExportFormatType.Excel)
    >
    > 6 ==> Response.ContentType = "application/vnd.ms-excel"
    >
    > After the above alterations the should work fine but it doesn't. I even
    > tried to export to MS Word but it didn't work as well. Following is the
    > explaination what actually happening:
    >
    > So after user clicks View Report, what happening is the excel application
    > opens in the browser but showing no report just saying : "You are curently
    > not logged in.
    > Please Log in first!". This is kind of weird to me because this message only
    > comes when somebody tries to access my website's any page without Logging
    > In. So to find out whats going wrong I put a break point at Page_Init
    > procedure. So I step through each line and just after executing
    > Response.End() statement I found that the page loads itself and as result of
    > that it breaks again at Page_Init procedure. But as I am checking at the
    > begining whether user is logged in or not and apparently when this page gets
    > executed 2nd time, it doesn't have any session information thus resulting
    > "You are curently not logged in. Please Log in first!" message but displays
    > in the excel application opened in the browser. One more thing I also
    > observed that whenever I clicked to get the report, I always see a small
    > window appearing for very short period of time at the top left corner with a
    > progress bar stating "Transfering...
    > http://localhost/webreadfile/report.aspx". I really don't know whats causing
    > this twice execution because it only happens when I try to export cystal
    > report to some MS Office format such as MS Excel.
    >
    > I also tried to put trace on and there I also confirmed it that this page is
    > getting executed twice in case of exporting to Excel format. Exporting to
    > PDF works perfect.
    >
    > I would really really appreciate your help.
    >
    > thanks.
    >
    >
    >
    >
     
    =?Utf-8?B?RWx0b24gVw==?=, May 16, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. crjunk

    Export CrystalReport to Excel

    crjunk, Oct 11, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    635
    crjunk
    Oct 11, 2004
  2. Luis Esteban Valencia
    Replies:
    1
    Views:
    1,416
    Carl Prothman [MVP]
    Jan 12, 2005
  3. David Dvali
    Replies:
    0
    Views:
    431
    David Dvali
    Aug 16, 2005
  4. David Dvali
    Replies:
    0
    Views:
    372
    David Dvali
    Aug 16, 2005
  5. Doogie
    Replies:
    1
    Views:
    470
    sloan
    Nov 19, 2008
Loading...

Share This Page