[英]axlsx_rails gem: Columns width issue
我正在使用axlsx_rails gem在.xlsx文件中編寫。 我在電子表格中基於表單字段有多個列。 可能會有所不同。
我想根據可用數據為所有列設置列寬。
我用過:
col_widths= [10,20,30,40,50]
p = Axlsx::Package.new
p.use_autowidth = true
wb = p.workbook
wb.add_worksheet(:name => 'try') do |sheet|
sheet.add_row ["hi","hello","how","are","you"]
sheet.column_widths col_widths ##this column widths method doesn't take an array.
是否可以將數組傳遞給column_widths方法或任何其他將col_widths數組值轉換為的方法,以便我們可以將其傳遞給column_widths方法?
謝謝。
該方法采用列寬列表 ,而不是array 。
您可以使用splat運算符將數組轉換為列表。 只需添加一個*
字符:
col_widths= [10,20,30,40,50]
p = Axlsx::Package.new
p.use_autowidth = true
wb = p.workbook
wb.add_worksheet(:name => 'try') do |sheet|
sheet.add_row ["hi","hello","how","are","you"]
sheet.column_widths *col_widths ## Here I have used the splat operator
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.