summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-04-21 13:58:27 +0900
committerRandy Morgan <[email protected]>2012-04-21 13:58:27 +0900
commit050f4cfac1b3a52da16b98f3a494083f0de5348f (patch)
tree889e7217fe7a731be6f3588e4e179d3d73d349cd /examples
parentc84e62cb7a91fefae0457baabbd9b2f3bef3259e (diff)
downloadcaxlsx-050f4cfac1b3a52da16b98f3a494083f0de5348f.tar.gz
caxlsx-050f4cfac1b3a52da16b98f3a494083f0de5348f.zip
adding in icon set and MOAR examples for conditional formatting.
Diffstat (limited to 'examples')
-rw-r--r--examples/example_conditional_formatting.rb63
1 files changed, 52 insertions, 11 deletions
diff --git a/examples/example_conditional_formatting.rb b/examples/example_conditional_formatting.rb
index cfff3c86..429b6fac 100644
--- a/examples/example_conditional_formatting.rb
+++ b/examples/example_conditional_formatting.rb
@@ -5,7 +5,6 @@ require 'axlsx'
p = Axlsx::Package.new
book = p.workbook
-ws = book.add_worksheet
# define your regular styles
percent = book.styles.add_style(:format_code => "0.00%", :border => Axlsx::STYLE_THIN_BORDER)
@@ -15,17 +14,59 @@ money = book.styles.add_style(:format_code => '0,000', :border => Axlsx::STYLE_T
profitable = book.styles.add_style( :fg_color=>"FF428751",
:type => :dxf)
-# 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]
+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 B4:B100 in the worksheet
+ ws.add_conditional_formatting("B4: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 B4:B100 in the worksheet
-ws.add_conditional_formatting("B4:B100", { :type => :cellIs, :operator => :greaterThan, :formula => "100000", :dxfId => profitable, :priority => 1 })
+ color_scale = Axlsx::ColorScale.new
+ ws.add_conditional_formatting("B4: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 B4:B100 in the worksheet
+ data_bar = Axlsx::DataBar.new
+ ws.add_conditional_formatting("B4: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 B4:B100 in the worksheet
+ icon_set = Axlsx::IconSet.new
+ ws.add_conditional_formatting("B4:B100", { :type => :iconSet, :dxfId => profitable, :priority => 1, :icon_set => icon_set })
+end
-f = File.open('example_differential_styling.xlsx', 'w')
-p.serialize(f)
+p.serialize('example_differential_styling.xlsx')