ruby on rails - Export To Excel - Change Default "Save as type" to Microsoft Office Excel Workbook(*xls) -


I am exporting one in Excel with my Ruby on the Ralis application. I have not used any gem or plugin (something different since our requirement, we could not use them). We used Inbuilt "format.xls" support which comes with Ruby on Rail.

The problem is that, when we get our Excel, appears on I want to change the Office Excel workbook (* xls) . How to do this

Below is my controller action code and related view with which we get Excel.

Gate_excel methods def get_excel format.xls header ['content-type'] = "app / vnd.ms- Excel "header [" content-temper "] = 'inline; File name = "myexcel.xls" 'header [' cache-control '] =' 'end end

see (get_excel.xls.erb)

  & lt; Html xmlns: o = "urn: schemas-microsoft-com: office: office xmlns: x =" vase: schemas-microsoft-com: office: excel "xmlns =" ​​http: // www.w3.org/TR / REC-html40 "xmlns: ss =" vase: schema-microsoft com: office: spreadsheet "/>  gt; meta http-equivalent = content type content =" text / html; Charset = UTF-8 "/>  gt; meta name = generator content =" Microsoft Excel 11 "/> style type = "Text / css" & gt; @page {mso header data: '& amp; r confidential'; margin: 0.75in 0.20in 0.5in 0.20in; MSO header margin: 0.25in; MSO-footer margin: 0.25in; MSO-Page-Orientation: Scenario;} Table {Page-break-in: Tire;} TD {white-space: abrap;}   15  X: ValidPrinterInfo />  74>  & Lt; X: FrozenNoSplit / & gt; & Lt; X: SplitHorizontal & gt; 5 & ​​lt; / X: SplitHorizontal & gt; & Lt; X: TopRowBottomPane & gt; 5 & ​​lt; / X: TopRowBottomPane & gt; & Lt; X: ActivePane & gt; 2 & lt; / X: ActivePane & gt; & Lt; X: Panel & gt; & Lt; X: Panel & gt; & Lt; X: number & gt; 3 & lt; / X: number & gt; & Lt; / X: Panel & gt; & Lt; X: Panel & gt; & Lt; X: number & gt; 2 & lt; / X: number & gt; & Lt; / X: Panel & gt; & Lt; X: ProtectContents & gt; False & lt; / X: ProtectContents & gt; & Lt; X: ProtectObjects & gt; False & lt; / X: ProtectObjects & gt; & Lt; X: ProtectScarenarios & gt; False & lt; / X: ProtectScernarios & gt; & Lt; / X: WorksheetOptions & gt; & Lt; / X: ExcelWorksheet & gt; & Lt; / X: ExcelWorksheets & gt; & Lt; X: WindowHeight & gt; 8580 & lt; / X: WindowHeight & gt; & Lt; X: WindowWidth & gt; 12120 & lt; / X: WindowWidth & gt; & Lt; X: WindowTopX & gt; 120 & lt; / X: WindowTopX & gt; & Lt; X: WindowTopY & gt; 45 & lt; / X: WindowTopY & gt; & Lt; X: ProtectStructure & gt; False & lt; / X: ProtectStructure & gt; & Lt; X: ProtectWindows & gt; False & lt; / X: ProtectWindows & gt; & Lt; / X: ExcelWorkbook & gt; & Lt; X: ExcelName & gt; & Lt; X: Name & gt; Print_Titles & lt; / X: Name & gt; & Lt; X: SheetIndex & gt; 1 & lt; / X: SheetIndex & gt; & Lt; X: formula & gt; = 'Gantt description'! $ 3: $ 5 & lt; / X: formula & gt; & Lt; / X: ExcelName & gt; & Lt; / XML & gt; & Lt; [Endif] - & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Table & gt; & Lt; Tr & gt; Some code & lt; / Tr & gt; & Lt; Tr & gt; Some code & lt; / Tr & gt; & Lt; Tr & gt; Some code & lt; / Tr & gt; & Lt; Tr & gt; Some code & lt; / Tr & gt; & Lt; Tr & gt; Some code & lt; / Tr & gt; & Lt; / Table & gt; & Lt; / Body & gt;    

config / initializers / mime_types.rb

  MIME :: Type.Register "app / vnd.ms-excel" ,: xls   

Then you should not need to set the header directly in the method.

I'm not sure that this will stop you from being prompted, but how do I serve the HTML table like XLS and there is no problem opening them anytime.

I do not even set a file name method name name (get_excel.xls in your case). I do not even set all the XML and xmlns stuff either, it just works.

Comments