below handler is help me to save my html content to excel format file, previously i save as .xls is ok, but after i change to .xlsx, i get error message when i try to open the .xlsx file
Excel cannot open the file "Report.xlsx" because the file format or extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file.
does possible to save html content to .xlsx file?
if possible, i suspect i missing some driver, currently im using framework 3.5 and microsoft excel 2010 installed.
if not possible, what else other method to save html content as .xlsx excel format?
do have some expert kindly advise me? Thanks...
<%@ WebHandler Language="VB" class="Handler" %>
Imports System Imports System.Web Imports System.Data Imports System.IO
Public Class Handler : Implements IHttpHandler Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest Dim id As String = context.Request.QueryString("id") Dim category As String = context.Request.QueryString("category") Dim P As String = context.Request.QueryString("P") Dim V As String = context.Request.QueryString("V")
No. You can't create valid .xlsx files like this. You have a number of options: Office Interop,
OpenXML or a third party library. There are a few around, but no free ones that I know of.
i open .xls in excel 2013 it will prompt me this warning msg
the file format and extension of 'report.xls' don't match. the file could be corrupted or unsafe. unless you trust its source, don't open it, do you want to open it anyway?
whatever i try to is to no display this warning msg when open it, do you have any idea on this metter?
Since 2007, this warning appears when you create an HTML file and save it as Excel. If you cannot ask your users to tolerate the warning, then you have to use one of the other methods for creating Excel files that I outlined.
Lye
Member
50 Points
115 Posts
HELP!! fail to save html content as excel .xlsx
Feb 19, 2013 01:22 AM|LINK
below handler is help me to save my html content to excel format file, previously i save as .xls is ok, but after i change to .xlsx, i get error message when i try to open the .xlsx file
Excel cannot open the file "Report.xlsx" because the file format or extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file.
does possible to save html content to .xlsx file?
if possible, i suspect i missing some driver, currently im using framework 3.5 and microsoft excel 2010 installed.
if not possible, what else other method to save html content as .xlsx excel format?
do have some expert kindly advise me? Thanks...
<%@ WebHandler Language="VB" class="Handler" %>
Imports System
Imports System.Web
Imports System.Data
Imports System.IO
Public Class Handler : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim id As String = context.Request.QueryString("id")
Dim category As String = context.Request.QueryString("category")
Dim P As String = context.Request.QueryString("P")
Dim V As String = context.Request.QueryString("V")
context.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
context.Response.AddHeader("Content-Disposition", "attachment;filename=" & GlobalVariable.rpt_name & ".xlsx")
Dim _str As String
_str = "<table><head><body>aa<br>bb<br>cc</body></head></table>"
context.Response.Write(_str)
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
Mikesdotnett...
All-Star
155645 Points
19985 Posts
Moderator
MVP
Re: HELP!! fail to save html content as excel .xlsx
Feb 19, 2013 04:49 AM|LINK
No. You can't create valid .xlsx files like this. You have a number of options: Office Interop, OpenXML or a third party library. There are a few around, but no free ones that I know of.
Or you can create a blank sheet and use the ACE OleDb provider to insert rows as if it was a database. Then save the result with a new file name and send that the to the client. Here's some help with doing that: http://yoursandmyideas.wordpress.com/2011/02/05/how-to-read-or-write-excel-file-using-ace-oledb-data-provider/
Web Pages CMS | My Site | Twitter
Lye
Member
50 Points
115 Posts
Re: HELP!! fail to save html content as excel .xlsx
Feb 19, 2013 09:29 AM|LINK
Office Interop, OpenXML or other quite hard for me because i have to insert value to cell one by one
second method i may consider if border and background color can also been imported
i also try to turn off warning msg in excel 2013, i success to turn off on excel 2010 but fail on excel 2013, possible?
Mikesdotnett...
All-Star
155645 Points
19985 Posts
Moderator
MVP
Re: HELP!! fail to save html content as excel .xlsx
Feb 19, 2013 05:48 PM|LINK
Why not just save it as .xls? Office 2007+ will open it.
Web Pages CMS | My Site | Twitter
Lye
Member
50 Points
115 Posts
Re: HELP!! fail to save html content as excel .xlsx
Feb 20, 2013 01:29 AM|LINK
very thanks for your reply
i open .xls in excel 2013 it will prompt me this warning msg
the file format and extension of 'report.xls' don't match. the file could be corrupted or unsafe. unless you trust its source, don't open it, do you want to open it anyway?
whatever i try to is to no display this warning msg when open it, do you have any idea on this metter?
Mikesdotnett...
All-Star
155645 Points
19985 Posts
Moderator
MVP
Re: HELP!! fail to save html content as excel .xlsx
Feb 20, 2013 04:22 AM|LINK
Since 2007, this warning appears when you create an HTML file and save it as Excel. If you cannot ask your users to tolerate the warning, then you have to use one of the other methods for creating Excel files that I outlined.
Web Pages CMS | My Site | Twitter
Lye
Member
50 Points
115 Posts
Re: HELP!! fail to save html content as excel .xlsx
Feb 22, 2013 08:22 AM|LINK
thanks for your reply
so what is the best method can import from html to excel file without insert to cell one by one and warning appears?
Mikesdotnett...
All-Star
155645 Points
19985 Posts
Moderator
MVP
Re: HELP!! fail to save html content as excel .xlsx
Feb 22, 2013 11:28 AM|LINK
I would use JET and treat the worksheet like a database.
Web Pages CMS | My Site | Twitter