Writes XLSX files. Simple, clean XML and style. Supports autofilters and headers/footers with images and page numbers if you're willing to do a little Excel hacking.
Ruby HTML
Pull request Compare This branch is 81 commits ahead of mumboe:master.
Permalink
Failed to load latest commit information.
lib Fixes #13: Fix TRUE_FALSE_PATTERN to perform exact match against "tru… Nov 2, 2014
test
.gitignore clean up after tests Apr 24, 2012
CHANGELOG mention @rcook's true/false fix Apr 23, 2015
Gemfile modernize May 20, 2014
LICENSE update license and copyright May 20, 2014
README.markdown make more obvious the diff Oct 13, 2014
Rakefile add basic tests Apr 23, 2012
foo.rb treat "true" as true when calculating cell type Jul 4, 2012
repack.rb useful tools for development Jun 8, 2012
unpack.rb useful tools for development Jun 8, 2012
xlsx_writer.gemspec use MurmurHash3::V128.str_digest instead of Digest::MD5 for shared st… May 20, 2014

README.markdown

xlsx_writer

Writes (doesn't read or modify) XLSX files.

Imposes (non-customizable) a certain style: Arial 10pt, left-aligned text and dates, right-aligned numbers and currency

Optionally adds an autofilter.

Credit

Based on the original simple_xlsx_writer gem and patches by mumboe

Changes from simple_xlsx_writer (caution opinionated)

Then I tore it down and rebuilt it:

  • no longer constructs everything in a single zipstream... instead writes the individual files to /tmp and then zips them together
  • absolute minimum XML - went through every line, testing to see if I could remove it
  • no more block format - this was more appropriate when it was constructed as a zipstream

Features not present in simple_xlsx_writer:

  • opinionated, non-customizable styles - Arial 10pt, left-aligned text and dates, right-aligned numbers and currency
  • autofilter based on a cell range
  • header and footer, with support for images (.emf only) and page numbers
  • fits columns to text

Wishlist

  1. real documentation
  2. real tests

Corporate support

Faraday logo

We use xlsx_writer for marketing analytics at Faraday.

Example

require 'xlsx_writer'

doc = XlsxWriter.new

# show TRUE for true but a blank cell instead of FALSE
doc.quiet_booleans!

sheet1 = doc.add_sheet("People")

# freeze pane underneath the first (header) row
sheet1.freeze_top_left = 'A2'

# DATA

sheet1.add_row([
  "DoB",
  "Name",
  "Occupation",
  "Salary",
  "Citations",
  "Average citations per paper"
])
sheet1.add_row([
  Date.parse("July 31, 1912"), 
  "Milton Friedman",
  "Economist / Statistician",
  {:type => :Currency, :value => 10_000},
  500_000,
  0.31
])
sheet1.add_autofilter 'A1:E1'

# FORMATTING

doc.page_setup.top = 1.5
doc.header.right.contents = 'Corporate Reporting'
doc.footer.left.contents = 'Confidential'
doc.footer.right.contents = :page_x_of_y

# if you really need images in header/footer: do it in Excel, save, unzip the xlsx... get the .emf files, "cropleft" (if necessary), etc. from there

left_header_image = doc.add_image('image1.emf', 118, 107)
left_header_image.croptop = '11025f'
left_header_image.cropleft = '9997f'
center_footer_image = doc.add_image('image2.emf', 116, 36)
doc.header.left.contents = left_header_image
doc.footer.center.contents = [ 'Powered by ', center_footer_image ]
doc.page_setup.header = 0
doc.page_setup.footer = 0

# OUTPUT

# You should move the file to where you want it
require 'fileutils'
::FileUtils.mv doc.path, 'myfile.xlsx'

# don't forget
doc.cleanup

Copyright

Copyright (c) 2014 Dee Zsombor, Justin Beck, Seamus Abshere. See LICENSE for details.