472,958 Members | 1,475 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

CrystalReport.NET exporting to Excel Problem

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.

Nov 19 '05 #1
1 3098
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.

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: sridevi | last post by:
Hello How to export data from ms-access database to excel worksheet using ASP. mainly i need to export data to multiple worksheets. it is very urgent to us. i have a sample code which works...
4
by: D | last post by:
I've created a report with many subreports of aggregate data. I want my client to be able to export this data to Excel to make her charts, etc. Only one problem: one of the fields is a "SchoolYear"...
2
by: Kenneth | last post by:
How do I remove the limitation in Access that deny me from exporting 24000 rows and 17 columns (in a query) into Excel? Kenneth
2
by: Regnab | last post by:
I've got my code working so that it'll count the number of columns in the table and move across (eg Range A-P and then range Q-W). Problem is when I get to the end of the single letters and get...
0
by: crjunk | last post by:
According to the help files: ----- Exporting Reports with the Export Button The Export button is located at the top left corner of the CrystalReportViewer toolbar. When users click the Export...
0
by: David Dvali | last post by:
Hello. I have some strange problem and will be very thankful if anybody will help me to solve it. In my ASP.NET web form I have used CrystalReport to produce some report, now I want to export...
0
by: David Dvali | last post by:
Hello. I have some strange problem and will be very thankful if anybody will help me to solve it. In my ASP.NET web form I have used CrystalReport to produce some report, now I want to export...
0
by: David Dvali | last post by:
Hello. I'm exporting CrystalReport into some formats, whne I export to Excel or PDF it works fine, but when I export it in HTML it shows me the error: ...
2
by: Snozz | last post by:
The short of it: If you needed to import a CSV file of a certain structure on a regular basis(say 32 csv files, each to one a table in 32 databases), what would be your first instinct on how to...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.