wb = xlsx_package.workbook
wb.add_worksheet(name: "Reporte") do |sheet|
  bg_green = sheet.styles.add_style(:bg_color => "cdffba")
  bg_red = sheet.styles.add_style(:bg_color => "ffcdd2")
  sheet.add_row ["Grupo", @vehicle.group.name]
  sheet.add_row ["Vehiculo", @vehicle.name]
  sheet.add_row ["", ""]
  sheet.add_row ["", ""]
  sheet.add_row ["Fecha", 'Temperatura', 'Ubicación']
  i = 0
  @positions.each do |position|
    attributes = JSON.parse(position.attributes["attributes"])
    if attributes["temp1"].present?
      sheet.add_row [position.fixtime, attributes["temp1"].present? ? attributes["temp1"] : 'n/a', position.gm_link]
      color_class = attributes['temp1'] || '0'
      if color_class <= 0
        sheet.rows[i + 5].cells[1].style = bg_green
      else
        sheet.rows[i + 5].cells[1].style = bg_red
      end
      i += 1
    end
  end
end