Last active
June 3, 2017 10:18
-
-
Save mh-github/d5b12334886b664833d7810d0d6411a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # controller code | |
| def allContacts | |
| @locations_hash = {} | |
| @contacts_name_hash = {} | |
| @contacts_email_hash = {} | |
| Location.all.each do |location| | |
| @locations_hash[location.id] = location.name | |
| end | |
| Contact.all.each do |contact| | |
| @contacts_name_hash[contact.id] = contact.name | |
| @contacts_email_hash[contact.id] = contact.email_1 | |
| end | |
| @contacts = [] | |
| Customer.all.each do |customer| | |
| @contacts << [customer.name, @locations_hash[customer.location_id], @contacts_name_hash[customer.contact_id], @contacts_email_hash[customer.contact_id]] | |
| end | |
| render xlsx: 'allContacts', locals: {xlsx_use_shared_strings: true}, filename: "allContacts.xlsx", disposition: 'inline' | |
| end | |
| # view code. filename: allContacts.axlsx | |
| wb = xlsx_package.workbook | |
| wrap = wb.styles.add_style alignment: {wrap_text: true} | |
| wb.styles do |s| | |
| color_cell = s.add_style :bg_color => "0000FF", :fg_color => "FF", :sz => 12, :alignment => { :horizontal=> :center } | |
| date_cell = s.add_style(format_code: "dd-mm-yyyy") | |
| s.add_style alignment: {wrap_text: true} | |
| wb.add_worksheet(name: "All Contacts") do |sheet| | |
| # sheet.add_row ["#{@month_name}"] | |
| sheet.add_row ['Customer', 'Location', 'Contact', 'Email'], style: [color_cell, color_cell, color_cell, color_cell] | |
| @contacts.each do |contact| | |
| sheet.add_row [contact[0], contact[1], contact[2], contact[3]] | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment