既存の色を別の hex/rgb コードにマッピングすることは、新しい色を追加するよりもはるかに簡単であるように思われるため、私の解決策は組み込み:xls_color_41が変更されたことを意味します。
2 番目のアプローチ
実際、gem のネイティブ メソッドを使用して、モンキー パッチを適用せずに同じ結果を達成しましたSpreadsheet::Workbook#set_custom_color。
document = Spreadsheet::Workbook.new
document.set_custom_color(41, 0x00, 0xad, 0xb1)
最初のアプローチ:
メソッドによって返されたデフォルトの Excel '97Spreadsheet::Excel::Writer::Workbookパレットの代わりに、返されたパレットを からにdefault_palette変更するメソッドを定義しました。結果は次のとおりです。:xls_color_41[0x33, 0xcc, 0xcc][0x00, 0xad, 0xb1]
module Spreadsheet
module Excel
module Writer
class Workbook < Spreadsheet::Writer
alias_method :excel_palette, :default_palette
def palette_modifier
{
41 => [0x00, 0xad, 0xb1]
}
end
def default_palette
excel_palette.map.with_index{|rgb, code| [code, rgb]}.to_h.update( palette_modifier ).values
end
end
end
end
end