ruby-on-railsrubyaxlsx

using axlsx gem how to generate excel in landscape orientation


I am using axlsx gem in rails and need to generate excel in landscape orientation

wb = xlsx_package.workbook
wb.add_worksheet(name: "Semestre") do |sheet|
sheet.add_row ["Período", "Turma", "Sala", "Disciplina", "Tipo", "Híbrida", "Dia da Semana", "Hora Inicial", "Hora Final", "CH", "Curso", "Professor", "Matrícula"]

  @oferta.each do |oferta|

if oferta.sala_id != nil 
  sala=oferta.sala.nome 
else 
  sala="-" 
end
sheet.add_row [oferta.periodo, oferta.codturma, sala, oferta.disciplinaturma.disciplina.nome, oferta.tipoaula, oferta.disciplinaturma.disciplina.hibrida, oferta.diasemana, oferta.horainicial.try(:strftime, ("%H:%M")), oferta.horafinal.try(:strftime, ("%H:%M")), oferta.cargahoraria.to_s+" h", oferta.disciplinaturma.turma.curso.nome, oferta.professor.nome, oferta.professor.matricula]

end end


Solution

  • Have you checked this document

    wb = Axlsx::Package.new.workbook

    using options when creating the worksheet.

    ws = wb.add_worksheet :page_setup => {:fit_to_width => 2, :orientation => :landscape}

    This doc also help you