Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails AXLSX Gem:列的单元格样式组_Ruby On Rails_Rubygems_Axlsx - Fatal编程技术网

Ruby on rails AXLSX 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

我指的是使用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: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的行


如何向列中的一组单元格添加左边框和右边框?

在所有空单元格中填充一个空白的
空格
,帮助我解决了这个问题