我正在使用axlsx
gem 创建一个电子表格。我想在所有电子表格列上设置固定宽度,我需要调用该函数
def column_widths(*widths)
widths.each_with_index do |value, index|
next if value == nil
Axlsx::validate_unsigned_numeric(value) unless value == nil
find_or_create_column_info(index).width = value
end
end
中定义的Axlsx::Worksheet
具有任意数量的列宽。例如`sheet.column_width(20, 20, ..., 20)。我的方法调用看起来像
sheet.column_widths [20]*headers.length
并导致错误
ActionView::Template::Error (Invalid Data [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20] for Invalid column width. must be [Fixnum, Integer, Float].
如何为未知数量的列动态创建正确的方法调用?