dynamic XLSX files from a web page


R

Ryan

Hello,
I generate an .xls file from an asp.net page. It works fine to open it with
Excel 2003. However, when I test it on a machine installed Excel 2007, it
pops up an alert message. I know we can get rid of the alert message by
modifying the client PC's registry with the following solution, but in our
case, it's not realistic.

Problem and solution :

Excel 2007 Extension Warning On Opening Excel Workbook from a Web Site

http://blogs.msdn.com/vsofficedeveloper/pages/Excel-2007-Extension-Warning.aspx

QUESTION:

I have tried to let the output file extension name to be ".xlsx" to avoid
this message, but Excel 2007 still cannot open the.xlsx file.

So what will be the solution to generate xlsx file on the fly?
I have tried with both "content-type:"
response.ContentType= "application/vnd.ms-excel"
and
response.ContentType
="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

I also read this article:

http://blogs.msdn.com/vsofficedeveloper/pages/Office-2007-Open-XML-MIME-Types.aspx

Then, I made sure that I have both MIME type on my web server, but still
doesn't work.
1) .xls = application/ms-excel
2) .xlsx = application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

For reference, this is my code :
html.Append("<table border=""1"">")
html.Append("<tr bgcolor=""#CEE7FF"">")
html.Append("<th>" & HttpUtility.HtmlEncode("Priority") & "</th>")
html.Append("<th>" & HttpUtility.HtmlEncode("Status") & "</th>")
html.Append("<th>" & HttpUtility.HtmlEncode("Call Id") & "</th>")
html.Append("<th>" & HttpUtility.HtmlEncode("Client") & "</th>")
html.Append("<th>" & HttpUtility.HtmlEncode("Support Type") & "</th>")
html.Append("<th>" & HttpUtility.HtmlEncode("Description") & "</th>")
html.Append("<th>" & HttpUtility.HtmlEncode("FRC") & "</th>")
html.Append("<th>" & HttpUtility.HtmlEncode("Unit") & "</th>")
html.Append("<th>" & HttpUtility.HtmlEncode("Assigned date") & "</th>")
html.Append("<th>" & HttpUtility.HtmlEncode("Assigned time") & "</th>")
html.Append("<th>" & HttpUtility.HtmlEncode("Resolved date") & "</th>")
html.Append("<th>" & HttpUtility.HtmlEncode("Resolved time") & "</th>")
html.Append("<th>" & HttpUtility.HtmlEncode("Assignee") & "</th>")
html.Append("</tr>")
html.Append("</table>")
Response.ClearContent()
Response.AddHeader("Content-Disposition:",
"attachment;filename=HeatReport.xlsx")
Response.ContentType =
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Response.Write(html.ToString)
Response.End()

I think that even if I name my report with the .xlsx extension, it's not
recognised as a real .xlsx report. I guess something is missing.
Could you please let me know the good way to make this work?

Thanks
 
Ad

Advertisements

S

Steven Cheng

Hi Ryan,

Thanks for your posting. Since the question you mentioned is an ASP.NET web
application issue, I would suggest you post in the those ASP.NET specific
newsgroups in the future:

microsoft.public.dotnet.framework.aspnet

As for the problem you mentioned here, I think it is due to the content you
write out in ASP.NET page is in HTML format instead of the expected xls or
xlsx (excel native format) content. And excel 2007 program is abit more
restrict on such format and result to the prompt dialog. I'm afraid such
kind of HTML or csv like format data cannot bypass the format
validation(and the warning).

BTW, for office 2007 document, you can use the OOXML sdk to programmtically
generate the document that conform the format:

#Getting Started with the Open XML Format SDK 2.0
http://msdn.microsoft.com/en-us/library/bb456488(office.14).aspx

http://msdn.microsoft.com/en-us/office/bb265236.aspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
--------------------
Thread-Topic: dynamic XLSX files from a web page
thread-index: AcnDpIQHsFlueoQbQaq4UTTDZrASdg==
X-WBNR-Posting-Host: 72.136.156.124
From: =?Utf-8?B?Unlhbg==?= <[email protected]>
Subject: dynamic XLSX files from a web page
Date: Wed, 22 Apr 2009 16:46:11 -0700
Hello,
I generate an .xls file from an asp.net page. It works fine to open it with
Excel 2003. However, when I test it on a machine installed Excel 2007, it
pops up an alert message. I know we can get rid of the alert message by
modifying the client PC's registry with the following solution, but in our
case, it's not realistic.

Problem and solution :

Excel 2007 Extension Warning On Opening Excel Workbook from a Web Site
http://blogs.msdn.com/vsofficedeveloper/pages/Excel-2007-Extension-Warning.a
spx

QUESTION:

I have tried to let the output file extension name to be ".xlsx" to avoid
this message, but Excel 2007 still cannot open the.xlsx file.

So what will be the solution to generate xlsx file on the fly?
I have tried with both "content-type:"
response.ContentType= "application/vnd.ms-excel"
and
response.ContentType
="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

I also read this article:
http://blogs.msdn.com/vsofficedeveloper/pages/Office-2007-Open-XML-MIME-Type
s.aspx

Then, I made sure that I have both MIME type on my web server, but still
doesn't work.
1) .xls = application/ms-excel
2) .xlsx = application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

For reference, this is my code :
html.Append("<table border=""1"">")
html.Append("<tr bgcolor=""#CEE7FF"">")
html.Append("<th>" & HttpUtility.HtmlEncode("Priority") & "</th>")
html.Append("<th>" & HttpUtility.HtmlEncode("Status") & "</th>")
html.Append("<th>" & HttpUtility.HtmlEncode("Call Id") & "</th>")
html.Append("<th>" & HttpUtility.HtmlEncode("Client") & "</th>")
html.Append("<th>" & HttpUtility.HtmlEncode("Support Type") & "</th>")
html.Append("<th>" & HttpUtility.HtmlEncode("Description") & "</th>")
html.Append("<th>" & HttpUtility.HtmlEncode("FRC") & "</th>")
html.Append("<th>" & HttpUtility.HtmlEncode("Unit") & "</th>")
html.Append("<th>" & HttpUtility.HtmlEncode("Assigned date") & "</th>")
html.Append("<th>" & HttpUtility.HtmlEncode("Assigned time") & "</th>")
html.Append("<th>" & HttpUtility.HtmlEncode("Resolved date") & "</th>")
html.Append("<th>" & HttpUtility.HtmlEncode("Resolved time") & "</th>")
html.Append("<th>" & HttpUtility.HtmlEncode("Assignee") & "</th>")
html.Append("</tr>")
html.Append("</table>")
Response.ClearContent()
 

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

Top