summaryrefslogtreecommitdiffhomepage
path: root/examples/example.rb
diff options
context:
space:
mode:
Diffstat (limited to 'examples/example.rb')
-rwxr-xr-xexamples/example.rb36
1 files changed, 26 insertions, 10 deletions
diff --git a/examples/example.rb b/examples/example.rb
index c9b5564e..218237a6 100755
--- a/examples/example.rb
+++ b/examples/example.rb
@@ -57,6 +57,7 @@ if examples.include? :basic
wb.add_worksheet(:name => "Basic Worksheet") do |sheet|
sheet.add_row ["First Column", "Second", "Third"]
sheet.add_row [1, 2, 3]
+ sheet.add_row [' preserving whitespace']
end
end
#```
@@ -277,11 +278,12 @@ if examples.include? :images
img = File.expand_path('../image1.jpeg', __FILE__)
# specifying the :hyperlink option will add a hyper link to your image.
# @note - Numbers does not support this part of the specification.
- sheet.add_image(:image_src => img, :noSelect => true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com") do |image|
+ sheet.add_image(:image_src => img, :noSelect => true, end_at: true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com") do |image|
image.width=720
image.height=666
image.hyperlink.tooltip = "Labeled Link"
image.start_at 2, 2
+ image.end_at 200, 200
end
end
end
@@ -309,6 +311,7 @@ end
#```ruby
if examples.include? :mbcs
+ wb.styles.fonts.first.name = 'Arial Unicode MS'
wb.add_worksheet(:name => "日本語でのシート名") do |sheet|
sheet.add_row ["日本語"]
sheet.add_row ["华语/華語"]
@@ -408,7 +411,7 @@ if examples.include? :bar_chart
sheet.add_row ["A Simple Bar Chart"]
%w(first second third).each { |label| sheet.add_row [label, rand(24)+1] }
sheet.add_chart(Axlsx::Bar3DChart, :start_at => "A6", :end_at => "F20") do |chart|
- chart.add_series :data => sheet["B2:B4"], :labels => sheet["A2:A4"], :title => sheet["A1"]
+ chart.add_series :data => sheet["B2:B4"], :labels => sheet["A2:A4"], :title => sheet["A1"], :colors => ["00FF00", "0000FF"]
end
end
end
@@ -423,7 +426,7 @@ if examples.include? :chart_gridlines
sheet.add_row ["Bar Chart without gridlines"]
%w(first second third).each { |label| sheet.add_row [label, rand(24)+1] }
sheet.add_chart(Axlsx::Bar3DChart, :start_at => "A6", :end_at => "F20") do |chart|
- chart.add_series :data => sheet["B2:B4"], :labels => sheet["A2:A4"]
+ chart.add_series :data => sheet["B2:B4"], :labels => sheet["A2:A4"], :colors => ["00FF00", "FF0000"]
chart.valAxis.gridlines = false
chart.catAxis.gridlines = false
end
@@ -455,14 +458,23 @@ if examples.include? :line_chart
4.times do
sheet.add_row [ rand(24)+1, rand(24)+1]
end
- sheet.add_chart(Axlsx::Line3DChart, :title => "Simple Line Chart", :rotX => 30, :rotY => 20) do |chart|
+ sheet.add_chart(Axlsx::Line3DChart, :title => "Simple 3D Line Chart", :rotX => 30, :rotY => 20) do |chart|
chart.start_at 0, 5
chart.end_at 10, 20
- chart.add_series :data => sheet["A3:A6"], :title => sheet["A2"]
- chart.add_series :data => sheet["B3:B6"], :title => sheet["B2"]
+ chart.add_series :data => sheet["A3:A6"], :title => sheet["A2"], :color => "0000FF"
+ chart.add_series :data => sheet["B3:B6"], :title => sheet["B2"], :color => "FF0000"
chart.catAxis.title = 'X Axis'
chart.valAxis.title = 'Y Axis'
end
+ sheet.add_chart(Axlsx::LineChart, :title => "Simple Line Chart", :rotX => 30, :rotY => 20) do |chart|
+ chart.start_at 0, 21
+ chart.end_at 10, 41
+ chart.add_series :data => sheet["A3:A6"], :title => sheet["A2"], :color => "FF0000"
+ chart.add_series :data => sheet["B3:B6"], :title => sheet["B2"], :color => "00FF00"
+ chart.catAxis.title = 'X Axis'
+ chart.valAxis.title = 'Y Axis'
+ end
+
end
end
#```
@@ -479,8 +491,8 @@ if examples.include? :scatter_chart
sheet.add_chart(Axlsx::ScatterChart, :title => "example 7: Scatter Chart") do |chart|
chart.start_at 0, 4
chart.end_at 10, 19
- chart.add_series :xData => sheet["B1:E1"], :yData => sheet["B2:E2"], :title => sheet["A1"]
- chart.add_series :xData => sheet["B3:E3"], :yData => sheet["B4:E4"], :title => sheet["A3"]
+ chart.add_series :xData => sheet["B1:E1"], :yData => sheet["B2:E2"], :title => sheet["A1"], :color => "FF0000"
+ chart.add_series :xData => sheet["B3:E3"], :yData => sheet["B4:E4"], :title => sheet["A3"], :color => "00FF00"
end
end
end
@@ -583,6 +595,8 @@ if examples.include? :comments
wb.add_worksheet(:name => 'comments') do |sheet|
sheet.add_row ['Can we build it?']
sheet.add_comment :ref => 'A1', :author => 'Bob', :text => 'Yes We Can!'
+ sheet.add_comment :ref => 'A2', :author => 'Bob', :text => 'Yes We Can! - but I dont think you need to know about it!', :visible => false
+
end
end
@@ -636,8 +650,8 @@ if examples.include? :conditional_formatting
money = wb.styles.add_style(:format_code => '0,000', :border => Axlsx::STYLE_THIN_BORDER)
# define the style for conditional formatting
- profitable = wb.styles.add_style( :fg_color=>"FF428751",
- :type => :dxf)
+ profitable = wb.styles.add_style( :fg_color => "FF428751", :type => :dxf )
+ unprofitable = wb.styles.add_style( :fg_color => "FF0000", :type => :dxf )
wb.add_worksheet(:name => "Conditional Cell Is") do |sheet|
@@ -652,6 +666,8 @@ if examples.include? :conditional_formatting
# Apply conditional formatting to range B3:B100 in the worksheet
sheet.add_conditional_formatting("B3:B100", { :type => :cellIs, :operator => :greaterThan, :formula => "100000", :dxfId => profitable, :priority => 1 })
+ # Apply conditional using the between operator; NOTE: supply an array to :formula for between/notBetween
+ sheet.add_conditional_formatting("C3:C100", { :type => :cellIs, :operator => :between, :formula => ["0.00%","100.00%"], :dxfId => unprofitable, :priority => 1 })
end
wb.add_worksheet(:name => "Conditional Color Scale") do |sheet|