简体   繁体   English

如何使用Axlsx gem在Rails中的Excel中添加列?

[英]How to add a column to an excel in rails using Axlsx gem?

I have few column names defined in my choices and I am adding it to the sheet as a first row but, one of the column should not be present all the time, it should vary conditionally, so I want to add a specific column based on some condition. 我在选择中定义的列名很少,我将其作为第一行添加到工作表中,但是,该列中的任何一个都不应该一直存在,它应该有条件地变化,因此我想根据一些条件。

Here is my code sheet.add_row choices, style: style_shout 这是我的代码表。add_row选项的样式:style_shout

NOW, How should I add a column to the sheet? 现在,我应该如何在工作表中添加一

try something like this: 尝试这样的事情:

adding first row with column names, then second row with column values 在第一行中添加列名称,然后在第二行中添加列值

sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4', 'col5']
sheet.add_row [1, 2, 0.3, 4, 5.0]

and depending on the conditions you want you can modify as required, for example: 并根据您想要的条件,可以根据需要进行修改,例如:

  #Hide the 5th column
  sheet.column_info[4].hidden = true

you could encapsulate this within a condition to hide or display a column 您可以将其封装在隐藏或显示列的条件下

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM