diff options
| author | Randy Morgan <[email protected]> | 2012-04-21 09:23:26 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-04-21 09:23:26 +0900 |
| commit | 6a1bb3e599743f20e0fae92bc5a44745f70056e6 (patch) | |
| tree | 5142de7fecb515a4a85e15f68d073c76e4ec527e /examples/example_conditional_formatting.rb | |
| parent | d1c44ab60b2740af32a085a0f7c8bfa445589412 (diff) | |
| parent | e43fd6cb182205ee52dc76d19758b9f0203bab4e (diff) | |
| download | caxlsx-6a1bb3e599743f20e0fae92bc5a44745f70056e6.tar.gz caxlsx-6a1bb3e599743f20e0fae92bc5a44745f70056e6.zip | |
Merge branch 'master' of github.com:randym/axlsx
Diffstat (limited to 'examples/example_conditional_formatting.rb')
| -rw-r--r-- | examples/example_conditional_formatting.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/examples/example_conditional_formatting.rb b/examples/example_conditional_formatting.rb new file mode 100644 index 00000000..cfff3c86 --- /dev/null +++ b/examples/example_conditional_formatting.rb @@ -0,0 +1,31 @@ +#!/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 +ws = book.add_worksheet + +# 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) + +# 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 }) + +f = File.open('example_differential_styling.xlsx', 'w') +p.serialize(f) |
