How to suppress the file corrupt warning at Excel download?

前端 未结 8 1102
被撕碎了的回忆
被撕碎了的回忆 2020-11-27 19:21

I have a web page which links to an Excel 2007 worksheet. It is a .xls file and not .xlsx file. When I click on the link I get the usual dialog box

相关标签:
8条回答
  • 2020-11-27 19:32

    I had same kind of issue and client complaining about it. I had done much googling but no luck. Finally I have created spreadsheet using cfspreadsheet, I know it require additional work than directly creating through HTML but it remove warning.

    0 讨论(0)
  • 2020-11-27 19:37

    If you don’t want to look for a solution, but just want to solve the problem, insert this key in your registry to suppress the notification:

    [HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Excel\Security] “ExtensionHardening”=dword:00000000

    You can accomplish the above by doing the following:

    1. Open your Registry (Start -> Run -> regedit.exe)
    2. Navigate to HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\OFFICE\12.0\EXCEL\SECURITY
    3. Right click in the right window and choose New -> DWORD
    4. Type “ExtensionHardening” as the name (without the quotes)
    5. Verify that the data has the value “0″
    0 讨论(0)
  • 2020-11-27 19:37

    For the old Excel format (.xls)

    Assuming you create your spreadsheet object with this syntax:

    <cfset sheet = SpreadsheetNew() /> 
    

    You would use this to create the download:

    <cfheader name="content-disposition" value="attachment;filename=my_spreadsheet.xls">
    <cfcontent type="application/vnd.ms-excel" variable="#spreadsheetReadBinary(sheet)#" reset="true">
    

    For the newer Excel format (.xlsx)

    Create your spreadsheet object with this syntax:

    <cfset sheet = SpreadsheetNew("", "true") />
    

    And use this to create the download:

    <cfheader name="content-disposition" value="attachment;filename=my_xml_spreadsheet.xlsx">
    <cfcontent type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" variable="#spreadsheetReadBinary(sheet)#" reset="true">
    

    Thanks to Raymond Camden for the bulk of this (his example was for creating the spreadsheet in the older format -- I updated for the newer format and use slightly different MIME values).

    0 讨论(0)
  • 2020-11-27 19:39

    If you are not specifying the file extension, it is probably getting named as a .cfm file with the content type as "application/vnd-excel" which causes this warning.

    Try adding this before the file output begins:

    <cfheader name="Content-Disposition" value="attachment;filename=myexcelfile.xls">
    <cfcontent type="application/ms-excel" reset="true">
    
    0 讨论(0)
  • 2020-11-27 19:40

    The message suggests that the file contents and the file extension don't match. So either it's an XLSX file or the current file on the server is broken in some way. I suggest to try to open the file with a ZIP tool. If that works, it's really an XLSX-format file. Then you can fix the warning by renaming the file.

    If that's not the case, something happened to the file.

    But either way, suppressing the warning is not a solution to your problem. The next time a virus comes along and asks your customers to open nakedgrls.gif.exe, you better didn't mess with the security settings.

    0 讨论(0)
  • 2020-11-27 19:40

    I don't believe you can hide it from the user. Those kinds of warnings are external to your browser.

    0 讨论(0)
提交回复
热议问题