diff options
| author | Randy Morgan <[email protected]> | 2012-04-25 20:57:49 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-04-25 20:57:49 +0900 |
| commit | 91ea5ff009672adbad8587a1a4437d0b02519b0e (patch) | |
| tree | 383b2747b674cf64296fc05c95a44c3ee8f3dbfc /examples/example_conditional_formatting.rb | |
| parent | 1381dca8d62748ad103004a2cf35cbc51e7c336c (diff) | |
| download | caxlsx-91ea5ff009672adbad8587a1a4437d0b02519b0e.tar.gz caxlsx-91ea5ff009672adbad8587a1a4437d0b02519b0e.zip | |
documentation updates and example dir restructuring.
Diffstat (limited to 'examples/example_conditional_formatting.rb')
| -rw-r--r-- | examples/example_conditional_formatting.rb | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/examples/example_conditional_formatting.rb b/examples/example_conditional_formatting.rb deleted file mode 100644 index ab49d238..00000000 --- a/examples/example_conditional_formatting.rb +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env ruby -w -s -# -*- coding: utf-8 -*- -$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" -require 'axlsx' - -p = Axlsx::Package.new -book = p.workbook - -# define your regular styles -percent = book.styles.add_style(:format_code => "0.00%", :border => Axlsx::STYLE_THIN_BORDER) -money = book.styles.add_style(:format_code => '0,000', :border => Axlsx::STYLE_THIN_BORDER) - -# define the style for conditional formatting -profitable = book.styles.add_style( :fg_color=>"FF428751", - :type => :dxf) - -book.add_worksheet(:name => "Cell Is") do |ws| - - # Generate 20 rows of data - ws.add_row ["Previous Year Quarterly Profits (JPY)"] - ws.add_row ["Quarter", "Profit", "% of Total"] - offset = 3 - rows = 20 - offset.upto(rows + offset) do |i| - ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent] - end - -# Apply conditional formatting to range B3:B100 in the worksheet - ws.add_conditional_formatting("B3:B100", { :type => :cellIs, :operator => :greaterThan, :formula => "100000", :dxfId => profitable, :priority => 1 }) -end - -book.add_worksheet(:name => "Color Scale") do |ws| - ws.add_row ["Previous Year Quarterly Profits (JPY)"] - ws.add_row ["Quarter", "Profit", "% of Total"] - offset = 3 - rows = 20 - offset.upto(rows + offset) do |i| - ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent] - end -# Apply conditional formatting to range B3:B100 in the worksheet - color_scale = Axlsx::ColorScale.new - ws.add_conditional_formatting("B3:B100", { :type => :colorScale, :operator => :greaterThan, :formula => "100000", :dxfId => profitable, :priority => 1, :color_scale => color_scale }) -end - - -book.add_worksheet(:name => "Data Bar") do |ws| - ws.add_row ["Previous Year Quarterly Profits (JPY)"] - ws.add_row ["Quarter", "Profit", "% of Total"] - offset = 3 - rows = 20 - offset.upto(rows + offset) do |i| - ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent] - end -# Apply conditional formatting to range B3:B100 in the worksheet - data_bar = Axlsx::DataBar.new - ws.add_conditional_formatting("B3:B100", { :type => :dataBar, :dxfId => profitable, :priority => 1, :data_bar => data_bar }) -end - -book.add_worksheet(:name => "Icon Set") do |ws| - ws.add_row ["Previous Year Quarterly Profits (JPY)"] - ws.add_row ["Quarter", "Profit", "% of Total"] - offset = 3 - rows = 20 - offset.upto(rows + offset) do |i| - ws.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})"], :style=>[nil, money, percent] - end -# Apply conditional formatting to range B3:B100 in the worksheet - icon_set = Axlsx::IconSet.new - ws.add_conditional_formatting("B3:B100", { :type => :iconSet, :dxfId => profitable, :priority => 1, :icon_set => icon_set }) -end - -p.serialize('example_conditional_formatting.xlsx') |
