diff options
| author | Jean Jacques Warmerdam <[email protected]> | 2013-07-24 12:32:54 +0200 |
|---|---|---|
| committer | Jean Jacques Warmerdam <[email protected]> | 2013-07-24 12:32:54 +0200 |
| commit | 88ee2b1ca8aee6bd14c838f247654f43c073fd2e (patch) | |
| tree | f5414ad991971477ac7b0286ebb3067dc5ca2cf7 /examples | |
| parent | 35d3cc8b21bce0c4ce7b9ec4e29d52df4b5f9cc4 (diff) | |
| parent | 7fb6629b6f1e56b3e012613ec8cfcda8628c0ca5 (diff) | |
| download | caxlsx-88ee2b1ca8aee6bd14c838f247654f43c073fd2e.tar.gz caxlsx-88ee2b1ca8aee6bd14c838f247654f43c073fd2e.zip | |
Merge branch 'master' of https://github.com/randym/axlsx
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/2010_comments.rb | 17 | ||||
| -rw-r--r-- | examples/conditional_formatting/example_conditional_formatting.rb | 6 | ||||
| -rwxr-xr-x | examples/example.rb | 36 | ||||
| -rw-r--r-- | examples/underline.rb | 13 |
4 files changed, 60 insertions, 12 deletions
diff --git a/examples/2010_comments.rb b/examples/2010_comments.rb new file mode 100644 index 00000000..6a7bedf8 --- /dev/null +++ b/examples/2010_comments.rb @@ -0,0 +1,17 @@ +#!/usr/bin/env ruby -w -s +# -*- coding: utf-8 -*- +$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" + +#```ruby +require 'axlsx' +p = Axlsx::Package.new +p.workbook.add_worksheet(:name => 'Excel 2010 comments') do |sheet| + sheet.add_row ['Cell with visible comment'] + sheet.add_row + sheet.add_row + sheet.add_row ['Cell with hidden comment'] + + sheet.add_comment :ref => 'A1', :author => 'XXX', :text => 'Visibile' + sheet.add_comment :ref => 'A4', :author => 'XXX', :text => 'Hidden', :visible => false +end +p.serialize('excel_2010_comment_test.xlsx') diff --git a/examples/conditional_formatting/example_conditional_formatting.rb b/examples/conditional_formatting/example_conditional_formatting.rb index ab49d238..f5823ab4 100644 --- a/examples/conditional_formatting/example_conditional_formatting.rb +++ b/examples/conditional_formatting/example_conditional_formatting.rb @@ -11,8 +11,8 @@ percent = book.styles.add_style(:format_code => "0.00%", :border => Axlsx::STYLE 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) +profitable = book.styles.add_style( :fg_color => "FF428751", :type => :dxf ) +unprofitable = wb.styles.add_style( :fg_color => "FF0000", :type => :dxf ) book.add_worksheet(:name => "Cell Is") do |ws| @@ -27,6 +27,8 @@ book.add_worksheet(:name => "Cell Is") do |ws| # Apply conditional formatting to range B3:B100 in the worksheet ws.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 book.add_worksheet(:name => "Color Scale") do |ws| 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| diff --git a/examples/underline.rb b/examples/underline.rb new file mode 100644 index 00000000..ccd1b394 --- /dev/null +++ b/examples/underline.rb @@ -0,0 +1,13 @@ +$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" +require 'axlsx' +p = Axlsx::Package.new +p.workbook do |wb| + wb.styles do |s| + no_underline = s.add_style :sz => 10, :b => true, :u => false, :alignment => { :horizontal=> :right } + wb.add_worksheet(:name => 'wunderlinen') do |sheet| + sheet.add_row %w{a b c really?}, :style => no_underline + end + end +end +p.serialize 'no_underline.xlsx' + |
