This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'axlsx' | |
p = Axlsx::Package.new | |
p.workbook do |wb| | |
# Stuff like this is why I LOVE RUBY | |
# If you dont know about hash default values | |
# LEARN IT! LIVE IT! LOVE IT! | |
defaults = { :style => :thick, :color => "000000" } | |
borders = Hash.new do |hash, key| | |
hash[key] = wb.styles.add_style :border => defaults.merge( { :edges => key.to_s.split('_').map(&:to_sym) } ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#```ruby | |
wb.add_worksheet(name: 'outline_level') do |sheet| | |
sheet.add_row [1, 2, 3, 4, Time.now, 149455.15] | |
sheet.add_row [1, 2, 5, 6, Time.now,14100.19] | |
sheet.add_row [9500002267, 1212, 1212, Time.now,14100.19] | |
sheet.add_row [], :collapsed => 1 | |
sheet.rows[0..2].each do |row| | |
row.outline_level = 1 | |
# This will collapse the outline level rows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Hacking comment position! | |
# Use at your own risk :) | |
# add_comment is the preferred way to add comments to your worksheet. However, if you really need to position a | |
# a specific comment, here is one way to do it. | |
require 'axlsx' | |
p = Axlsx::Package.new | |
wb = p.workbook | |
wb.add_worksheet(:name => 'comments') do |sheet| | |
sheet.add_row ['Can we build it?', 'Yes we can!'] | |
sheet.add_comment(:ref => 'A1', :author => 'Bob', :text => 'Yes We Can!').tap do |comment| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'axlsx' | |
Axlsx::Package.new do |p| | |
p.workbook do |wb| | |
styles = wb.styles | |
header = styles.add_style :bg_color => "DD", :sz => 16, :b => true, :alignment => {:horizontal => :center} | |
tbl_header = styles.add_style :b => true, :alignment => { :horizontal => :center } | |
ind_header = styles.add_style :bg_color => "FFDFDEDF", :b => true, :alignment => {:indent => 1} | |
col_header = styles.add_style :bg_color => "FFDFDEDF", :b => true, :alignment => { :horizontal => :center } | |
label = styles.add_style :alignment => { :indent => 1 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'axlsx' | |
p = Axlsx::Package.new | |
p.workbook do |wb| | |
# define your regular styles | |
styles = wb.styles | |
title = styles.add_style :sz => 15, :b => true, :u => true | |
default = styles.add_style :border => Axlsx::STYLE_THIN_BORDER | |
header = styles.add_style :bg_color => '00', :fg_color => 'FF', :b => true | |
money = styles.add_style :format_code => '#,###,##0', :border => Axlsx::STYLE_THIN_BORDER | |
percent = styles.add_style :num_fmt => Axlsx::NUM_FMT_PERCENT, :border => Axlsx::STYLE_THIN_BORDER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" | |
require 'axlsx' | |
require 'date' | |
p = Axlsx::Package.new | |
wb = p.workbook | |
wb.styles do |style| | |
# Date/Time Styles | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Using Tables: | |
#This will add in the sorting filters for you as well as apply default table styling in excel. | |
#LibraOffice does the filters, but not the styling (as does Google docs if I recall correctly.) | |
#```ruby | |
wb.add_worksheet(:name => "Table") do |sheet| | |
sheet.add_row ["Build Matrix"] | |
sheet.add_row ["Build", "Duration", "Finished", "Rvm"] | |
sheet.add_row ["19.1", "1 min 32 sec", "about 10 hours ago", "1.8.7"] |
OlderNewer