Ruby on rails 如何从sidekiq在xls文件中添加头名称?

Ruby on rails 如何从sidekiq在xls文件中添加头名称?,ruby-on-rails,ruby,ruby-on-rails-3,ruby-on-rails-3.2,Ruby On Rails,Ruby,Ruby On Rails 3,Ruby On Rails 3.2,上面的代码在创建tmp文件夹中的xls文件时运行良好,但我希望xls文件中包含头名称,如何在代码中传递头名称?这段代码是用sidekiq编写的,用于后台处理。有谁能推荐我吗 sampl.xls文件: 使用CSV保存资源。Excel将毫无问题地打开它 [{"id"=>1, "office"=>" ", "ordernumber"=>"100", "code"=>"NA", "type"=>"I", "prev_order_number"=>nil, "insur

上面的代码在创建tmp文件夹中的xls文件时运行良好,但我希望xls文件中包含头名称,如何在代码中传递头名称?这段代码是用sidekiq编写的,用于后台处理。有谁能推荐我吗

sampl.xls文件:
使用CSV保存资源。Excel将毫无问题地打开它

[{"id"=>1, "office"=>" ", "ordernumber"=>"100", "code"=>"NA", "type"=>"I", "prev_order_number"=>nil, "insured_name"=>"sree"}]

请从您的
sample.xls
文件中添加样本行。这不是Excel,而是JSON。你想要JSON还是XLS?我想要XLS但是数据获取JSON[{col1:“id”,col2:“office”,col3:“ordernumber”,col4:“code”,col5:“type”,col6:“prev\u order\u number”,col7:“insured\u name”}{“id”=>1,“office”=>,“ordernumber”=>“100”,“code”=>“NA”,“type”=>“i”,“prev\u order\u number”=>nil,“insured\u name”=>“sree”}就是这样,但我想在下面的身份证号码列表中,在总公司和下面的办公室名称列表中,像我want@SrikanthRao考虑选择答案来结束你的问题。
[{"id"=>1, "office"=>" ", "ordernumber"=>"100", "code"=>"NA", "type"=>"I", "prev_order_number"=>nil, "insured_name"=>"sree"}]
csv_file = CSV.generate do |csv|
    csv << @policies.first.keys
    @policies.each do |policy|
        csv << policy.values
    end
end

File.write("#{Rails.root}/tmp/report/sample.xls", csv_file)
headers = {col1: "id", col2: "office", col3: "ordernumber", col4: "code", col5: "type", col6: "prev_order_number", col7: "insured_name"}

File.open("#{Rails.root}/tmp/report/sample.xls", 'w') do |f|
  f.write @policies.unshift(headers)
end