473,289 Members | 2,108 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,289 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 3131
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.