ruby-on-rails - 将 axlsx gem 与 conditional_formatting 一起使用
问题描述
我使用 axlsx gem,但我需要比较元素 A1 是否等于 B1,以防不同,为单元格添加背景颜色。我使用 conditional_formatting 如下:
sheet.add_conditional_formatting('A1', { :type => :notContainsText,
:text => B1,
:operator => :equal,
:dxfId => red,
:priority => 1 })
但是在引用列时出现以下错误:
uninitialized constant #<Class:0x00007fafd813f850>::B1
可能缺少什么?还有另一种方法吗?这是我所有的代码
wb = xlsx_package.workbook
wb.styles do |style|
highlight_cell = style.add_style(bg_color: "EFC376")
red = style.add_style(:bg_color=> 'FFFF0000', :type => :dxf)
wb.add_worksheet(name: "inventario") do |sheet|
sheet.add_row [
t('inventario.Ubicacion'), "Formula"
], style: highlight_cell
current_row = sheet.rows.count + 1
sheet.add_row [
current_row,
"=IFERROR(VLOOKUP(A#{current_row},ubicaciones!A2:A#{@t_grouping_levels.length+1},1,0),#{'"n/a"'})"
]
sheet.add_conditional_formatting('A1', { :type => :notContainsText,
:text => B1,
:operator => :equal,
:dxfId => red,
:priority => 1 })
end
wb.add_worksheet(name: "ubicaciones") do |sheet|
sheet.add_row [
t('inventario.Ubicacion')
], style: highlight_cell
@t_grouping_levels.each do |u|
sheet.add_row [
u.description
]
end
end
end