Generating XLS files from ASP

G

Guest

Hi All,
I'm generating XLS files from ASP(.Net) code using the usual code
chunks ...

Response.ContentType = "application/vnd.ms-excel"
Response.AppendHeader("Content-Disposition", "attachment; filename=""" &

NomeFile & """")
Response.Flush()
Response.write("<table border=""1"" .....
......
......
Response.end

It all works fine since I'm able to Open/Save the file with Excel 2000. But
.....
....... when I run the code on a box where only an Excel Viewer 2003 is
installed (rather then the full product) I cannot open it, and Viewer aborts
with the following Message : "Cannot Open files of this type".
Choosing to save save the file to reopen it laterleads to the same error.

Moreover, the generated XLS file looks to be really small ....(1Kb) and
after opening and resaving it from Excel program as a xls Workbook it becomes
larger (14Kb). At this point the viewer can open it.. ...

All this let me think that the generated file is not a "real" xls file ....
while viewer can only open this kind of files ... (also tried to use freeware
viewer but I got the same behaviour .....)

Any help is appreciated .... Thanks in advance Daniele Balducci
 
H

Hans Kesting

daniele.balducci said:
Hi All,
I'm generating XLS files from ASP(.Net) code using the usual
code chunks ...

Response.ContentType = "application/vnd.ms-excel"
Response.AppendHeader("Content-Disposition", "attachment;
filename=""" &

NomeFile & """")
Response.Flush()
Response.write("<table border=""1"" .....
.....
.....
Response.end

It all works fine since I'm able to Open/Save the file with Excel
2000. But ....
...... when I run the code on a box where only an Excel Viewer 2003 is
installed (rather then the full product) I cannot open it, and Viewer
aborts with the following Message : "Cannot Open files of this type".
Choosing to save save the file to reopen it laterleads to the same
error.

Moreover, the generated XLS file looks to be really small ....(1Kb)
and after opening and resaving it from Excel program as a xls
Workbook it becomes larger (14Kb). At this point the viewer can open
it.. ...

All this let me think that the generated file is not a "real" xls
file .... while viewer can only open this kind of files ... (also
tried to use freeware viewer but I got the same behaviour .....)

Any help is appreciated .... Thanks in advance Daniele Balducci

You are right. When you use Response.Write("<table ..."),
you are generating an HTML file (containing a single table). Using the
extension of the supplied filename (and/or the contenttype), the
browser is tricked into launching Excel to "open" this file.
Excel knows how to decode that HTML file. Apparently the
viewer does not :-(
When you save the file from Excel, it saves is as a "real" Excel-file,
that is why it's 14 times as big (at least, your example is), and the
viewer can handle it.

Sorry, I can't help you to generate a real xls file, I think you will
need to use Excel on the server for that...

Hans Kesting
 
G

Guest

Hello Hans, Thanks from your quick answer.

I fear it will not possible to install one more Excel ... I'll tell the
users that
my application has been designed to work from clients where Excel is
installed as part
of the standard SW platform ,,, ;-)

May be the will not get too angry .... Ciao Daniele
 
G

Guest

You could build a tab or comma separated text file which can definately be
opened by excel and almost certainly an excel viewer... jd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top