WriteExcel
Write to a cross-platform Excel binary file.
Recent Changes
0.3.0
-
Chart support(Area, Bar, Column, Line, Pie, Scatter, Stock).
-
Document added. See rdoc in your installed gem directory.
-
Change Class name from ‘Spreadsheet::WriteExcel’ to ‘WriteExcel’.
-
many bug fix.
Description
This library is converted from Spreadsheet::WriteExcel module of Perl. search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel-2.37/
Some examples written in perl was successfully converted to Ruby. But this library written in Ruby has many bugs, I think.
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 and images 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 OpenOffice.org.
This module cannot be used to read an Excel file.
Usage
See rdoc’s WriteExcel class document.
Example Code:
require 'writeexcel'
# Create a new Excel Workbook
workbook = WriteExcel.new('ruby.xls')
# Add worksheet(s)
worksheet = workbook.add_worksheet
worksheet2 = workbook.add_worksheet
# Add and define a format
format = workbook.add_format
format.set_bold
format.set_color('red')
format.set_align('right')
# 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
workbook.close
Difference with Perl module
-
WriteExcel.new()
-
accept default format parameter such as new(‘foo.xls’, :font => ‘Roman’, :size => 12)
-
-
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 .…..
Caution
This library can handle multibyte character written in utf8. I tested in Japanese, and it looks work well. But, in this version, utf8 or not is recognized by matching non-ascii characters because ruby 1.8 can not recognize character code correctly.
Dependencies
-
ruby 1.8
Author
Original was written in Perl by John McNamara ([email protected]).
Convert to ruby by Hideo Nakamura ([email protected])
License
same as Ruby.