diff options
Diffstat (limited to 'examples/example.rb')
| -rwxr-xr-x | examples/example.rb | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/examples/example.rb b/examples/example.rb index 116ce730..4d4c2630 100755 --- a/examples/example.rb +++ b/examples/example.rb @@ -14,6 +14,7 @@ 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 @@ -50,6 +51,7 @@ examples << :no_autowidth examples << :cached_formula examples << :page_breaks examples << :rich_text +examples << :tab_color p = Axlsx::Package.new wb = p.workbook @@ -210,6 +212,7 @@ if examples.include? :row_column_style 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] @@ -246,6 +249,21 @@ if examples.include? :fixed_column_width 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| @@ -659,7 +677,7 @@ 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 +## 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 @@ -683,6 +701,7 @@ end 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) + status = wb.styles.add_style(:border => Axlsx::STYLE_THIN_BORDER) # define the style for conditional formatting profitable = wb.styles.add_style( :fg_color => "FF428751", :type => :dxf ) @@ -746,6 +765,19 @@ if examples.include? :conditional_formatting icon_set = Axlsx::IconSet.new sheet.add_conditional_formatting("B3:B100", { :type => :iconSet, :dxfId => profitable, :priority => 1, :icon_set => icon_set }) end + + wb.add_worksheet(:name => "Contains Text") do |sheet| + sheet.add_row ["Previous Year Quarterly Profits (JPY)"] + sheet.add_row ["Quarter", "Profit", "% of Total", "Status"] + offset = 3 + rows = 20 + offset.upto(rows + offset) do |i| + sheet.add_row ["Q#{i}", 10000*((rows/2-i) * (rows/2-i)), "=100*B#{i}/SUM(B3:B#{rows+offset})", (10000*((rows/2-i) * (rows/2-i))) > 100000 ? "PROFIT" : "LOSS"], :style=>[nil, money, percent, status] + end + # Apply conditional formatting to range D3:D100 in the worksheet to match words. + sheet.add_conditional_formatting("D3:D100", { :type => :containsText, :operator => :equal, :text => "PROFIT", :dxfId => profitable, :priority => 1 }) + sheet.add_conditional_formatting("D3:D100", { :type => :containsText, :operator => :equal, :text => "LOSS", :dxfId => unprofitable, :priority => 1 }) + end end # Page Breaks @@ -825,4 +857,19 @@ if examples.include? :rich_text end p.serialize 'rich_text.xlsx' end -#```
\ No newline at end of file +#``` + +##Change tab color of sheet + +#```ruby +if examples.include? :tab_color + p = Axlsx::Package.new + p.use_shared_strings = true + wb = p.workbook + wb.add_worksheet(:name => "Change Tab Color") do |sheet| + sheet.add_row ["Check", "out", "the", "Tab Color", "below!"] + sheet.sheet_pr.tab_color = "FFFF6666" + end + p.serialize 'tab_color.xlsx' +end +##``` |
