Skip to content
ruby gem for Write to a cross-platform Excel binary file.
Ruby HTML Other
Branch: master
Clone or download
Hideo NAKAMURA bug fix : #44
Latest commit d034506 Jul 28, 2015
Type Name Latest commit message Commit time
Failed to load latest commit information.
charts delete 'Spreadsheet::' Oct 19, 2010
examples remove "require 'rubygems'" Dec 27, 2014
html typo : PI -> PI() issue #30 Dec 16, 2013
test not to use simplecov Dec 30, 2014
utils utility for adding magic comment to all rb files. Apr 8, 2010
.gitattributes customize git diff hunk-header. Apr 8, 2010
.gitignore change environment from jeweler to bundler. Feb 8, 2013
.travis.yml add .travis.yml Dec 30, 2014
LICENSE.txt change environment from jeweler to bundler. Feb 8, 2013
README.rdoc add travis badge. Dec 30, 2014
Rakefile change environment from jeweler to bundler. Feb 8, 2013
writeexcel.rdoc * fix typo. Jun 24, 2011



Write to a cross-platform Excel binary file.

Gem Version Build Status


This library is converted from Spreadsheet::WriteExcel module of Perl.

Original description is below:

The Spreadsheet::WriteExcel module can be used to create a cross-
platform Excel binary file. Multiple worksheets can be added to a
workbook and formatting can be applied to cells. Text, numbers,
formulas, hyperlinks, images and charts can be written to the cells.

TThe Excel file produced by this module is compatible with 97,
2000, 2002, 2003 and 2007.

The module will work on the majority of Windows, UNIX and
Macintosh platforms. Generated files are also compatible with the
spreadsheet applications Gnumeric and

This module cannot be used to read an Excel file.


Add this line to your application's Gemfile:

gem 'writeexcel'

And then execute:

$ bundle

Or install it yourself as:

$ gem install writeexcel


See Reference . You must save source file in UTF8, and run ruby with -Ku option or set $KCODE='u' in Ruby 1.8.

Example Code:

require 'writeexcel'

# Create a new Excel Workbook
workbook ='ruby.xls')

# Add worksheet(s)
worksheet  = workbook.add_worksheet
worksheet2 = workbook.add_worksheet

# Add and define a format
format = workbook.add_format

# write a formatted and unformatted string.
worksheet.write(1, 1, 'Hi Excel.', format)  # cell B2
worksheet.write(2, 1, 'Hi Excel.')          # cell B3

# write a number and formula using A1 notation
worksheet.write('B4', 3.14159)
worksheet.write('B5', '=SIN(B4/4)')

# write to file

Difference with Perl module


    • accept default format parameter such as new('foo.xls', :font => 'Roman', :size => 12)

  • Unary minus is supported, but it will be stored as '-1*'. ex) '=-1' -> '=-1*1', '=-SIN(PI()/2)' => '=-1*SIN(PI()/2)'

  • Worksheet.write(row, col, token, format)

    • if token.kind_of?(Numeric) then call write_number, if token.kind_of?(String) then not call write_number().

  • Worksheet.keep_leading_zeros()

    • ignore. if write 0001, use string such as write(1,2, '0001')

  • and .…..

Recent Change


  • use test-unit gem instead of test/unit.


  • put formula parsers classes in a module to avoid namespace conflicts. (thanks Kevin)


  • Bug fix issue 29. bug in extern sheet reference.


  • Bug fix issue 28. bug in non ascii worksheet names.

  • Bug fix in testcase issue 28. fail due to defferent timezone.


  • Bug fix issue 25. bug in Chart#set_legend.


  • Bug fix in Workbook#set_properties.


Original was written in Perl by John McNamara (

Convert to ruby by Hideo Nakamura ( Copyright © 2009-2014 Hideo NAKAMURA. See LICENSE.txt for details.




  1. Fork it

  2. Create your feature branch (`git checkout -b my-new-feature`)

  3. Commit your changes (`git commit -am 'Add some feature'`)

  4. Push to the branch (`git push origin my-new-feature`)

  5. Create new Pull Request

You can’t perform that action at this time.