Module: Spreadsheet::Rails::SpreadsheetHelper

Defined in:
lib/excel_rails.rb

Instance Method Summary collapse

Instance Method Details

#disposition(download, filename) ⇒ Object


18
19
20
21
22
23
# File 'lib/excel_rails.rb', line 18

def disposition(download, filename)
  download = true if (filename && download == nil)
  disposition = download ? "attachment;" : "inline;"
  disposition += " filename=\"#{filename}\"" if filename
  headers["Content-Disposition"] = disposition
end

#excel_document(opts = {}) {|workbook| ... } ⇒ Object

Yields:

  • (workbook)

7
8
9
10
11
12
13
14
15
16
# File 'lib/excel_rails.rb', line 7

def excel_document(opts={})
  download = opts.delete(:force_download)
  filename = opts.delete(:filename)
  template_path = opts.delete(:template_path)
  workbook_class = opts.delete(:renderer) || Spreadsheet::Workbook
  workbook = template_path ? Spreadsheet.open(template_path) : workbook_class.new
  yield(workbook)
  disposition(download, filename) if (download || filename)
  workbook
end