GithubHelp home page GithubHelp logo

cxn03651 / writeexcel Goto Github PK

View Code? Open in Web Editor NEW
274.0 9.0 49.0 3.03 MB

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

Home Page: http://wiki.github.com/cxn03651/writeexcel/

License: MIT License

Ruby 81.16% CSS 0.41% HTML 18.15% Yacc 0.28%

writeexcel's Introduction

writeexcel

Write to a cross-platform Excel binary file.

<img src=“https://badge.fury.io/rb/writeexcel.png” alt=“Gem Version” /> <img src=“https://travis-ci.org/cxn03651/writeexcel.svg?branch=master” alt=“Build Status” />

Description

This library is converted from Spreadsheet::WriteExcel module of Perl. search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel-2.38/

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 OpenOffice.org.

This module cannot be used to read an Excel file.

Installation

Add this line to your application’s Gemfile:

gem 'writeexcel'

And then execute:

$ bundle

Or install it yourself as:

$ gem install writeexcel

Usage

See Reference writeexcel.web.fc2.com/ . 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 = 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 .…..

Recent Change

v1.0.9

  • Fixed a bug: Can’t modify frozen String (RuntimeError)

v1.0.8

  • add nkf gem as runtime dependent gem for future Ruby 3.4.

v1.0.7

  • support Ruby 3.3

  • support Ruby 2.4 or later

v1.0.6

  • support Ruby 3.2

  • use minitest gem instead of test-unit.

v1.0.5

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

v1.0.4

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

v1.0.3

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

v1.0.2

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

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

v1.0.1

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

v1.0.0

  • Bug fix in Workbook#set_properties.

Author

Original was written in Perl by John McNamara ([email protected]).

Convert to ruby by Hideo Nakamura ([email protected]) Copyright © 2009-2024 Hideo NAKAMURA. See LICENSE.txt for details.

License

See LICENSE.txt

Contributing

  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

writeexcel's People

Contributors

almathie avatar cxn03651 avatar jlw avatar kevbob1 avatar m-larin avatar mathieujobin avatar maximerety avatar murbanski avatar rolfb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

writeexcel's Issues

writeexcel v0.5.0 breaks .to_json in rails 3.0.1

Hi!

Adding writeexcel gem dependence brakes up .to_json method.

To reproduce:

  1. Add 'writeexcel' dependence
  2. try to run function like "fo".to_json or {'foo' => 'bar'}.to_json

It results a error:
ArgumentError: wrong number of arguments (2 for 1)
from /usr/lib/ruby/gems/1.8/testadmin/ruby/1.8/gems/activesupport-3.0.1/lib/active_support/json/encoding.rb:106:in encode' from /usr/lib/ruby/gems/1.8/testadmin/ruby/1.8/gems/activesupport-3.0.1/lib/active_support/json/encoding.rb:106:inescape'
from /usr/lib/ruby/gems/1.8/testadmin/ruby/1.8/gems/activesupport-3.0.1/lib/active_support/json/encoding.rb:51:in `escape'
...

.to_json works correctly when 'writeexcel' dependence is removed.

write_formula fails when references are not in sheet order

Both example should give identical results, but in the second one, the sheets references are swapped...

require 'rubygems'
require 'writeexcel'


# Working example
workbook = WriteExcel.new('test-working.xls')

worksheet = workbook.add_worksheet("First")
worksheet.write(0, 0, 1)

worksheet = workbook.add_worksheet("Second")
worksheet.write(0, 0, 2)

worksheet = workbook.add_worksheet("Third")
worksheet.write(0, 0, "First :")
worksheet.write_formula(0, 1, %q{='First'!A1})
worksheet.write(1, 0, "Second :")
worksheet.write_formula(1, 1, %q{='Second'!A1})

workbook.close



# Failing example
workbook = WriteExcel.new('test-failing.xls')

worksheet = workbook.add_worksheet("Second")
worksheet.write(0, 0, 2)

worksheet = workbook.add_worksheet("First")
worksheet.write(0, 0, 1)

worksheet = workbook.add_worksheet("Third")
worksheet.write(0, 0, "First :")
worksheet.write_formula(0, 1, %q{='First'!A1})
worksheet.write(1, 0, "Second :")
worksheet.write_formula(1, 1, %q{='Second'!A1})


workbook.close

Excel found unreadable content in 'file.xls'.Do you want to recover the contents of this workbook

Hi,

I'm getting this error from Excel 2010 on simple xls file with 10000 rows and 20 columns without formatting or formulas. It is rather hard to get which row or cell leads to such error. Because after removing 1000 rows excel opens file without issues(with 90000 rows) and file with those 1000 rows excel able to open as well. Do you have any idea how to fix this issue?

ruby 1.9.3p545
magic utf8 comment were added to each source file
i'm using just write_row and put force_encoding("UTF-8") to any row field

Thanks.

Hyperlinks do not work in Google Spreadsheet or Apple Numbers

In Numbers, it looks like only the first hyperlink of the document will work. In Google Spreadsheet, no hyperlinks work. And it's fine in Excel.

I tried using the HYPERLINK formula instead but it doesn't look like it's supported by this gem.

I am not familiar with the Excel binary format but links are working with all platform using the Spreadsheet gem so I guess it's fixable.

Strange error - Racc::ParseError

I want to write 1537 rows into file and get this error:

parse error on value "=" ("=")
racc/parser.rb:350:in `on_error'

Backtrace
racc/parser.rb:350:in on_error' racc/parser.rb:99:in_racc_do_parse_c'
racc/parser.rb:99:in __send__' racc/parser.rb:99:in do_parse'
[RAILS_ROOT]/vendor/plugins/writeexcel/lib/writeexcel/formula.rb:206:inparse' [RAILS_ROOT]/vendor/plugins/writeexcel/lib/writeexcel/formula.rb:40:in parse_formula'
[RAILS_ROOT]/vendor/plugins/writeexcel/lib/writeexcel/worksheet.rb:2844:inwrite_formula' [RAILS_ROOT]/vendor/plugins/writeexcel/lib/writeexcel/worksheet.rb:2247:in write'
[RAILS_ROOT]/lib/to_xls.rb:22:increate' [RAILS_ROOT]/vendor/plugins/writeexcel/lib/writeexcel/format.rb:1278:in each_with_index'
[RAILS_ROOT]/lib/to_xls.rb:21:ineach' [RAILS_ROOT]/lib/to_xls.rb:21:in each_with_index'
[RAILS_ROOT]/lib/to_xls.rb:21:increate' [RAILS_ROOT]/vendor/plugins/writeexcel/lib/writeexcel/format.rb:1278:in each_with_index'
[RAILS_ROOT]/lib/to_xls.rb:20:ineach' [RAILS_ROOT]/lib/to_xls.rb:20:in each_with_index'
[RAILS_ROOT]/lib/to_xls.rb:20:increate' [RAILS_ROOT]/app/models/questionnare/questionnare.rb:59:in to_xls'

What does it meen? Maybe I want to write some data that cannot parse?
How can I fix this?
Tnx.

Data may have lost error

Excel generated on ubuntu is ok but on windows it is showing data may have lost so i used compatibility mode now it is showing blank cells but on click on blank cell showing data on formula bar

write_xlsx BUGS

error027240_01.xml

在文件“C:\Users\Administrator\AppData\Local\Microsoft\Windows\INetCache\Content.Outlook\FJJN2SHK\网络-网络设备巡检报告-2021-08-04.xlsx”中检测到错误已修复的记录: /xl/worksheets/sheet1.xml 部分的 单元格信息

UTF-8 Arbitrarily converted to UTF-16LE or UTF-16BE

I was patching a fork of the roo gem to fix several xls parsing error and I ran into this weird state, where the characters are encoded in a different format than expected when loading files generated by this gem. I traced it down to write_string and found this nugget:

    # Handle utf8 strings
    if is_utf8?(str)
      str_utf16le = utf8_to_16le(str)
      return write_utf16le_string(row, col, str_utf16le, args[3])
    end

This causes some cells to be arbitrarily encoded in UTF-16LE, which gets loaded as UTF-8 by the spreadsheet gem. I noticed the same conversion, but to UTF-16BE in chart axis saving. --don't mix the streams--

Then I went to read the write_utf16le_string method to see if it was doing something odd. I did not expect it to convert the string again, but here it calls utf16be_to_16le on an already encoded utf-16le string.

  def write_utf16le_string(*args)
    # Check for a cell reference in A1 notation and substitute row and column
    args = row_col_notation(args)

    return -1 if (args.size < 3)                  # Check the number of args

    row, col, str, format = args

    # Change from UTF16 big-endian to little endian
    str = utf16be_to_16le(str)

    write_utf16be_string(row, col, str, format)
  end

Which in turn doesn't even use encoding but instead unpacks and repacks the string.

  def utf16be_to_16le(utf16be)
    utf16be.unpack('n*').pack('v*')
  end

And then the write_utf16be_string at the end of write_utf16le_string itself calls utf16be_to_16le to convert it back to 16le. At this point I starting losing track of be's and le's in trying to figure out what the actual encoding becomes.

def utf16be_to_16le(...)
    ...
    # Change from UTF16 big-endian to little endian
    str = utf16be_to_16le(str)

WHY does it do this??? Is it a mistake, or something to appease an older version of excel? There's 3 levels of arbitrary re-encoding for utf-8 without clarifying comments and it clearly produces an output that other readers can't correctly interpret and which differs from excel 2010's xls outputs.

Using autofilter and "D1" as worksheet name generates exception

Using "D1" or any uppercase letter followed by a number together with autofilter generates an exception. Lowercase initial letter is instead ok. Try this simple test code:

require 'rubygems'
require 'writeexcel'
workbook = WriteExcel.new(open('test.xls', 'w'))
worksheet = workbook.add_worksheet('D1')
worksheet.autofilter(0, 0, 0, 10)
workbook.close

I get:

Racc::ParseError:
parse error on value "!" (error)
from /home/drsound/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/racc/parser.rb:350:in on_error' from /home/drsound/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/racc/parser.rb:99:in_racc_do_parse_c'
from /home/drsound/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/racc/parser.rb:99:in __send__' from /home/drsound/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/racc/parser.rb:99:in do_parse'
from /home/drsound/.rvm/gems/ruby-1.8.7-p352/gems/writeexcel-0.6.8/lib/writeexcel/formula.rb:206:inparse' from /home/drsound/.rvm/gems/ruby-1.8.7-p352/gems/writeexcel-0.6.8/lib/writeexcel/formula.rb:40:in parse_formula'
from /home/drsound/.rvm/gems/ruby-1.8.7-p352/gems/writeexcel-0.6.8/lib/writeexcel/worksheet.rb:2952:instore_formula' from /home/drsound/.rvm/gems/ruby-1.8.7-p352/gems/writeexcel-0.6.8/lib/writeexcel/worksheet.rb:7237:in store_filters'
from /home/drsound/.rvm/gems/ruby-1.8.7-p352/gems/writeexcel-0.6.8/lib/writeexcel/worksheet.rb:264:inclose' from /home/drsound/.rvm/gems/ruby-1.8.7-p352/gems/writeexcel-0.6.8/lib/writeexcel/workbook.rb:1284:in calc_sheet_offsets'
from /home/drsound/.rvm/gems/ruby-1.8.7-p352/gems/writeexcel-0.6.8/lib/writeexcel/workbook.rb:1282:ineach' from /home/drsound/.rvm/gems/ruby-1.8.7-p352/gems/writeexcel-0.6.8/lib/writeexcel/workbook.rb:1282:in calc_sheet_offsets'
from /home/drsound/.rvm/gems/ruby-1.8.7-p352/gems/writeexcel-0.6.8/lib/writeexcel/workbook.rb:1143:instore_workbook' from /home/drsound/.rvm/gems/ruby-1.8.7-p352/gems/writeexcel-0.6.8/lib/writeexcel/workbook.rb:152:in close'
from (irb):136

Insert multiple images in one cell

This is very much an edge case. However I have some Perl that did this using insert_bitmap before insert_image was added to the Ruby version. rebuilding now in ruby I get either a hang or no additional images in the cell.

here is some example code

x = 9
y = 5
worksheet1.set_row(0, 200)
worksheet1.insert_image('A1', File.join(File.dirname(File.expand_path(FILE)), 'conductor_watercourse.png'), x, y)
worksheet1.write('B1', "1")
worksheet1.insert_image('A1', File.join(File.dirname(File.expand_path(FILE)), 'conductor_watercourse.png'), x, 25)
worksheet1.write('B1', "2")
worksheet1.insert_image('A1', File.join(File.dirname(File.expand_path(FILE)), 'conductor_watercourse.png'), x, 45)
worksheet1.write('B1', "3")

in Perl i simply added to the y axis before writing the image

Any ideas where I am going wrong.

Cheers
Steven

name PI is not known in formula

writeexcel/formula.rb:515:in `get_name_index': Unknown defined name PI in formula (RuntimeError)

This happens when I try to do things like:

worksheet.write('A4', '=SIN(PI/4)')

Write `=` into a cell

I had a problem where a user submitted multiple = in a text field and exporting the data failed with

parse error on value "=" ("=")
/home/ubuntu/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/racc/parser.rb:351:in `on_error'
(eval):3:in `_racc_do_parse_c'
(eval):3:in `do_parse'

Is there any way to treat data always as string and skipping the formula parsing?

set_row breaks merge_range

If you have multiple merge_range functions in your code and you try to set the height of ANY row using set_row only the first merge_range works properly. All others merge the needed cells but do not write text in them.
Example code to reproduce bug:

require 'rubygems'
require 'writeexcel'

workbook = WriteExcel.new('test.xls')

worksheet = workbook.add_worksheet('worksheet')
heading = workbook.add_format(
:align => 'center',
:size => 12,
:bold => 1
)
subHeading = workbook.add_format(
:align => 'center',
:size => 12
)

worksheet.merge_range('A2:H2', 'first row', heading)
worksheet.merge_range('A3:H3', 'Second row', subHeading) # text isn't visible. if you comment out set_row it will be visible again
worksheet.set_row(3, 30)

workbook.close()

Namespace collisions

This gem defines commonly used class names like Format, Chart, Colors, etc. In an application of any significant size, including this gem will cause conflicts with existing code. Any way these could be namespaced better?

Make block format possible for workbook.close

Hi.

workbook = WriteExcel.new('ruby.xls') # Step 1
worksheet = workbook.add_worksheet # Step 2
worksheet.write('A1', 'Hi Excel!') # Step 3
workbook.close

I believe the .close could be eliminated, just as
it is possible in

File.open() {

}

Simply use a block style, like so:

WriteExcel.new('ruby.xls') { # Step 1
worksheet = add_worksheet # Step 2
worksheet.write('A1', 'Hi Excel!') # Step 3
}

writeexcel v0.6 breaks email sending in Rails 3 encoding issue

Hi!

It seems that writeexcel beaks e-mail sending in Rails 3 (tested in 3.0.1, ruby 1.8.7). Header (from, to) fields are forced to use UTF8 encoding that results error on sending (unknown sender/receiver domain/address).

Without this gem ActionMailer gives something like

mail = MyMailer.notice
=> #<Mail::Message:-618977088, Multipart: true, Headers: <From: [email protected]>, <To: [email protected]>, <Subject: Notice>, <Mime-Version: 1.0>, 
<Content-Type: multipart/alternative; boundary="--==_mimepart_4cf6e4dde3fc0_2899241d3726737ce"; charset=UTF-8>>
mail.from
=> ["[email protected]"]
mail.to
=> ["[email protected]"]

When writeexcel is enabled then
mail = MyMailer.notice
=> #<Mail::Message:-620247058, Multipart: true, Headers: <From: [email protected]>, <To: [email protected]>, <Subject: Notice>, <Mime-Version: 1.0>,
<Content-Type: multipart/alternative; boundary=utf8'en'--==_mimepart_4cf6e20aace22_27cc241c8722624c2; charset=utf8'en'UTF-8>>
mail.to
=> ["=?UTF-8?B?IHRlc3RAdGVzdC5lZQ==?="]
mail.from
=> ["=?UTF-8?B?IHRlc3RAdGVzdC5lZQ==?="]

Notice changes in :from and :to outputs and :charset.

The last one causes error on sending (Gmail example)
mail.deliver
=> Net::SMTPFatalError: 553-5.1.2 We weren't able to find the recipient domain. Please check for any
from /usr/lib/ruby/1.8/net/smtp.rb:930:in `check_response'

NoMethodError

I've got a NoMethodError in controller:

undefined method `write' for #<Pathname:0x00000005ad3bf8>

Action:

workbook = WriteExcel.new(path)
xls = workbook.add_worksheet
row = 1
orders.each do |c|
  xls.write(row, 0, c.id.to_s)
  xls.write(row, 1, c.code.to_s)
  row += 1
end
workbook.close

Racc::ParseError

parse error on value ":" (error)
from /usr/local/lib/ruby/2.1.0/racc/parser.rb:529:in on_error' from /usr/local/lib/ruby/2.1.0/racc/parser.rb:258:in_racc_do_parse_c'
from /usr/local/lib/ruby/2.1.0/racc/parser.rb:258:in `do_parse'

on a line of code like:
worksheet.write(row_index, col_index, col_value.to_s)

where col_value is a String similar to

word : word : word\nword : ....

Validation list with more than 255 chars

I'm trying to create a data_validation list from an array with 10 elements.

I'm getting this error :

TypeError - can't convert String into Integer:
  writeexcel (1.0.4) lib/writeexcel/formula.rb:302:in `convert_string'
  writeexcel (1.0.4) lib/writeexcel/formula.rb:101:in `parse_tokens'
  writeexcel (1.0.4) lib/writeexcel/formula.rb:52:in `parse_formula'
  writeexcel (1.0.4) lib/writeexcel/data_validations.rb:278:in `pack_dv_formula'
  writeexcel (1.0.4) lib/writeexcel/data_validations.rb:120:in `dv_record'
...

This test throught the error at line 302 of formula.rb :

 exit "String in formula has more than 255 chars\n" if length > 255

Concatenation of my 10 array elements gave a string of more than 255 length chars.

method `store_formula' shouldn't be private

in 0.6.11 the store_formula method gives the error:
testExcel.rb:21:in <main>': private methodstore_formula' called for #Writeexcel::Worksheet:0x13a1840 (NoMethodError)

reverting back to 0.6.9 fixed the issue.

Setting properties on a worksheet corrupts the file in 1.9.3-p327

Weird bug, seems like the gem works just fine in 1.9, until you set a property (like company or whatnot) .. this somehow causes the whole file to get corrupted and unreadable.

Sorry I can't really give you any real useful tests here .. all the hex stuff in your test suite is basically useless unless you intimately understand the XLS format itself ...

My basic repro for this is ..

  1. use 1.9.3
  2. generate a workbook+worksheet
  3. set a property (like :company => "test company")
  4. close the workbook

Now try to open the generated file (I've used the roo gem to attempt to open it as my unit test for this, if it crashes .. its corrupt, if it does not its ok)

On 1.8.7 its ok, on 1.9.3 it is not ..

Gridlines only hide in two first worksheets

Take the following example:

require 'writeexcel'

io = File.open('gridlines-worksheets.xls', 'w')
book = WriteExcel.new(io)
s1 = book.add_worksheet('Foo')
s2 = book.add_worksheet('Bar')
s3 = book.add_worksheet('Baz')

s1.hide_gridlines(2)
s2.hide_gridlines(2)
s3.hide_gridlines(2)

book.close

The gridlines are only hidden in the first two worksheets. They remain visible on the third worksheet, despite the call to hide_gridlines. Result is similar when more worksheets are present: only the first two hide their gridlines.

Character range encodin issues for ruby > 1.8.7

HI,

in one of the our projects we use Writeexcel and I think is great.
One problem what we found so far is encoding issues with some of the characters
« » ² ³ µ ¶
We think because they belongs to totally different characters range..Please take a look:
https://en.wikipedia.org/wiki/Unicode_subscripts_and_superscripts#Superscripts_and_subscripts_block
When we generate excel file, the characters either missing or we got ??????...

In all our files we have ruby encoding flag:
# coding: UTF-8

Any help or idea how we can fix this it would be great...

Regards,
Aleksandar

Labelling a sheet

I'm not sure if this is currently implemented and not documented, or if it's not currently implemented, but I'd like to be able to change the name of sheets. I have a script to generate a report of EBS volumes against a given AWS account, with different sheets for each supported AWS region. I'd like to be able to rename Sheet 1 to us-east-1, Sheet 2 to us-west-2, Sheet 3 to eu-west-1, etc.

Please consider adding nkf as a dependency for this project to support Ruby 3.4.0

This is what I get when using this gem on Ruby 3.3.0:

/Users/rodrigo.rosas/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/writeexcel-1.0.5/lib/writeexcel/workbook.rb:14: warning: nkf was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.4.0. Add nkf to your Gemfile or gemspec. Also contact author of writeexcel-1.0.5 to add nkf into its gemspec.

Thanks in advance.

Private attributes in workbook.rb

In version 0.6.5 of the writeexcel gem, I'm getting the following warnings:

lib/writeexcel/workbook.rb:35: warning: private attribute?
lib/writeexcel/workbook.rb:36: warning: private attribute?

Is this intentional?

Exceptions using writeexcel 0.6.0 with rails 2.3.8

Lots of exceptions are generated using writeexcel 0.6.0 with rails 2.3.8. Here is a test case for rails 2.3.8:

  1. create a fresh rails application with "rails my_test_app"
  2. add writeexcel gem to config/environment.rb
  3. enter rails console with 'script/console'
  4. use these simple instructions:
    a) workbook = WriteExcel.new('/tmp/test.xls')
    b) worksheet = workbook.add_worksheet
    c) worksheet.write(0, 0, 'test')
  5. You get the first exception
    --- EXCEPTION BEGIN ---

append
/usr/lib/ruby/gems/1.8/gems/writeexcel-0.6.0/lib/writeexcel/worksheet.rb:2756 in store_with_compatibility
/usr/lib/ruby/gems/1.8/gems/writeexcel-0.6.0/lib/writeexcel/worksheet.rb:2747 in write_string
/usr/lib/ruby/gems/1.8/gems/writeexcel-0.6.0/lib/writeexcel/worksheet.rb:2584 in write
/home/drsound/scambio/test/writeexcel_test2/(irb):4 in irb_binding
/usr/lib/ruby/1.8/irb/workspace.rb:52 in irb_binding
FD 00 0A 00 00 00 00 00 0F 00 00 00 00 00

=> 0

--- EXCEPTION END ---

  1. If you try "workbook.close", you will get one million exceptions more!

No problems at all if I use the same instructions within rails 3.0.1 or a plain ruby program.

bug in write_comment

I'm trying to create an excel file with a lot of comments and I've noticed that, when I put more than one note per row, only the last one is created.

require 'rubygems'
require 'writeexcel'

workbook  = WriteExcel.new("comments0.xls")
worksheet = workbook.add_worksheet

worksheet.write(0, 0, 'Hello a1')
worksheet.write(0, 1, 'Hello b1')
worksheet.write(1, 0, 'Hello a2')
worksheet.write(1, 1, 'Hello b2')

worksheet.write_comment('A1', 'This is a comment a1', :author=>'arr')
worksheet.write_comment('A2', 'This is a comment a2', :author=>'arr')
worksheet.write_comment('B1', 'This is a comment b1', :author=>'arr')
worksheet.write_comment('B2', 'This is a comment b2', :author=>'arr')

workbook.close

As you can see I try to create one comment for each cell, but the resulting excel has only 2 comments on the last columns. (https://skitch.com/david.saitta/gkbbq/microsoft-excel)
It seems that the library consider only the last comment for row.

Thanks for your work!!!

compatibility_mode and 'data may have been lost'

Good day, i assume that writing some different data to the same cells will produce

 'data may have been lost'

while opening xls file.

Original perl module suggest to use compatibility_module which will use xls compatibility mode.
Never helps, anyway.

My question mostly about logic. If i need some area used as a square with borders, only way to achieve it to write format to all cells which are perimeter of that block. When it is done - all is good, file opens as expected, but when i try e.g. merge some cells within block it will produce above warning.

What i'm doing wrong ?

freeze_panes problem

Hello,
I came across a wierd problem using freeze_panes. I've observed that it does not get applied for third and later worksheets. simply:

wb = WriteExcel.new("test_freeze_panes.xls")
10.times{|i| ws = wb.add_worksheet("Pane #{i}"); ws.freeze_panes(2,0); }
wb.close

..and panes are freezed only in two first worksheets.
using :
-writeexcel both 1.0.0, 1.0.1
-ruby 1.9.3p385 (2013-02-06 revision 39114) [x86_64-linux]
-libreoffice for view the .xls

Could you make it work?

Issue with utf8 strings in num_format

This issue was raised on Stackoverflow.

The problem is in the store_num_format() method in the workbook.rb class. After converting the string to utf16 the character count should be reset:

...
# Handle utf8 strings
if is_utf8?(format)
  format = utf8_to_16be(format)
  encoding = 1
  cch = format.bytesize # Add this.
end
...

Chart does not render Data Lable

I made column chart , it's rendering perfect and work fine as i need. Now i want to put data label on chart so i can easily recognize value on column chart but i can't find any method for this. Can any one help me on this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.