2

我想根据作为单词的单元格内容设置 axlsx 创建工作表的背景颜色(即“通过”或“失败”)

如果单元格内容是数字,我可以格式化工作表。我尝试更改 type => :containsText 并添加 :text => "Fail" 但没有成功。我可以轻松地将单元格内容更改为“失败”,但是我无法让条件样式正常工作。

如果单元格值是数字(在本例中为 2),则此代码效果很好:

 red =  styles.add_style(:bg_color=> 'FFFF0000', :type => :dxf)



# Apply conditional formatting to range I:L in the worksheet
sheet.add_conditional_formatting('I:L', { :type => :cellIs,
                                          :operator => :equal,
                                          :formula => "2",
                                          :dxfId => red,
                                          :priority => 1 })

但是如果我改变 :formula => "Fail" 那么它就不起作用了。我试过改变 :type => containsText 和一堆组合。

4

1 回答 1

4

花了更多的时间摆弄,但这是答案:)

red =  styles.add_style(:bg_color=> 'FFFF0000', :type => :dxf)
sheet.add_conditional_formatting('I:L', { :type => :containsText, 
                                      :text => "Fail",
                                      :operator => :equal,
                                      :dxfId => red,
                                      :priority => 1 })
于 2015-05-02T16:44:45.753 回答