How can I output to Excel 2007 format

Last post 12-22-2008 8:49 AM by TCKarthick_accet. 9 replies.

Sort Posts:

  • How can I output to Excel 2007 format

    04-21-2007, 9:42 AM
    • Contributor
      2,703 point Contributor
    • Jackxxx
    • Member since 04-13-2003, 11:43 AM
    • Northern California
    • Posts 2,033

    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()
     
    Thank you

    Jackxxx
  • Re: How can I output to Excel 2007 format

    04-22-2007, 11:04 PM
    Answer

    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

    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
  • Re: How can I output to Excel 2007 format

    08-17-2007, 3:10 AM
    • Member
      2 point Member
    • rajverma84
    • Member since 08-17-2007, 5:51 AM
    • Posts 1

    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

    Regards
    Rajeev
  • Re: How can I output to Excel 2007 format

    08-17-2007, 4:15 PM
    • Contributor
      2,703 point Contributor
    • Jackxxx
    • Member since 04-13-2003, 11:43 AM
    • Northern California
    • Posts 2,033

    Sorry, still have not found any good fix.

    Thank you

    Jackxxx
  • Re: How can I output to Excel 2007 format

    03-18-2008, 2:25 AM
    • Member
      30 point Member
    • chayady
    • Member since 08-01-2007, 5:02 AM
    • Posts 70

    Could it be Ofiice 2007 bug?

    Check this thread

    http://forums.asp.net/p/1070490/1560113.aspx#1560113

    * Please remember to Mark this post as Answered if it serves your purpose so that issue can be closed and others can refer.
  • Re: How can I output to Excel 2007 format

    03-31-2008, 6:21 AM
    • Participant
      978 point Participant
    • jobejufranz
    • Member since 07-09-2007, 9:56 AM
    • Virtual Reality
    • Posts 240

    rajverma84:

    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

     

    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.

    1. On the client's PC, run the registry editor through Start - Run and typing regedit then press Enter
    2. Go to the location HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\OFFICE\12.0\EXCEL\SECURITY
    3. On the right window, right click you mouse and choose New -> DWORD Value
    4. Change the name to “ExtensionHardening” without the double quote
    5. Default value of this DWORD is actually 0 which sets the ExtensionHardening of Excel Application to be disabled
    6. 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.
  • Re: How can I output to Excel 2007 format

    04-16-2008, 9:43 AM
    • Member
      2 point Member
    • RobertTJ
    • Member since 04-16-2008, 1:40 PM
    • Posts 1

    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.

  • Re: How can I output to Excel 2007 format

    04-18-2008, 2:50 AM
    • Participant
      978 point Participant
    • jobejufranz
    • Member since 07-09-2007, 9:56 AM
    • Virtual Reality
    • Posts 240

    RobertTJ:

    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...Stick out tongue

    Happy coding cheers

    Please don't forget to click "Answer" if it helps you as it may help others also.
  • Re: How can I output to Excel 2007 format

    10-13-2008, 3:25 AM
    • Member
      10 point Member
    • chinnivasudeva
    • Member since 09-19-2008, 9:34 AM
    • Bangalore
    • Posts 5

    Use Excel functionality (include excel.dll features) instead of using

    Response.ContentType = "application/vnd.ms-excel"
    Response.AppendHeader("Content-Disposition", "filename=Data.xlsx;")
    Excel functionality will solve your problem. 
     
  • Re: How can I output to Excel 2007 format

    12-22-2008, 8:49 AM

    Hi, I am getting an alert message even after adding the ExtensionHardening in the Registry. Message is "Excel found unreadable content in data.xlsx. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes. Can you plz help?

Page 1 of 1 (10 items)