Examples:
require "rubygems" # if that is your preferred way to manage gems!
require "axlsx"
p = Axlsx::Package.new
ws = p.workbook.add_worksheet
# black text on a white background at 14pt with thin borders!
title = ws.styles.add_style(:bg_color => "FFFF0000", :fg_color=>"#FF000000", :sz=>14, :border=> {:style => :thin, :color => "FFFF0000"}
ws.add_row ["Least Popular Pets"]
ws.add_row ["", "Dry Skinned Reptiles", "Bald Cats", "Violent Parrots"], :style=>title
ws.add_row ["Votes", 6, 4, 1], :style=>Axlsx::STYLE_THIN_BORDER
f = File.open('example_you_got_style.xlsx', 'w')
p.serialize(f)
require "rubygems" require "axlsx"
p = Axlsx::Package.new
ws = p.workbook.add_worksheet
title = ws.styles.add_style(:bg_color => "FFFF0000",
:fg_color=>"#FF000000",
:border=>Axlsx::STYLE_THIN_BORDER,
:alignment=>{:horizontal => :center})
date_time = ws.styles.add_style(:num_fmt => Axlsx::NUM_FMT_YYYYMMDDHHMMSS,
:border=>Axlsx::STYLE_THIN_BORDER)
percent = ws.styles.add_style(:num_fmt => Axlsx::NUM_FMT_PERCENT,
:border=>Axlsx::STYLE_THIN_BORDER)
currency = ws.styles.add_style(:format_code=>"¥#,##0;[Red]¥-#,##0",
:border=>Axlsx::STYLE_THIN_BORDER)
ws.add_row ["Generated At:", Time.now], :styles=>[nil, date_time]
ws.add_row ["Previous Year Quarterly Profits (JPY)"], :style=>title
ws.add_row ["Quarter", "Profit", "% of Total"], :style=>title
ws.add_row ["Q1", 4000, 40], :style=>[title, currency, percent]
ws.add_row ["Q2", 3000, 30], :style=>[title, currency, percent]
ws.add_row ["Q3", 1000, 10], :style=>[title, currency, percent]
ws.add_row ["Q4", 2000, 20], :style=>[title, currency, percent]
f = File.open('example_you_got_style.xlsx', 'w')
p.serialize(f)
require "rubygems" require "axlsx"
p = Axlsx::Package.new
wb = p.workbook
ws = wb.add_worksheet
profitable = wb.styles.add_style(:bg_color => "FFFF0000",
:fg_color=>"#FF000000",
:type => :dxf)
ws.add_row ["Genreated At:", Time.now], :styles=>[nil, date_time]
ws.add_row ["Previous Year Quarterly Profits (JPY)"], :style=>title
ws.add_row ["Quarter", "Profit", "% of Total"], :style=>title
ws.add_row ["Q1", 4000, 40], :style=>[title, currency, percent]
ws.add_row ["Q2", 3000, 30], :style=>[title, currency, percent]
ws.add_row ["Q3", 1000, 10], :style=>[title, currency, percent]
ws.add_row ["Q4", 2000, 20], :style=>[title, currency, percent]
ws.add_conditional_formatting("A1:A7", { :type => :cellIs, :operator => :greaterThan, :formula => "2000", :dxfId => profitable, :priority => 1 })
f = File.open('example_differential_styling', 'w')
p.serialize(f)