Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > CrystalReport.NET exporting to Excel Problem

Reply
Thread Tools

CrystalReport.NET exporting to Excel Problem

 
 
Mustufa Baig
Guest
Posts: n/a
 
      05-16-2005
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.



 
Reply With Quote
 
 
 
 
=?Utf-8?B?RWx0b24gVw==?=
Guest
Posts: n/a
 
      05-16-2005
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.
>
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting to Excel using new version of Excel Doogie ASP .Net 1 11-19-2008 09:10 PM
Problem with Excel reports ::::Excel 2003 Migration To Excel 2007 =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?= ASP .Net 15 10-24-2007 01:34 PM
exporting an excel file from database; making changes to excel file and updating the database by importing it back Luis Esteban Valencia ASP .Net 1 01-12-2005 12:28 AM
Urgent!!!!! Problem while exporting data to excel sheet in ap.net =?Utf-8?B?U2lsZWVzaA==?= ASP .Net 4 11-05-2004 10:57 PM
Exporting data to Microsoft Excel from a Web Form (using OWC) problem sarah5e@yahoo.com ASP .Net 1 05-10-2004 01:45 PM



Advertisments