diff options
| author | Jonathan Tron <[email protected]> | 2015-07-04 11:59:37 +0200 |
|---|---|---|
| committer | Jonathan Tron <[email protected]> | 2015-07-04 11:59:37 +0200 |
| commit | 6c4719411cb4a400a70c70a9017d30c812708dea (patch) | |
| tree | 6aa6d1a23a075ea09ca1975816b771726d491b2f /examples | |
| parent | dbb456aa65c7637233da174a5d515c80fe04aefd (diff) | |
| parent | c82905173138a3be80e5c4617f8cecf62a97f6b8 (diff) | |
| download | caxlsx-6c4719411cb4a400a70c70a9017d30c812708dea.tar.gz caxlsx-6c4719411cb4a400a70c70a9017d30c812708dea.zip | |
Merge branch 'example' of https://github.com/shifakhan/axlsx into shifakhan-example
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/conditional_formatting/example_conditional_formatting.rb | 15 | ||||
| -rwxr-xr-x | examples/example.rb | 14 |
2 files changed, 29 insertions, 0 deletions
diff --git a/examples/conditional_formatting/example_conditional_formatting.rb b/examples/conditional_formatting/example_conditional_formatting.rb index 320ae9f1..37df52f0 100644 --- a/examples/conditional_formatting/example_conditional_formatting.rb +++ b/examples/conditional_formatting/example_conditional_formatting.rb @@ -9,6 +9,7 @@ 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) +status = book.styles.add_style(:border => Axlsx::STYLE_THIN_BORDER) # define the style for conditional formatting profitable = book.styles.add_style( :fg_color => "428751", :type => :dxf ) @@ -71,4 +72,18 @@ book.add_worksheet(:name => "Icon Set") do |ws| ws.add_conditional_formatting("B3:B100", { :type => :iconSet, :dxfId => profitable, :priority => 1, :icon_set => icon_set }) end +book.add_worksheet(:name => "Contains Text") do |ws| + ws.add_row ["Previous Year Quarterly Profits (JPY)"] + ws.add_row ["Quarter", "Profit", "% of Total", "Status"] + 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})", (10000*((rows/2-i) * (rows/2-i))) > 100000 ? "PROFIT" : "LOSS"], :style=>[nil, money, percent, status] + end + +# Apply conditional formatting to range D3:D100 in the worksheet + ws.add_conditional_formatting("D3:D100", { :type => :containsText, :operator => :equal, :text => "PROFIT", :dxfId => profitable, :priority => 1 }) + ws.add_conditional_formatting("D3:D100", { :type => :containsText, :operator => :equal, :text => "LOSS", :dxfId => unprofitable, :priority => 1 }) +end + p.serialize('example_conditional_formatting.xlsx') diff --git a/examples/example.rb b/examples/example.rb index 72066140..4d4c2630 100755 --- a/examples/example.rb +++ b/examples/example.rb @@ -701,6 +701,7 @@ end if examples.include? :conditional_formatting percent = wb.styles.add_style(:format_code => "0.00%", :border => Axlsx::STYLE_THIN_BORDER) money = wb.styles.add_style(:format_code => '0,000', :border => Axlsx::STYLE_THIN_BORDER) + status = wb.styles.add_style(:border => Axlsx::STYLE_THIN_BORDER) # define the style for conditional formatting profitable = wb.styles.add_style( :fg_color => "FF428751", :type => :dxf ) @@ -764,6 +765,19 @@ if examples.include? :conditional_formatting icon_set = Axlsx::IconSet.new sheet.add_conditional_formatting("B3:B100", { :type => :iconSet, :dxfId => profitable, :priority => 1, :icon_set => icon_set }) end + + wb.add_worksheet(:name => "Contains Text") do |sheet| + sheet.add_row ["Previous Year Quarterly Profits (JPY)"] + sheet.add_row ["Quarter", "Profit", "% of Total", "Status"] + offset = 3 + rows = 20 + offset.upto(rows + offset) do |i| + sheet.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})", (10000*((rows/2-i) * (rows/2-i))) > 100000 ? "PROFIT" : "LOSS"], :style=>[nil, money, percent, status] + end + # Apply conditional formatting to range D3:D100 in the worksheet to match words. + sheet.add_conditional_formatting("D3:D100", { :type => :containsText, :operator => :equal, :text => "PROFIT", :dxfId => profitable, :priority => 1 }) + sheet.add_conditional_formatting("D3:D100", { :type => :containsText, :operator => :equal, :text => "LOSS", :dxfId => unprofitable, :priority => 1 }) + end end # Page Breaks |
