使用 axlsx gem 如何在横向生成 excel

using axlsx gem how to generate excel in landscape orientation

我在 rails 中使用 axlsx gem 并且需要在横向方向生成 excel

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]

结束 结束

你检查过这个吗document

wb = Axlsx::Package.new.workbook

创建工作表时使用选项。

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

这个doc也对你有帮助