Railscasts Episode #362 - Exporting to Excel: How to avoid the warning message given by Excel 2010 when opening the file?

前端 未结 2 1613
滥情空心
滥情空心 2021-01-18 12:12

When using the example app from Ryan Bates\' Railscasts Episode #362 about exporting to Excel (https://github.com/railscasts/362-exporting-csv-and-excel), I\'ve noticed that

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-18 12:45

    The xls file that is generated by the Railscasts application is actually an XML file in the old Excel 2003 XML format.

    Recent versions of Excel have a feature called Extension Hardening that generate this warning when the file format doesn't match the file extension:

    The alert is a new security feature in Excel 2007 called Extension Hardening, which ensures that the file content being opened matches the extension type specified in the shell command that is attempting to open the file. Because the MIME types listed above are associated with the .XLS extension, the file must be in XLS (BIFF8) file format to open without this warning prompt.

    In order to avoid this warning you will have to generate an Excel file in a format that matches the file extension. Editing the registry as suggested as a workaround in the above link probably isn't workable in practice. Changing the extension to xml might also work.

    As alternatives writeexcel for xls, write_xlsx for xlsx and AXLSX (that you mention above) are good options.

提交回复
热议问题