Connecting Tech Pros Worldwide Forums | Help | Site Map

exporting crystal report to Excel

Mustufa Baig
Guest
 
Posts: n/a
#1: Nov 19 '05
Hi everybody,

I have an ASP.NET website where clients can view their monthly billings by
selecting different options. One of the option is the way they want to see
the report i.e. whether they want to see it in PDF or EXCEL etc etc.....
What I am trying to acheive is depending on their choice of format, I want
to send the stream of that particulae selected format to the browser. I have
tried couple od solutions but I couldn't able to get them to work. Following
is one of them.

Following should work but I m getting the following error: "Thread was being
aborted."

----------------------------------------------------------------------------
---------------------------------

Private Sub xlsExport()

Dim oStream As New System.IO.MemoryStream()

oStream = myReport.ExportToStream(ExportFormatType.PortableD ocFormat)

Response.Clear()

Response.Buffer() = True

Response.ContentType = "application/pdf"

Try

Response.BinaryWrite(oStream.ToArray())
<--------------------- error occured after this

Response.End()

Catch err As Exception

Response.Write("< BR >")

Response.Write(err.Message.ToString)

End Try

End Sub

-------------------------------------------------------------------------

Any help or sugestion will be highly appreciated.

Thanks.



Elton W
Guest
 
Posts: n/a
#2: Nov 19 '05

re: exporting crystal report to Excel


Hi Mustufa,

You can try following code:

Dim oStream As System.IO.MemoryStream =
myReport.ExportToStream(ExportFormatType.PortableD ocFormat)
' No need a New MemoryStream

Response.Clear()

Response.Buffer() = True

Response.ContentType = "application/pdf"

Try

Response.BinaryWrite(oStream.ToArray())

Catch err As Exception

Response.Write("< BR >")

Response.Write(err.Message.ToString)

End Try

oStream .Close() ' Close stream before end response

Response.End()

If it doesn't work, please let us know.

HTH

Elton Wang
elton_wang@hotmail.com

[color=blue]
> Hi everybody,
>
> I have an ASP.NET website where clients can view their monthly billings by
> selecting different options. One of the option is the way they want to see
> the report i.e. whether they want to see it in PDF or EXCEL etc etc.....
> What I am trying to acheive is depending on their choice of format, I want
> to send the stream of that particulae selected format to the browser. I have
> tried couple od solutions but I couldn't able to get them to work. Following
> is one of them.
>
> Following should work but I m getting the following error: "Thread was being
> aborted."
>
> ----------------------------------------------------------------------------
> ---------------------------------
>
> Private Sub xlsExport()
>
> Dim oStream As New System.IO.MemoryStream()
>
> oStream = myReport.ExportToStream(ExportFormatType.PortableD ocFormat)
>
> Response.Clear()
>
> Response.Buffer() = True
>
> Response.ContentType = "application/pdf"
>
> Try
>
> Response.BinaryWrite(oStream.ToArray())
> <--------------------- error occured after this
>
> Response.End()
>
> Catch err As Exception
>
> Response.Write("< BR >")
>
> Response.Write(err.Message.ToString)
>
> End Try
>
> End Sub
>
> -------------------------------------------------------------------------
>
> Any help or sugestion will be highly appreciated.
>
> Thanks.
>
>
>[/color]
Mustufa Baig
Guest
 
Posts: n/a
#3: Nov 19 '05

re: exporting crystal report to Excel


Thanks a lot. It worked!! But now I should tell you that it doesn't work
when I export it to Excel or some other MS office format like MsWord format.
So to export to excel, I did two changes: one is ExportFormatType.Excel AND
the other is Response.ContentType = "application/vnd.ms-excel". Apparently
it should work. But 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.



"Elton W" <EltonW@discussions.microsoft.com> wrote in message
news:9B101AE8-853E-457D-845C-909550491D72@microsoft.com...[color=blue]
> Hi Mustufa,
>
> You can try following code:
>
> Dim oStream As System.IO.MemoryStream =
> myReport.ExportToStream(ExportFormatType.PortableD ocFormat)
> ' No need a New MemoryStream
>
> Response.Clear()
>
> Response.Buffer() = True
>
> Response.ContentType = "application/pdf"
>
> Try
>
> Response.BinaryWrite(oStream.ToArray())
>
> Catch err As Exception
>
> Response.Write("< BR >")
>
> Response.Write(err.Message.ToString)
>
> End Try
>
> oStream .Close() ' Close stream before end response
>
> Response.End()
>
> If it doesn't work, please let us know.
>
> HTH
>
> Elton Wang
> elton_wang@hotmail.com
>
>[color=green]
> > Hi everybody,
> >
> > I have an ASP.NET website where clients can view their monthly billings[/color][/color]
by[color=blue][color=green]
> > selecting different options. One of the option is the way they want to[/color][/color]
see[color=blue][color=green]
> > the report i.e. whether they want to see it in PDF or EXCEL etc etc.....
> > What I am trying to acheive is depending on their choice of format, I[/color][/color]
want[color=blue][color=green]
> > to send the stream of that particulae selected format to the browser. I[/color][/color]
have[color=blue][color=green]
> > tried couple od solutions but I couldn't able to get them to work.[/color][/color]
Following[color=blue][color=green]
> > is one of them.
> >
> > Following should work but I m getting the following error: "Thread was[/color][/color]
being[color=blue][color=green]
> > aborted."
> >[/color]
>
> --------------------------------------------------------------------------[/color]
--[color=blue][color=green]
> > ---------------------------------
> >
> > Private Sub xlsExport()
> >
> > Dim oStream As New System.IO.MemoryStream()
> >
> > oStream =[/color][/color]
myReport.ExportToStream(ExportFormatType.PortableD ocFormat)[color=blue][color=green]
> >
> > Response.Clear()
> >
> > Response.Buffer() = True
> >
> > Response.ContentType = "application/pdf"
> >
> > Try
> >
> > Response.BinaryWrite(oStream.ToArray())
> > <--------------------- error occured after this
> >
> > Response.End()
> >
> > Catch err As Exception
> >
> > Response.Write("< BR >")
> >
> > Response.Write(err.Message.ToString)
> >
> > End Try
> >
> > End Sub
> >[/color]
>
> -------------------------------------------------------------------------[color=green]
> >
> > Any help or sugestion will be highly appreciated.
> >
> > Thanks.
> >
> >
> >[/color][/color]


Closed Thread