summaryrefslogtreecommitdiffhomepage
path: root/examples/example.rb
diff options
context:
space:
mode:
authorAdam Mueller <[email protected]>2012-11-23 09:19:56 -0800
committerAdam Mueller <[email protected]>2012-11-23 09:25:27 -0800
commit171ffca724ba0bbf845af1f4c7712e663500d4e8 (patch)
tree03c49c65f479a00eb1e976c320eee5d642fe1b05 /examples/example.rb
parent8147c29641f916557092fe5cd24909c774b5c8d1 (diff)
downloadcaxlsx-171ffca724ba0bbf845af1f4c7712e663500d4e8.tar.gz
caxlsx-171ffca724ba0bbf845af1f4c7712e663500d4e8.zip
Adds an example of header/footers.
Also, header and footer content is now escaped. So that the user doesn't have to worry about that. Change-Id: Ib35b2eca6755d9b2d9974be25887734873d6e64a
Diffstat (limited to 'examples/example.rb')
-rwxr-xr-xexamples/example.rb21
1 files changed, 16 insertions, 5 deletions
diff --git a/examples/example.rb b/examples/example.rb
index 87678a2e..1e93f4f8 100755
--- a/examples/example.rb
+++ b/examples/example.rb
@@ -35,6 +35,7 @@ examples = []
#examples << :repeated_header
#examples << :defined_name
#examples << :printing
+#examples << :header_footer
#examples << :comments
#examples << :panes
examples << :conditional_formatting
@@ -149,7 +150,7 @@ if examples.include? :surrounding_border
# LEARN IT! LIVE IT! LOVE IT!
defaults = { :style => :thick, :color => "000000" }
borders = Hash.new do |hash, key|
- hash[key] = wb.styles.add_style :border => defaults.merge( { :edges => key.to_s.split('_').map(&:to_sym) } )
+ hash[key] = wb.styles.add_style :border => defaults.merge( { :edges => key.to_s.split('_').map(&:to_sym) } )
end
top_row = [0, borders[:top_left], borders[:top], borders[:top], borders[:top_right]]
middle_row = [0, borders[:left], nil, nil, borders[:right]]
@@ -167,11 +168,11 @@ if examples.include? :surrounding_border
end
end
-#```ruby
+#```ruby
# Hacking border styles
if examples.include? :deep_custom_borders
wb.styles do |s|
- top_bottom = s.add_style :border => { :style => :thick, :color =>"FFFF0000", :edges => [:top, :bottom] }
+ top_bottom = s.add_style :border => { :style => :thick, :color =>"FFFF0000", :edges => [:top, :bottom] }
border = s.borders[s.cellXfs[top_bottom].borderId]
# edit existing border parts
border.prs.each do |part|
@@ -511,7 +512,7 @@ if examples.include? :repeated_header
wb.add_worksheet(:name => "repeated header") do |sheet|
sheet.add_row %w(These Column Header Will Render On Every Printed Sheet)
200.times { sheet.add_row %w(1 2 3 4 5 6 7 8) }
- wb.add_defined_name("'repeated header'!$1:$1", :local_sheet_id => sheet.index, :name => '_xlnm.Print_Titles')
+ wb.add_defined_name("'repeated header'!$1:$1", :local_sheet_id => sheet.index, :name => '_xlnm.Print_Titles')
end
end
@@ -546,7 +547,17 @@ if examples.include? :printing
end
#```
-## Add Comments to your spreadsheet
+## Add headers and footers to a worksheet
+#``` ruby
+if examples.include? :header_footer
+ header_footer = {:different_first => false, :odd_header => '&L&F : &A&R&D &T', :odd_footer => '&C&Pof&N'}
+ wb.add_worksheet(:name => "header footer", :header_footer => header_footer) do |sheet|
+ sheet.add_row ["this sheet has a header and a footer"]
+ end
+end
+#```
+
+## Add Comments to your spreadsheet
#``` ruby
if examples.include? :comments
wb.add_worksheet(:name => 'comments') do |sheet|