examples/example.rb in axlsx-2.0.1 vs examples/example.rb in axlsx-2.1.0.pre

- old
+ new

@@ -12,10 +12,11 @@ examples << :custom_borders examples << :surrounding_border examples << :deep_custom_borders examples << :row_column_style examples << :fixed_column_width +examples << :height examples << :outline_level examples << :merge_cells examples << :images examples << :format_dates examples << :mbcs @@ -38,17 +39,20 @@ examples << :defined_name examples << :printing examples << :header_footer examples << :comments examples << :panes +examples << :book_view examples << :sheet_view +examples << :hiding_sheets examples << :conditional_formatting examples << :streaming examples << :shared_strings examples << :no_autowidth examples << :cached_formula examples << :page_breaks +examples << :rich_text p = Axlsx::Package.new wb = p.workbook #``` @@ -205,10 +209,11 @@ if examples.include? :row_column_style wb.styles do |s| head = s.add_style :bg_color => "00", :fg_color => "FF" percent = s.add_style :num_fmt => 9 wb.add_worksheet(:name => "Columns and Rows") do |sheet| + # Note: you must add rows to the document *BEFORE* applying column styles to them sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4', 'col5'] sheet.add_row [1, 2, 0.3, 4, 5.0] sheet.add_row [1, 2, 0.2, 4, 5.0] sheet.add_row [1, 2, 0.1, 4, 5.0] @@ -241,11 +246,26 @@ sheet.add_row ['abcdefg', 'This is a very long text and should flow into the right cell', nil, 'xxx' ] sheet.column_widths nil, 3, 5, nil end end + +##Specifying Row height + #```ruby +if examples.include? :height + wb.styles do |s| + head = s.add_style :bg_color => "00", :fg_color => "FF" + wb.add_worksheet(:name => "fixed row height") do |sheet| + sheet.add_row ["This row will have a fixed height", "It will overwite the default row height"], :height => 30 + sheet.add_row ["This row can have a different height too"], :height => 10, :style => head + end + end +end + + +#```ruby if examples.include? :outline_level wb.add_worksheet(name: 'outline_level') do |sheet| sheet.add_row [1, 2, 3, Time.now, 5, 149455.15] sheet.add_row [1, 2, 5, 6, 5,14100.19] sheet.add_row [9500002267, 1212, 1212, 5,14100.19] @@ -277,17 +297,27 @@ #```ruby if examples.include? :images wb.add_worksheet(:name => "Image with Hyperlink") do |sheet| 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| image.width=720 image.height=666 image.hyperlink.tooltip = "Labeled Link" - image.start_at 2, 2 + image.start_at 0, 0 end + + # position in block + sheet.add_image(:image_src => img, :noSelect => true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com") do |image| + image.start_at 22, 14 + image.end_at 23, 17 + end + # all in one go + sheet.add_image(:image_src => img, :start_at => [15, 33], :end_at => [20, 37], :noSelect => true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com") end end #``` ##Using Custom Formatting and date1904 @@ -468,11 +498,11 @@ 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["A3:A6"], :title => sheet["A2"], :color => "FF0000", :show_marker => true, :smooth => true chart.add_series :data => sheet["B3:B6"], :title => sheet["B2"], :color => "00FF00" chart.catAxis.title = 'X Axis' chart.valAxis.title = 'Y Axis' end @@ -642,11 +672,31 @@ pane.y_split = 4 end end end +## Book Views +# +## Book views let you specify which sheet the show as active when the user opens the work book as well as a bunch of other +## tuning values for the UI @see Axlsx::WorkbookView +## ```ruby +if examples.include? :book_view + # when you open example.xml the second sheet is selected, and the horizontal scroll bar is much smaller showing more sheets + wb.add_view tab_ratio: 800, active_tab: 1 +end +## Hiding Sheets +## +## Sheets can be hidden with the state attribute +if examples.include? :hiding_sheets + wb.add_worksheet name: 'hidden', state: :hidden do |sheet| + sheet.add_row ['you cant see me!'] + end + wb.add_worksheet name: 'very hidden', state: :very_hidden do |sheet| + sheet.add_row ['you really cant see me!'] + end +end # conditional formatting # 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) @@ -761,17 +811,35 @@ end p.serialize("no-use_autowidth.xlsx") end #``` - - +#```ruby if examples.include? :cached_formula p = Axlsx::Package.new p.use_shared_strings = true wb = p.workbook wb.add_worksheet(:name => "cached formula") do | sheet | sheet.add_row [1, 2, '=A1+B1'], :formula_values => [nil, nil, 3] end p.serialize 'cached_formula.xlsx' end +#``` +#```ruby +if examples.include? :rich_text + p = Axlsx::Package.new + p.use_shared_strings = true + wb = p.workbook + wrap_text = wb.styles.add_style({:alignment => {:horizontal => :center, :vertical => :center, :wrap_text => true}} ) + rt = Axlsx::RichText.new + rt.add_run('I\'m bold, ', :b => true) + rt.add_run('I\'m italic, ', :i => true) + rt.add_run('I\'m strike' + "\n", :strike => true) + rt.add_run('I\'m bold, italic and strike' + "\n", :b => true, :i => true, :strike => true) + rt.add_run('I\'m style-less :D') + wb.add_worksheet(:name => "RichText") do | sheet | + sheet.add_row [rt], :style => wrap_text + end + p.serialize 'rich_text.xlsx' +end +#```