Skip to content

Instantly share code, notes, and snippets.

@stereosupersonic
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stereosupersonic/990b4f397ad4abc75d1a to your computer and use it in GitHub Desktop.
Save stereosupersonic/990b4f397ad4abc75d1a to your computer and use it in GitHub Desktop.
data = Service.available_for(shop).map do |service|
[service.name_de, service.id, service.category, service.service_type, (service.global ? 'Ja': 'Nein')]
end
require 'spreadsheet'
def to_excel(data,filename = 'out.xls')
Spreadsheet.client_encoding = 'UTF-8'
book = Spreadsheet::Workbook.new
sheet = book.create_worksheet :name => filename
data.each_with_index do |row, i|
sheet_row = sheet.row(i)
row.each_with_index do |val,i|
sheet_row[i] = val.to_s.force_encode('UTF-8') rescue val
end
end
book.write filename
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment