有种特殊的情况,客户需要的excell表头搞得很炫,要人工去写代码实现比较费事。
可以先存一个模板,然后再在这个模板的基础上写数据。
可以先存一个模板,然后再在这个模板的基础上写数据。
def wait_shipments(warehouse_id = 1)
search_date = Time.now
file = Spreadsheet.open "#{Rails.root}/public/xls/wait_shipments.xls"
list = file.worksheet 0
Shipment.where(status:0,warehouse_id:warehouse_id).map{ |shipment| shipment.order_details }.flatten.each_with_index do |order_detail,index|
list[index+3,0] = order_detail.customer_order&.customer_order_no
list[index+3,1] = "上海网"
list[index+3,2] = "张先生"
list[index+3,3] = "xxxx"
list[index+3,4] = "重庆市江北区盘溪2支路"
list[index+3,5] = order_detail.customer_order&.member&.company_name
list[index+3,6] = order_detail.address&.ship_contact
list[index+3,8] = order_detail.address&.ship_contacttel
list[index+3,9] = order_detail.address&.ship_address
list[index+3,10] = "寄付现结"
list[index+3,12] = "原料"
list[index+3,13] = 1
list[index+3,14] = 1
list[index+3,17] = "顺丰隔日"
end
xls_report = StringIO.new
file.write xls_report
send_data xls_report.string, :type => 'text/xls', :filename => "wait_shipments_#{search_date.to_s(:db)}.xls"
end