# report = {'name'=> 'Долги клиентов', 'format'=>'xlsx', 'report_params_attributes'=>[{'name'=>'customers', 'view_name'=>'Клиенты', 'param_type'=> 'customers_multiselect', 'required'=> false}]} @params['customers'].blank? ? customers = Customer.available_for_user(@user).collect(&:id).join(',') : customers = @params['customers'].join(',') @customers = ActiveRecord::Base.connection.execute( "SELECT customers.name as name, customers.address as address, customers.debt as debt FROM customers WHERE customers.id IN (#{customers}) ORDER BY customers.name" ) wb = xlsx_package.workbook wb.styles do |s| header_cell = s.add_style :bg_color => "FFFFFF", :fg_color => "000000", :border => { :style => :thin, :color => "00" }, :sz => 12, :b => true, :alignment => { :horizontal=> :center, :wrap_text => true } bold_cell = s.add_style :bg_color => "FFFFFF", :fg_color => "000000", :border => { :style => :thin, :color => "00" }, :sz => 10, :b => true, :alignment => { :horizontal=> :right, :wrap_text => true } default_cell = s.add_style :bg_color => "FFFFFF", :fg_color => "000000", :border => { :style => :thin, :color => "00" }, :sz => 10, :alignment => { :horizontal=> :right, :wrap_text => true } wb.add_worksheet(:name => 'Sheet1') do |sheet| sheet.add_row [t(:customers_debts_report)], :style => header_cell sheet.add_row [t(:customer), t(:address), t(:debt)], style: bold_cell @customers.each do |customer| sheet.add_row [ customer['name'], customer['address'], customer['debt']], style: default_cell end sheet.column_widths 30,40,15 sheet.merge_cells("A1:C1") end end