I have been using this code for a while and it works great. Now with the new Excel 2007 format and extention (xlsx), when you open a file it has a message that the xls file is not in the expected format.
Does anyone know how to modify this code to output to the new format? I tried just changing the extention, but no change.
Response.ContentType = "application/vnd.ms-excel"
'Excel 2000-2003 (xls)
'Response.AppendHeader("Content-Disposition", "filename=Data.xls;")
'Excel 2007 (xlsx)
Response.AppendHeader("Content-Disposition", "filename=Data.xlsx;")
Response.Charset = ""
Response.Buffer = False
Me.EnableViewState = False
Dim tw As New System.IO.StringWriter
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
' tell the grid to render itself into the html text writer
DataGrid1.RenderControl(hw)
Dim strHtml As String = tw.ToString
Dim iLoop As Int32
Dim Multiple As Int32 = Fix(strHtml.Length / 1000)
' now write the contents of the html string to the client
For iLoop = 0 To Multiple
Response.Write(Mid(strHtml, (100000 * iLoop) + 1, 100000))
Response.Flush()
Next
Response.End()
I have one workaround you might consider. The warning you get opening in
Excel 2007 is controlled by a registry entry that is read just when a file
is opened in Excel. So you could set the entry, open the file and reset the
registry back.
Set this to 0 to bypass warning. Set to 1 or delete to re-establish the
warning.
I hope the above information will be helpful. If you have any issues or concerns, please let me know. It's my pleasure to be of assistance
Best Regards,
__________________________________________________
Sincerely,
Rex Lin
Microsoft Online Community Support
If there is any question or the issue is not resolved, please feel free to mark the thread as not resolved
Marked as answer by Rex Lin - MSFT on Apr 26, 2007 08:18 AM
under Security... ExtensionHardening was not found actually.
so is there any alternative for this ...
Please reply
regards
rajeev
Hi Guys,
I'm also facing the same problem. Based on my research on this issue, we will only encounter this if the client Excel version is 2007. Excel 2007 implements strong XML formatting but previous version is not.
Excel 2007 is having xlsx file format while prior is
xls.
So far the best possible solution i've found is to set "ExtensionHardening" double word value to
0 in the registry but the biggest drawback is setting the registry of your client 1 at a time and this will take you forever to edit if you have a lot.
Will anyway I will teach you how to edit your registry for those who still want to learn how to do this. Just a word of advice: Please take extra precautions in editing the registry as it may render instability to your clients PC if you didn't do it correctly.
On the client's PC, run the registry editor through Start - Run and typing regedit then press Enter
Go to the location HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\OFFICE\12.0\EXCEL\SECURITY
On the right window, right click you mouse and choose New -> DWORD Value
Change the name to “ExtensionHardening” without the double quote
Default value of this DWORD is actually 0 which sets the ExtensionHardening of Excel Application to be disabled
Close Registry Editor
That's all. Hope this will help others. On my side, I'm still stuck because not all my client's are using Office 2007.
Cheers.
Please don't forget to click "Answer" if it helps you as it may help others also.
I found something on MSDN which refers to setting a group policy to fix this also -
http://support.microsoft.com/kb/948615. Being a programmer I do not know for sure, but would think this may be easier than going around to each user's PC.
I found something on MSDN which refers to setting a group policy to fix this also -
http://support.microsoft.com/kb/948615. Being a programmer I do not know for sure, but would think this may be easier than going around to each user's PC.
Correct me if I'm wrong but the Group Policy you mention is only applicable if your client is connected in a Domain and you set a Policy in the Domain itself so that it would be applied to the client. And if your client is not connected to the Domain let's
say on a Workgroup Only, then you don't have any choice but to edit the registry...[:P]
Happy coding cheers
Please don't forget to click "Answer" if it helps you as it may help others also.
Jackxxx
Contributor
3060 Points
2788 Posts
How can I output to Excel 2007 format
Apr 21, 2007 01:42 PM|LINK
I have been using this code for a while and it works great. Now with the new Excel 2007 format and extention (xlsx), when you open a file it has a message that the xls file is not in the expected format.
Does anyone know how to modify this code to output to the new format? I tried just changing the extention, but no change.
Response.ContentType = "application/vnd.ms-excel" 'Excel 2000-2003 (xls) 'Response.AppendHeader("Content-Disposition", "filename=Data.xls;") 'Excel 2007 (xlsx) Response.AppendHeader("Content-Disposition", "filename=Data.xlsx;") Response.Charset = "" Response.Buffer = False Me.EnableViewState = False Dim tw As New System.IO.StringWriter Dim hw As New System.Web.UI.HtmlTextWriter(tw) ' tell the grid to render itself into the html text writer DataGrid1.RenderControl(hw) Dim strHtml As String = tw.ToString Dim iLoop As Int32 Dim Multiple As Int32 = Fix(strHtml.Length / 1000) ' now write the contents of the html string to the client For iLoop = 0 To Multiple Response.Write(Mid(strHtml, (100000 * iLoop) + 1, 100000)) Response.Flush() Next Response.End()Jackxxx
Rex Lin - MS...
All-Star
17422 Points
2116 Posts
Re: How can I output to Excel 2007 format
Apr 23, 2007 03:04 AM|LINK
Hi, Jack:
I have one workaround you might consider. The warning you get opening in
Excel 2007 is controlled by a registry entry that is read just when a file
is opened in Excel. So you could set the entry, open the file and reset the
registry back.
HKCU\Software\Microsoft\Office\12.0\Excel\Security\ExtensionHardening
Set this to 0 to bypass warning. Set to 1 or delete to re-establish the
warning.
I hope the above information will be helpful. If you have any issues or concerns, please let me know. It's my pleasure to be of assistance
__________________________________________________
Sincerely,
Rex Lin
Microsoft Online Community Support
If there is any question or the issue is not resolved, please feel free to mark the thread as not resolved
rajverma84
Member
2 Points
1 Post
Re: How can I output to Excel 2007 format
Aug 17, 2007 07:10 AM|LINK
I am facing the same problem ...
HKCU\Software\Microsoft\Office\12.0\Excel\Security\ExtensionHardening
under Security... ExtensionHardening was not found actually.
so is there any alternative for this ...
Please reply
regards
rajeev
Rajeev
Jackxxx
Contributor
3060 Points
2788 Posts
Re: How can I output to Excel 2007 format
Aug 17, 2007 08:15 PM|LINK
Sorry, still have not found any good fix.
Jackxxx
chayady
Member
30 Points
70 Posts
Re: How can I output to Excel 2007 format
Mar 18, 2008 06:25 AM|LINK
Could it be Ofiice 2007 bug?
Check this thread
http://forums.asp.net/p/1070490/1560113.aspx#1560113
jobejufranz
Participant
988 Points
240 Posts
Re: How can I output to Excel 2007 format
Mar 31, 2008 10:21 AM|LINK
Hi Guys,
I'm also facing the same problem. Based on my research on this issue, we will only encounter this if the client Excel version is 2007. Excel 2007 implements strong XML formatting but previous version is not.
Excel 2007 is having xlsx file format while prior is xls.
So far the best possible solution i've found is to set "ExtensionHardening" double word value to 0 in the registry but the biggest drawback is setting the registry of your client 1 at a time and this will take you forever to edit if you have a lot.
Will anyway I will teach you how to edit your registry for those who still want to learn how to do this. Just a word of advice: Please take extra precautions in editing the registry as it may render instability to your clients PC if you didn't do it correctly.
That's all. Hope this will help others. On my side, I'm still stuck because not all my client's are using Office 2007.
Cheers.
RobertTJ
Member
2 Points
1 Post
Re: How can I output to Excel 2007 format
Apr 16, 2008 01:43 PM|LINK
I found something on MSDN which refers to setting a group policy to fix this also - http://support.microsoft.com/kb/948615. Being a programmer I do not know for sure, but would think this may be easier than going around to each user's PC.
jobejufranz
Participant
988 Points
240 Posts
Re: How can I output to Excel 2007 format
Apr 18, 2008 06:50 AM|LINK
Correct me if I'm wrong but the Group Policy you mention is only applicable if your client is connected in a Domain and you set a Policy in the Domain itself so that it would be applied to the client. And if your client is not connected to the Domain let's say on a Workgroup Only, then you don't have any choice but to edit the registry...[:P]
Happy coding cheers
chinnivasude...
Member
10 Points
5 Posts
Re: How can I output to Excel 2007 format
Oct 13, 2008 07:25 AM|LINK
Use Excel functionality (include excel.dll features) instead of using
Response.ContentType = "application/vnd.ms-excel" Response.AppendHeader("Content-Disposition", "filename=Data.xlsx;")Subbu_avvaru
Member
2 Points
4 Posts
Re: How can I output to Excel 2007 format
Nov 12, 2012 07:23 PM|LINK
what do you mean export functionality: give me example