By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,794 Members | 1,192 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,794 IT Pros & Developers. It's quick & easy.

Generating XLS files from ASP

P: n/a
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

Nov 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
daniele.balducci wrote:
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
Nov 19 '05 #2

P: n/a
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

"Hans Kesting" wrote:
daniele.balducci wrote:
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

Nov 19 '05 #3

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

"daniele.balducci" wrote:
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

"Hans Kesting" wrote:
daniele.balducci wrote:
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

Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.