473,382 Members | 1,357 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 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 3139
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.