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
>>
>
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
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
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)
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