Skip to content

practicingruby/writeexcel

 
 

Repository files navigation

writeexcel

Write to a cross-platform Excel binary file.

Recent Changes

v0.4.2

  • use namespace ‘Writeexcel::’ to Chart(::*), Colors, Format, Formula, Worksheet.

  • add_chart() parameter of :type changed . ex) Chart::Bar => ‘Chart::Bar’

  • almost complete japanese document : writeexcel.doc

  • Bug fix. typo in Worksheet#set_zoom()

  • some refactoring.

v0.4.1

  • Bug fix. Workbook#add_format() doesn’t work when received two or more parameters.

  • Bug fix. Worksheet#write_formula() doesn’t work when formula contains utf8 string.

v0.4.0

  • works also on Ruby 1.9.1.

  • modify README.rdoc below.

  • write source and run in utf8.

  • unary minus supported. but -1 –> -1*1, -SIN() –> -1*SIN()

v0.3.5

  • Bug fix. Worksheet#write_comment() doesn’t work when value arg is numeric.

  • Bug fix. TRUE/FALSE in formula was misundarstood as :NAME.

  • Bug fix. Worksheet#close() mis-handled @colinfo.

  • Bug fix. Worksheet#set_row() grbit mis-calculate by param hidden.

  • convert examples.(formula_result, indent, merge6, outline, outline_collapsed, panes, right_to_left, row_wrap)

v0.3.4

  • Bug fix. add_comment doesn’t work.

  • convert examples.(chess, colors, comment1, comment2)

v0.3.3

  • add recent change in this document.

v0.3.2

  • Bug fix. defined name doesn’t work.

  • use jeweler to maintain gem.

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. You must save source file in UTF8 and run ruby with -Ku option or set $KCODE=‘u’.

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)

  • 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 .…..

Caution

You must save source file in UTF8 and run ruby with -Ku option or set $KCODE=‘u’ when use urf8 string data.

Dependencies

  • ruby 1.8, ruby 1.9.1

Author

Original was written in Perl by John McNamara (jmcnamara@cpan.org).

Convert to ruby by Hideo Nakamura (cxn03651@msj.biglobe.ne.jp) Copyright © 2009-2010 Hideo NAKAMURA. See LICENSE for details.

License

same as Ruby.

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

About

ruby gem for Write to a cross-platform Excel binary file.

Resources

Stars

Watchers

Forks

Packages

No packages published