热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

使用axlsx创建3种颜色条件格式-Create3colorconditionalformattingwithaxlsx

Withaxlsx,thefollowing使用axlsx,以下内容color_scaleAxlsx::ColorScale.newdo|c_s|c_s.colors[1]

With axlsx, the following

使用axlsx,以下内容

color_scale = Axlsx::ColorScale.new do |c_s|
  c_s.colors[1].rgb = "FFFFFF00"
end
color_scale.add :type => :percentile, :val => 50, :color => "FF00FF00"
worksheet.add_conditional_formatting("B3:B100", { :type => :colorScale, :operator => :greaterThan, :formula => "100000", :priority => 1, :color_scale => color_scale })

creates a basic 3 color conditional formatting, but the colors are pretty garish, making it hard to distinguish between slightly smaller and slightly larger values.

创建一个基本的3色条件格式,但颜色非常花哨,很难区分略小和稍大的值。

Is it necessary to reverse-engineer the colors Excel uses in order to create something that looks like the default 3 color conditional formatting that Excel provides?

是否有必要对Excel使用的颜色进行反向工程,以创建看起来像Excel提供的默认3色条件格式的内容?

1 个解决方案

#1


3  

For color scales, Excel will by default prefer Themes, while Axlsx is currently expecting you to specify exactly what you want. This is partly for interoperability but mostly because I have not ran into a use case that requires similarity to Excel's defaults.

对于色标,Excel默认情况下更喜欢主题,而Axlsx目前希望您准确指定所需内容。这部分是因为互操作性,但主要是因为我没有遇到需要与Excel的默认值相似的用例。

That said, Axlsx should do what it can to give you some sensible defaults and I am sure you can understand how your request is an excellent opportunity to improve this area.

也就是说,Axlsx应尽其所能为您提供合理的默认设置,我相信您可以理解您的请求是如何改善这一领域的绝佳机会。

Would you be so kind as to send me a sample xlsx of what you are trying to achieve? I am sure that I can add a bit of sugar in to make you a bit happier with the results you are seeing now and hopefully benefit the other users of the gem.

你愿意向我发送你想要实现的xlsx样本吗?我确信我可以添加一些糖,让你对现在看到的结果更开心,并希望有益于宝石的其他用户。

UPDATE 2012.11.16

Axlsx has been updated to provide two class methods on ColorScale to create new ColorScale ojects with sensible defaults for two-tone and three-tone color scaling. This is currently in master and will be released in a few weeks with 1.3.4

Axlsx已经更新,在ColorScale上提供了两种类方法,可以创建具有合理默认值的双色调和三色调颜色缩放的新ColorScale对象。这是目前掌握的,将在几周内以1.3.4发布

Examples:

# to make a three tone color scale
color_scale = Axlsx::ColorScale.three_tone

# to make a two tone color scale
color_scale = Axlsx::ColorScale.two_tone

# To make a customized color scale you, pass hashes consisting of 
# type, val and color key-value pairs as arguments to the initializer.
# This example that creates the same three tone color scale as 
# Axlsx::ColorScale.three_tone
color_scale = Axlsx:ColorScale.new({:type => :min, :val => 0, :color => 'FFF8696B'},
                 {:type => :percent, :val => '50', :color => 'FFFFEB84'},
                 {:type => :max, :val => 0, :color => 'FF63BE7B'})

推荐阅读
author-avatar
TheKing小狼
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有