Ruby on rails AXLSX Gem:列的单元格样式组
我指的是使用gem包围一个框(一串列)。我能想出如何在一组单元格中添加上下边框。例如:Ruby on rails AXLSX Gem:列的单元格样式组,ruby-on-rails,rubygems,axlsx,Ruby On Rails,Rubygems,Axlsx,我指的是使用gem包围一个框(一串列)。我能想出如何在一组单元格中添加上下边框。例如: sheet["B3:D3"].each do |cell| cell.style = workbook.styles.add_style({:border => { :style => :thick, :color => '000000', :name => :top, :edges => [:top] }}) end sheet["B24:D
sheet["B3:D3"].each do |cell|
cell.style = workbook.styles.add_style({:border => { :style => :thick, :color => '000000', :name => :top, :edges => [:top] }})
end
sheet["B24:D24"].each do |cell|
cell.style = workbook.styles.add_style({:border => { :style => :thick, :color => '000000', :name => :bottom, :edges => [:bottom] }})
end
sheet["B3:B24"].each do |cell|
cell.style = workbook.styles.add_style({:border => { :style => :thick, :color => '000000', :name => :left, :edges => [:left] }})
end
sheet["D3:D24"].each do |cell|
cell.style = workbook.styles.add_style({:border => { :style => :thick, :color => '000000', :name => :right, :edges => [:right] }})
end
现在,当我试图在空的单元格上添加左右列时,问题就出现了。例如:
sheet["B3:D3"].each do |cell|
cell.style = workbook.styles.add_style({:border => { :style => :thick, :color => '000000', :name => :top, :edges => [:top] }})
end
sheet["B24:D24"].each do |cell|
cell.style = workbook.styles.add_style({:border => { :style => :thick, :color => '000000', :name => :bottom, :edges => [:bottom] }})
end
sheet["B3:B24"].each do |cell|
cell.style = workbook.styles.add_style({:border => { :style => :thick, :color => '000000', :name => :left, :edges => [:left] }})
end
sheet["D3:D24"].each do |cell|
cell.style = workbook.styles.add_style({:border => { :style => :thick, :color => '000000', :name => :right, :edges => [:right] }})
end
我得到一个错误:
NoMethodError异常:nil:NilClass的未定义方法“each”
对于工作表[“B3:B24”]
原因是,给定范围内的空单元格。例如:
像B5
和B6
这样的单元格是空的,当我做sheet[“B3:B24”]
时,我得到了上面的错误
但是,如果我这样做,sheet[“B7:B9”]
或sheet[“B21:B24”]
,我不会得到错误,因为它们不是空的
注意:-我的方框的列从B3到B24开始。以及从B3到D3的行
如何向列中的一组单元格添加左边框和右边框?在所有空单元格中填充一个空白的
空格
,帮助我解决了这个问题