uninitialized constant Spreadsheet::Link - roo gem - xlsx file - ruby-on-rails

When I open a file in xlsx format, using empact/roo gem, this line of code:
data = Roo::Spreadsheet.open("/Users/asd/Desktop/in_xlsx.xlsx", extensions: :xlsx)
or this line
data = Roo::Excelx.new("/Users/asd/Desktop/in_xlsx.xlsx")
works perfect! (at least this is what I think)
data is now a Roo::Excelx object with the columns and rows filled correctly.
But whenever I try to use a method like data.first_row or data.cell(1,1), I get this
NameError: uninitialized constant Spreadsheet::Link
from /Users/asd/.rvm/gems/ruby-2.0.0-p353#ch/gems/roo-1.13.2/lib/roo/excelx.rb:379:in `set_cell_values'
Additional info:
MacOS 10.9.1
Rails 4.0.2
Ruby 2.0.0-p353
Roo (1.13.2)
Any help is really appreciated!

Try this :
require 'rubygems'
require 'roo'
For more information http://roo.rubyforge.org/

Related

Rails 5 gem gon not recognize jbuilder file

I have implemented rails gem gon in index method and it works fine. But when I try to implement in controller#new it is not working this is my error output:
No such file or directory # rb_sysopen - app/views/cuenta_proveedors/new.json.jbuilder
but i have already create this file.
this is my controller
def new
#cuenta_proveedor = CuentaProveedor.new
#cuentas = #negocio.cuenta_proveedors.order(:created_at)
gon.jbuilder // THIS LINE CAUSE THE ERROR SHOWN BY APPLICATION TRACE
end
i have the created the file new.json.jbuiler
json.cuenta_proveedores #cuentas do |cc|
json.proveedor cc.proveedor.nombre
json.inicial cc.monto_inicial
json.saldo cc.monto_adeudado
json.observacion cc.observacion
json.token cc.token
end
Why is this happening? I can not found any logic to this error. If you need more information ask me . Thanks

Read GB2312 encoding page using Ruby

I am trying to parse GB2312 encoded page (http://news.qq.com/a/20140824/015032.htm), and this is my code.
I am not yet into the parsing part, just in the open and read, and I got error.
This is my code:
require 'open-uri'
open("http://news.qq.com/a/20140824/015032.htm").read
And this is the error:
Encoding::InvalidByteSequenceError: "\x8B" on GB2312
I am using Ruby 2.0.0p247
Any solution?
I don't know exactly why this happens when calling .read, but you can work around it if you are using Nokogiri. Just pass the file object directly to Nokogiri without calling .read:
require 'open-uri'
file = open("http://news.qq.com/a/20140824/015032.htm")
document = Nokogiri(file)
I cannot duplicate the error using 2.0.0p247,
require 'open-uri'
open("http://news.qq.com/a/20140824/015032.htm").read
Works fine.
However
require 'open-uri'
open("http://news.qq.com/a/20140824/015032.htm").read.encode('utf-8')
will raise the error
Encoding::InvalidByteSequenceError: "\x8B" on GB2312
Are you trying to do some encoding conversion?
you can try this
document = Nokogiri::HTML(open("http://news.qq.com/a/20140824/015032.htm"), nil, "GB18030")

Name Error in Excel Uninitalized Contant in 'roo'

I am trying to read an Excel file in Ruby On Rails.
I have done coding like this for reading the cell content from the Excel sheet.
def test
require 'rubygems'
require 'iconv'
require 'roo'
s = Excel.new("C:/Sites/hmmsapp/Book1.xls")
s.default_sheet = s.sheets.first
1.upto(4) do |line|
roll = s.cell(line,'A')
puts "#{roll} -------------"
end
end
But on running this it always gives me this error.
NameError in HostelController#test
uninitialized constant HostelController::Excel
I have also included iconv as per suggestions for this problem. But there is no change in error.
Please give some light to removing this error & to read the excel file properly.
Try Roo::Excel.new
Or Roo::Spreadsheet.new

Fastercsv shows malformedCSVError, what am i doing wrong?

I am implementing in Ruby and i am running a project which reads a CSV file to add users.
but when i pick my file it just gives always the same error:
FasterCSV::MalformedCSVError in User importController#match
Illegal quoting on line 1.
my CSV file just exists of :
"RubenPersoon1","test","Bauwens","Ruben","rub#gmail.com",0
anyone who knows what can be wrong?
Try to upgrade your FasterCSV gem version. With the latest version it works:
FasterCSV.parse_line '"RubenPersoon1","test","Bauwens","Ruben","rub#gmail.com",0'
=> ["RubenPersoon1", "test", "Bauwens", "Ruben", "rub#gmail.com", "0"]
ruby-1.8.7-p352 :005 > FasterCSV.parse '"RubenPersoon1","test","Bauwens","Ruben","rub#gmail.com",0'
=> [["RubenPersoon1", "test", "Bauwens", "Ruben", "rub#gmail.com", "0"]]
Also, keep in mind that if you are on Ruby 1.9.2, FasterCSV is already included. Just require 'csv' and use the CSV class.

Rails3+CSV wrong number of arguments (0 for 1) , in generate

In development mode iam using (rails3 and ruby 1.9.2p136) and CSV is working good,
but,
In production mode iam using (rails3 and ruby 1.9.2p0) and CSV throws error
(wrong number of arguments (0 for 1) , in generate)
please can u suggest me what could be the problem.
thanks
I encountered exact same problem on Fedora15 with ruby 1.8.7 .
Code below fixed the CSV.generate problem.
if RUBY_VERSION < "1.9"
require "rubygems"
require "faster_csv"
CSV = FCSV
else
require "csv"
end

Resources