Re: spreadsheet 0.6.8 - undefined method `read' for false:FalseClass (NoMethodError)

425 views
Skip to first unread message

Zeno Davatz

unread,
Mar 27, 2012, 1:47:29 AM3/27/12
to Sergueï Cambour, spreadsheet
Dear Sergueï

This is good to know.

Please also join the list, see CC.

Best
Zeno

On Mon, Mar 26, 2012 at 9:18 PM, Sergueï Cambour <s.ca...@gmail.com> wrote:
> I've just tried the following code on my Ubuntu laptop searching the file
> locally and it worked:
>
> # coding: utf-8
> require 'spreadsheet'
>
> folder = '/home/serge/Development/Ruby/xls_files'
> pattern = "olé_*.xls"
>
> Dir.chdir(folder)
> source_files = Dir.glob(pattern)
> puts "source files: #{source_files.inspect}"
> recent_file = source_files.max_by { |f1| File.mtime(f1) }
>
> Spreadsheet.client_encoding = 'UTF-8'
> Spreadsheet.open(recent_file) do |book|
>   puts "sheets: #{book.worksheets.size}"
>   sheet = book.worksheet(0)
>   puts "First sheet name: #{sheet.name}"
> end
>
>
> I'll try tomorrow on Windows locally as well and let you know.
>
> On 26 March 2012 18:07, Zeno Davatz <zda...@gmail.com> wrote:
>>
>> This seems to be some network setup problem on Windows.
>>
>> From where do you pass the file name?  Across the LAN?
>>
>> Best
>> Zeno
>>
>> Am 26.03.2012 um 17:46 schrieb Sergueï Cambour <s.ca...@gmail.com>:
>>
>> Hi and sorry for disturbing you, guys!
>>
>> I have a strange behavior of the spreadsheet gem on Windows box and
>> unfortunately can't figure out why.
>> When I run 2 almost identical code blocks to read an Excel file on the LAN
>> server, it worls fine when I pass the file name directly like this:
>>
>> #encoding: utf-8
>> require 'spreadsheet'
>>
>> folder = "\\\\server100\\1\\Folder2\\Folder3"
>> file = folder << "\\" << "olé-olé-my_file.xls"
>>
>> Spreadsheet.client_encoding = 'UTF-8'
>> Spreadsheet.open(file) do |book|
>>   puts "sheets: #{book.worksheets.size}"
>>   sheet = book.worksheet(0)
>>   puts "First sheet name: #{sheet.name}"
>> end
>>
>> Now if I search for the most recent file in the same folder and pass its
>> name to the Spreadsheet like this, I get an error:
>>
>> #encoding: utf-8
>> require 'spreadsheet'
>>
>> folder = "\\\\server100\\1\\Folder2\\Folder3"
>> pattern = "olé-olé-*.xls"
>>
>> Dir.chdir(folder)
>> source_files = Dir.glob(pattern)
>> recent_file = source_files.max_by { |f1| File.mtime(f1) }
>> file = folder << "\\" << recent_file
>>
>> Spreadsheet.client_encoding = 'UTF-8'
>> Spreadsheet.open(file) do |book|
>>   puts "sheets: #{book.worksheets.size}"
>>   sheet = book.worksheet(0)
>>   puts "First sheet name: #{sheet.name}"
>> end
>>
>> The error stack trace:
>>
>>
>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.6.8/lib/spreadsheet/excel/reader.rb:1172:in
>> `setup': undefined method `read' for false:FalseClass (NoMeth
>> odError)
>>         from
>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.6.8/lib/spreadsheet/excel/reader.rb:121:in
>> `read'
>>         from
>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.6.8/lib/spreadsheet/excel/workbook.rb:32:in
>> `open'
>>         from
>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.6.8/lib/spreadsheet.rb:62:in
>> `open'
>>         from
>> C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.6.8/lib/spreadsheet.rb:68:in
>> `open'
>>
>> What am I doing wrong?
>> thank you in advance for your help.
>>
>> Best regards,
>>
>> SergueiCambour
>>
>

Javix

unread,
Mar 27, 2012, 3:32:34 AM3/27/12
to rubyspr...@googlegroups.com, Sergueï Cambour
As promised, I tried the same code but adapted to my Windows PC, just copied the needed files to find from a network folder to a folder:

folder = "C:\\Documents and Settings\\user_name\\Mes documents\\xls_files"

The rest of the code was left the same.


Dir.chdir(folder)     
source_files = Dir.glob(pattern)       

recent_file = source_files.max_by { |f1| File.mtime(f1) }

puts "file inspect: #{recent_file.inspect}"

if File.exists?(recent_file)
  puts "exists: #{File.stat(recent_file).
mtime}, readable: #{File.readable?(recent_file)}"
else
  puts "not"
end


Spreadsheet.client_encoding = 'UTF-8'
Spreadsheet.open(recent_file) do |book|

  puts "sheets: #{book.worksheets.size}"
  sheet = book.worksheet(0)   
  puts "First sheet name: #{sheet.name}"
end

And it works as needed....:

result:

file inspect: "olé-20120223-V01.00.xls"
exists: 2012-03-23 16:18:06 +0100, readable: true
sheets: 5
First sheet name: Données


Strange enough, when pointing the code to the network folder, it still generates the error:


C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.6.8/lib/spreadsheet/excel/reader.rb:1172:in `setup': undefined method `read' for false:FalseClass (NoMethodError)
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.6.8/lib/spreadsheet/excel/reader.rb:121:in `read'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.6.8/lib/spreadsheet/excel/workbook.rb:32:in `open'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.6.8/lib/spreadsheet.rb:62:in `open'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.6.8/lib/spreadsheet.rb:65:in `block in open'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.6.8/lib/spreadsheet.rb:64:in `open'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.6.8/lib/spreadsheet.rb:64:in `open'

Zeno Davatz

unread,
Mar 27, 2012, 3:44:31 AM3/27/12
to spreadsheet
Dear Serguei

This seems to be a windows Problem. Please contact Luis Lavena about
this issues. He is very knowledgeable about Ruby and Windows as he
does the RubyInstaller for Windows. He has list. Post to that list and
he will reply.

If it works on Linux it works for me.

Best
Zeno

On Tue, Mar 27, 2012 at 9:28 AM, Sergueï Cambour <s.ca...@gmail.com> wrote:
> As promised, I tried the same code but adapted to my Windows PC, just copied
> the needed files to find from a network folder to a folder:
>
> folder = "C:\\Documents and Settings\\user_name\\Mes documents\\xls_files"
>
> The rest of the code was left the same.
>

> Dir.chdir(folder)
> source_files = Dir.glob(pattern)
>
> recent_file = source_files.max_by { |f1| File.mtime(f1) }
>

> puts "file inspect: #{recent_file.inspect}"
>
> if File.exists?(recent_file)

>   puts "exists: #{File.stat(recent_file).mtime}, readable:


> #{File.readable?(recent_file)}"
> else
>   puts "not"
> end
>

> Spreadsheet.client_encoding = 'UTF-8'
> Spreadsheet.open(recent_file) do |book|
>
>   puts "sheets: #{book.worksheets.size}"
>   sheet = book.worksheet(0)
>   puts "First sheet name: #{sheet.name}"
> end
>

> And it works as needed....:
>
> result:
>
> file inspect: "olé-20120223-V01.00.xls"
> exists: 2012-03-23 16:18:06 +0100, readable: true
> sheets: 5
> First sheet name: Données
>
>
> Strange enough, when pointing the code to the network folder, it still
> generates the error:
>

> C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.6.8/lib/spreadsheet/excel/reader.rb:1172:in
> `setup': undefined method `read' for false:FalseClass (NoMethodError)
>     from
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.6.8/lib/spreadsheet/excel/reader.rb:121:in
> `read'
>     from
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.6.8/lib/spreadsheet/excel/workbook.rb:32:in
> `open'
>     from
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.6.8/lib/spreadsheet.rb:62:in
> `open'
>     from

> C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.6.8/lib/spreadsheet.rb:65:in
> `block in open'
>     from
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.6.8/lib/spreadsheet.rb:64:in
> `open'
>     from
> C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.6.8/lib/spreadsheet.rb:64:in
> `open'
>
>
> Serguei

Sergueï Cambour

unread,
Mar 27, 2012, 3:51:16 AM3/27/12
to rubyspr...@googlegroups.com
OK, I forwarded the issue to him and I'll come back as son as I get some news from him.

Regards,

Serguei

Zeno Davatz

unread,
Mar 27, 2012, 4:02:43 AM3/27/12
to rubyspr...@googlegroups.com
Dear Sergei

On Tue, Mar 27, 2012 at 9:51 AM, Sergueï Cambour <s.ca...@gmail.com> wrote:
> OK, I forwarded the issue to him and I'll come back as son as I get some
> news from him.

Excellent! Make sure to post to his list not to his personal email.

Best
Zeno

Javix

unread,
Mar 27, 2012, 5:28:41 AM3/27/12
to rubyspr...@googlegroups.com, Sergueï Cambour
I just commented the rescue clause  at line 1170 in spreadsheet/exce/reader.rb file to get more details on what is going on behind the scenes and discovered that it is linked somehow to ruby-ole gem:

path in open: "Book"
C:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby-ole-1.2.11.3/lib/ole/storage/file_system.rb:132:in `dirent_from_path': No such file or directory - Book (Errno::ENOENT)
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/ruby-ole-1.2.11.3/lib/ole/storage/file_system.rb:166:in `open'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.6.8/lib/spreadsheet/excel/reader.rb:1170:in `block in setup'

The value 'Book' as path is coming from the declared array at line 1169 in reader.rb file.




On Tuesday, March 27, 2012 7:47:29 AM UTC+2, Zeno R.R. Davatz wrote:

Javix

unread,
Mar 27, 2012, 6:03:35 AM3/27/12
to rubyspr...@googlegroups.com, Sergueï Cambour
One more interesting thing.

Given a code you already know:


# coding: utf-8
require 'spreadsheet'

folder = "\\\\server100\\1\\Folder2\\Folder3"

file = "\\\\server100\\1\\Folder2\\Folder3\\olé_file1.xls"

#Spreadsheet.client_encoding = 'UTF-8' # I think there is no need set it to UTF-8 here as it was done by default at line 51 in spreadsheet.rb file


  Spreadsheet.open(file) do |book|
   puts "sheets: #{book.worksheets.size}"
   sheet = book.worksheet(0)
   puts "First sheet name: #{sheet.name}"
end


The above code will work without any problem.

And now if you add:

Dir.chdir(folder)

And you will get the 'desired' error:


C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.6.8/lib/spreadsheet/excel/reader.rb:1172:in `setup': undefined method `read' for false:FalseClass (NoMethodError)
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.6.8/lib/spreadsheet/excel/reader.rb:121:in `read'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.6.8/lib/spreadsheet/excel/workbook.rb:32:in `open'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.6.8/lib/spreadsheet.rb:62:in `open'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.6.8/lib/spreadsheet.rb:65:in `block in open'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.6.8/lib/spreadsheet.rb:64:in `open'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.6.8/lib/spreadsheet.rb:64:in `open'


On Tuesday, March 27, 2012 7:47:29 AM UTC+2, Zeno R.R. Davatz wrote:

Javix

unread,
Mar 27, 2012, 8:10:30 AM3/27/12
to rubyspr...@googlegroups.com, Sergueï Cambour
The solution I found is to pass a block to Dir.chdir instead:

folder = "\\\\server100\\Folder1\\Folder2\\Folder3"
recent_file = nil
Dir.chdir(folder) do
  pattern = 'olé_*.xls'

  source_files = Dir.glob(pattern)       
  recent_file = source_files.max_by { |f1| File.mtime(f1) }
end

Spreadsheet.open(File.join(folder, recent_file)) do |book|

  puts "sheets: #{book.worksheets.size}"
  sheet = book.worksheet(0)   
  puts "First sheet name: #{sheet.name}"
end

Like that, If a block is given, it is passed the name of the new current directory, and the block is
executed with that as the current directory. The original working directory is restored when
the block exits. The return value of chdir is the value of the block.


Hope we can close the issue if you find it to be correct.

On Tuesday, March 27, 2012 7:47:29 AM UTC+2, Zeno R.R. Davatz wrote:

Zeno Davatz

unread,
Mar 27, 2012, 8:50:33 AM3/27/12
to rubyspr...@googlegroups.com
Dear Sergei

If this works on Windows for you I am more then happy to close the issue.

If you could wrap this up in your Github account that would be great.

Best
Zeno

Javix

unread,
Mar 27, 2012, 9:09:57 AM3/27/12
to rubyspr...@googlegroups.com, Sergueï Cambour
I created a Gist explaining the solution at: https://gist.github.com/2215617

Best regards,

Serguei


On Tuesday, March 27, 2012 7:47:29 AM UTC+2, Zeno R.R. Davatz wrote:

Zeno Davatz

unread,
Mar 27, 2012, 9:58:45 AM3/27/12
to rubyspr...@googlegroups.com
Dear Serguei

On Tue, Mar 27, 2012 at 3:09 PM, Javix <s.ca...@gmail.com> wrote:
> I created a Gist explaining the solution at: https://gist.github.com/2215617

Awesome, thank you! Did you hear back from Luis Lavena? I am curious
to know what he said about your solution. Did you send him your
solution as well?

Best
Zeno

Sergueï Cambour

unread,
Mar 27, 2012, 10:01:07 AM3/27/12
to rubyspr...@googlegroups.com
You are welcome.
Yes, I posted the same description at Rubyinstaller group as he asked and the link to our discussion thread.
No news from him for the moment.

Regards,

Serguei

Nataly®

unread,
Oct 25, 2012, 4:42:41 AM10/25/12
to rubyspr...@googlegroups.com
Digging this subject up because i'm just having this error.
I'm on Mac Os and everything was fine until i updated my project (i'm working with RubyMine) with the code of my work mate and since i have this error.
It is surely a conflict with something from his code but i don't know what.
Any ideas?

Nataly®

unread,
Oct 25, 2012, 4:48:43 AM10/25/12
to rubyspr...@googlegroups.com
Here how i call the spreadsheet open method on which line is the error :
 
<% Spreadsheet.open USERS_LIST_FILE do |excel_users_file|%>

I tried replacing the constant by its value (the file and its path) but nothing change.
I tried too to use the File.ope method before calling the Spreadsheet.open but still the same.

Nataly®

unread,
Oct 25, 2012, 5:07:36 AM10/25/12
to rubyspr...@googlegroups.com
Ok found the problem : it is the file, it is corrupted.
Sorry for the bother (again...).

Zeno Davatz

unread,
Oct 25, 2012, 5:56:30 AM10/25/12
to rubyspr...@googlegroups.com
Dear Nataly

On Thu, Oct 25, 2012 at 11:07 AM, Nataly® <nataly...@gmail.com> wrote:
> Ok found the problem : it is the file, it is corrupted.
> Sorry for the bother (again...).

Why don't you summarize your issue on your github page so others can
profit as well.

Best
Zeno

Nataly®

unread,
Oct 26, 2012, 4:58:33 AM10/26/12
to rubyspr...@googlegroups.com
i'll try to find how to do that, if this can help other people.

Reply all
Reply to author
Forward
0 new messages