summaryrefslogtreecommitdiffhomepage
path: root/examples/conditional_formatting/getting_barred.rb
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-04-25 20:57:49 +0900
committerRandy Morgan <[email protected]>2012-04-25 20:57:49 +0900
commit91ea5ff009672adbad8587a1a4437d0b02519b0e (patch)
tree383b2747b674cf64296fc05c95a44c3ee8f3dbfc /examples/conditional_formatting/getting_barred.rb
parent1381dca8d62748ad103004a2cf35cbc51e7c336c (diff)
downloadcaxlsx-91ea5ff009672adbad8587a1a4437d0b02519b0e.tar.gz
caxlsx-91ea5ff009672adbad8587a1a4437d0b02519b0e.zip
documentation updates and example dir restructuring.
Diffstat (limited to 'examples/conditional_formatting/getting_barred.rb')
-rw-r--r--examples/conditional_formatting/getting_barred.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/examples/conditional_formatting/getting_barred.rb b/examples/conditional_formatting/getting_barred.rb
new file mode 100644
index 00000000..6e69b6ab
--- /dev/null
+++ b/examples/conditional_formatting/getting_barred.rb
@@ -0,0 +1,37 @@
+#!/usr/bin/env ruby -w -s
+# -*- coding: utf-8 -*-
+$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
+require 'axlsx'
+p = Axlsx::Package.new
+p.workbook do |wb|
+ # define your regular styles
+ styles = wb.styles
+ title = styles.add_style :sz => 15, :b => true, :u => true
+ default = styles.add_style :border => Axlsx::STYLE_THIN_BORDER
+ header = styles.add_style :bg_color => '00', :fg_color => 'FF', :b => true
+ money = styles.add_style :format_code => '#,###,##0', :border => Axlsx::STYLE_THIN_BORDER
+ percent = styles.add_style :num_fmt => Axlsx::NUM_FMT_PERCENT, :border => Axlsx::STYLE_THIN_BORDER
+
+ # define the style for conditional formatting - its the :dxf bit that counts!
+ profitable = styles.add_style :fg_color => 'FF428751', :sz => 12, :type => :dxf, :b => true
+
+ wb.add_worksheet(:name => 'Data Bar Conditional Formatting') do |ws|
+ ws.add_row ['A$$le Q1 Revenue Historical Analysis (USD)'], :style => title
+ ws.add_row
+ ws.add_row ['Quarter', 'Profit', '% of Total'], :style => header
+ ws.add_row ['Q1-2010', '15680000000', '=B4/SUM(B4:B7)'], :style => [default, money, percent]
+ ws.add_row ['Q1-2011', '26740000000', '=B5/SUM(B4:B7)'], :style => [default, money, percent]
+ ws.add_row ['Q1-2012', '46330000000', '=B6/SUM(B4:B7)'], :style => [default, money, percent]
+ ws.add_row ['Q1-2013(est)', '72230000000', '=B7/SUM(B4:B7)'], :style => [default, money, percent]
+
+ ws.merge_cells 'A1:C1'
+
+ # Apply conditional formatting to range B4:B7 in the worksheet
+ data_bar = Axlsx::DataBar.new
+ ws.add_conditional_formatting 'B4:B7', { :type => :dataBar,
+ :dxfId => profitable,
+ :priority => 1,
+ :data_bar => data_bar }
+ end
+end
+p.serialize 'getting_barred.xlsx'