Export To Excel - Change Default “Save as type” to Microsoft Office Excel Workbook(*xls)

Hi all,

I am Doing an Export to Excel with my Ruby on Ralis application.I have
not used any gem or Plugin (since our requirement was something
different, we couldn’t use them). We used the inbuilt “format.xls”
support that comes with Ruby on Rails.

The problem is that, when we get our Excel, Save as Type appears on the
webpage. I want to change this to Microsoft Office Excel Workbook
(*xls). How to do it?

Below is my controller action code and the respective view with which we
get the excel.

Get_excel methods in controller

def get_excel
format.xls do
headers[‘Content-Type’] = “application/vnd.ms-excel”
headers[“Content-disposition”] = ‘inline;
filename=“myexcel.xls”’
headers[‘Cache-Control’] = ‘’
end
end

VIEW (get_excel.xls.erb)

@page { mso-header-data : '&R CONFIDENTIAL'; margin: 0.75in 0.20in 0.5in 0.20in; mso-header-margin: 0.25in; mso-footer-margin:0.25in; mso-page-orientation: landscape; } table{ page-break-inside: avoid; } td{ white-space:nowrap; } some codesome codesome codesome codesome code

On Mar 17, 2011, at 10:05 AM, Ankit G. wrote:

(*xls). How to do it?
headers[“Content-disposition”] = 'inline;
xmlns:ss = “urn:schemas-microsoft-com:office:spreadsheet” />
mso-page-orientation: landscape;
<x:ExcelWorkbook>
<x:VerticalResolution>600</x:VerticalResolution>
<x:Pane>
<x:WindowTopX>120</x:WindowTopX>

Attachments:
http://www.ruby-forum.com/attachment/6033/_2177C6EE6FB99384.jpg

Try adding a mime-type for Excel to your Web server.

Walter