【问题标题】:using axlsx gem how to generate excel in landscape orientation使用axlsx gem如何在横向生成excel
【发布时间】:2018-06-24 12:46:17
【问题描述】:

我在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]

结束 结束

【问题讨论】:

  • 我对问题进行了格式化,但是,没有真正的问题,请改进问题以更准确地显示您的问题。
  • searching Github 没有找到好的结果吗?
  • @praveen 的正确答案如下。我可以告诉你正在使用 axlsx_rails,这就是你有 axlsx_package 的原因。当您使用wb.add_worksheet 添加工作表时,您仍然可以使用页面设置。请参阅此示例:Docs
  • 顺便说一句,横向不会生成excel。电子表格没有方向,但您可以设置默认打印方向(例如页面比例和边距),如下所示。

标签: ruby-on-rails ruby axlsx


【解决方案1】:

你检查过这个document

wb = Axlsx::Package.new.workbook

在创建工作表时使用选项。

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

这个doc也帮你

【讨论】:

    猜你喜欢
    • 2016-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-07
    • 1970-01-01
    相关资源
    最近更新 更多