I have the below piece of code using which I am able to successfully export data into an Excel 2003 file (.xls file). Currently I would need to export the HTML data to excel 2010(.xlsx) format
Dim strw As New System.IO.StringWriter()
Dim htmlw As New HtmlTextWriter(strw)
strw.GetStringBuilder.Append("<table>")
strw.GetStringBuilder.Append("</table>")
strw.GetStringBuilder.Append("<table>")
strw.GetStringBuilder.Append("<tr>")
strw.GetStringBuilder.Append("<td colspan=9 align=left>")
strw.GetStringBuilder.Append("<B><font size='4'>")
strw.GetStringBuilder.Append("TEST HTML Data")
strw.GetStringBuilder.Append("</font>")
strw.GetStringBuilder.Append("</td>")
strw.GetStringBuilder.Append("</tr></table>")
strw.GetStringBuilder.Append("<br>")
Response.Write(strw)
Response.End()
This piece of code gave me the below error and it didn't open the excel sheet
"Excel cannot open the file 'Test.xlsx' because the file format or
file extension is not valid. Verify that the file has not been
corrupted and the file extension matches the format of the file."
I read in some articles that HTML contants are not supported in excel 2007 and excel 2010, is that true? are there any work around for this issue?
In the Response.AddHeader I have used the extention as ".xls", in this case it gave me a different warning message but finally it opened the data in excel (but the file is in 2003 format). Is there any way to supress this warning message, other than changing
any registry values.
Could anyone please help me with the change required. This is a critial issue for my application, any help in this is greatly appreciated.
<div class="message">Thanks for the reply, however in that case I am getting the below warning message, is there anyway to remove this warning message.</div> <div class="message"></div> <div class="message">The file you are trying to open, 'report.xls',
is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?</div>
Is there any way to hide this warning message from the .net code, other than adding the registry key. Since it is a web application, creating the registry key in all the client machines is not possible.
Sarunps
Member
4 Points
4 Posts
How to export HTML contents in to excel 2010(.xlsx) fromat
Jan 30, 2012 10:11 AM|LINK
Hi All,
I have the below piece of code using which I am able to successfully export data into an Excel 2003 file (.xls file). Currently I would need to export the HTML data to excel 2010(.xlsx) format
Response.ClearContent()
Response.ClearHeaders()
Response.Clear()
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Response.AddHeader("Content-Disposition", "attachment; filename=report.xlsx")
Dim strw As New System.IO.StringWriter()
Dim htmlw As New HtmlTextWriter(strw)
strw.GetStringBuilder.Append("<table>")
strw.GetStringBuilder.Append("</table>")
strw.GetStringBuilder.Append("<table>")
strw.GetStringBuilder.Append("<tr>")
strw.GetStringBuilder.Append("<td colspan=9 align=left>")
strw.GetStringBuilder.Append("<B><font size='4'>")
strw.GetStringBuilder.Append("TEST HTML Data")
strw.GetStringBuilder.Append("</font>")
strw.GetStringBuilder.Append("</td>")
strw.GetStringBuilder.Append("</tr></table>")
strw.GetStringBuilder.Append("<br>")
Response.Write(strw)
Response.End()
This piece of code gave me the below error and it didn't open the excel sheet
"Excel cannot open the file 'Test.xlsx' because the file format or
file extension is not valid. Verify that the file has not been
corrupted and the file extension matches the format of the file."
I read in some articles that HTML contants are not supported in excel 2007 and excel 2010, is that true? are there any work around for this issue?
In the Response.AddHeader I have used the extention as ".xls", in this case it gave me a different warning message but finally it opened the data in excel (but the file is in 2003 format). Is there any way to supress this warning message, other than changing any registry values.
Could anyone please help me with the change required. This is a critial issue for my application, any help in this is greatly appreciated.
Thanks!
Sarun P S
</div>Sum8
Contributor
4141 Points
931 Posts
Re: How to export HTML contents in to excel 2010(.xlsx) fromat
Jan 30, 2012 11:41 AM|LINK
Instead of saving it as an .XLSX file, save it as .XLS file.
Response.AddHeader("Content-Disposition", "attachment; filename=report.xls")Sumit Pathak
------------------
ThisPost = Helped == True ? "Mark As Answer" : "Elaborate your problem in more details"
Sarunps
Member
4 Points
4 Posts
Re: How to export HTML contents in to excel 2010(.xlsx) fromat
Jan 30, 2012 12:39 PM|LINK
Sum8
Contributor
4141 Points
931 Posts
Re: How to export HTML contents in to excel 2010(.xlsx) fromat
Jan 31, 2012 04:53 AM|LINK
Refer these links:
http://www.itexperience.net/excel-2007-error-different-format-than-specified-by-the-file-extension/
http://support.microsoft.com/kb/948615
http://www.dotnetspider.com/resources/35928-Generating-Exporting-an-Excel-File-ASP-NET.aspx
Sumit Pathak
------------------
ThisPost = Helped == True ? "Mark As Answer" : "Elaborate your problem in more details"
Sarunps
Member
4 Points
4 Posts
Re: How to export HTML contents in to excel 2010(.xlsx) fromat
Jan 31, 2012 05:46 AM|LINK
Is there any way to hide this warning message from the .net code, other than adding the registry key. Since it is a web application, creating the registry key in all the client machines is not possible.
Sum8
Contributor
4141 Points
931 Posts
Re: How to export HTML contents in to excel 2010(.xlsx) fromat
Jan 31, 2012 06:16 AM|LINK
I didn't found any solution to be implemented in .Net .
If you get it, please post here.
Sumit Pathak
------------------
ThisPost = Helped == True ? "Mark As Answer" : "Elaborate your problem in more details"
jaromedubois
Member
2 Points
1 Post
Re: How to export HTML contents in to excel 2010(.xlsx) fromat
Dec 06, 2012 03:37 PM|LINK
Here, I tried this .NET library and it worked.