Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invalid value for Integer(): "0600469" #478

Closed
tushgup93 opened this issue Jan 3, 2019 · 10 comments
Closed

invalid value for Integer(): "0600469" #478

tushgup93 opened this issue Jan 3, 2019 · 10 comments

Comments

@tushgup93
Copy link

Thanks for filing an issue. Following these instructions will help us solve your problem sooner.

Steps to reproduce

Upload any excel with value starting with "0" as mentioned above .

Issue

Describe the issue
Any value that contains numbers , roo considers it as a number but when it starts with "0", it does not treat it as string instead it throws the error invalid value for Integer()

System configuration

Roo version:
roo-2.7.1
Ruby version:
2.3.0

@chopraanmol1
Copy link
Member

@tushgup93 Thank you for reporting this issue. roo uses Integer() to convert respective value to integer.

ruby considers the value to be octal format if it starts with 0

Integer "0600469"
ArgumentError (invalid value for Integer(): "0600469")
Integer "0600467"
=> 196919 

Can you attach a sample excel file reproducing the mentioned issue so that expected behavior could be determined?

Please feel free to open a PR for this!

@tushgup93
Copy link
Author

so it basically have 4 columns:
Detail level | Detail value | Oil type | Liters
KBA | 600469 | AB-40 | 2.0
KBA | 060044 | AB-40 | 2.0
KBA | 60046 | AB-40 | 2.0
This is the code:

  1. file_object = Roo::Spreadsheet.open(@file.location,extension: :xlsx)
  2. converted_header = file_object.row(1).map { |x| x.to_s.parameterize.underscore.to_sym }.zip ->
    it breaks here in roo -> "roo-2.7.1/lib/roo/excelx/cell/number.rb:24"

Can we avoid roo to check for valid integer type or tell it to consider it as string by default?

@chopraanmol1
Copy link
Member

@tushgup93 I'm unable to reproduce this issue. The excel client (google spreadsheet, libre office) I used to generate the sample file either didn't accept leading zero to integer or changed the cell to use text format. And both of these scenarios work well with roo.

Since I'm unable to create an excel file which reproduces this issue, I'll suggest you attach a sample excel file which reproduces this issue.

@tushgup93
Copy link
Author

that is what i mentioned, on importing the excel file, roo does not accept it , so how to direct the cell to treat it as text format?
Anyway, attaching the sample xlsx file.
sample.xlsx

@chopraanmol1
Copy link
Member

@tushgup93 I've fixed the issue on the master. In roo typecasting take place when the file is parsed, due to which currently you cannot access raw value before typecasting takes place. If you still want to access raw value you can use the following method:

https://www.rubydoc.info/gems/roo/Roo%2FExcelx:excelx_value

@tushgup93
Copy link
Author

thanks @chopraanmol1 , can you also create a version with this commit ? I am using 2.7

@chopraanmol1
Copy link
Member

@tushgup93 I'll update you on this issue once we make next release.

@chopraanmol1
Copy link
Member

@tushgup93 roo v2.8.0 is released
https://rubygems.org/gems/roo/versions/2.8.0

@tushgup93
Copy link
Author

tushgup93 commented Jan 22, 2019 via email

@kevserbuyukaydin
Copy link

kevserbuyukaydin commented May 28, 2024

I have excel file some columns are like this.
Order | Customer | Code | No
0010008673,0010009249,0010009065 | A | 101 | P280
0010009250 | B | 103 | P280
0010009065 | C | 105 | P280

Order column format cells category is General.

@file.first_row return invalid value for Integer(): ""
If I choose the order column format cell type number or text, I do not receive this error or if I change the file name I don't get this error. I need to read this excel file without changing the order column format cell type.

@file = Roo::Spreadsheet.open(file)
p = Axlsx::Package.new
wb = p.workbook

wb.add_worksheet(name: 'blank lines removed') do |sheet|
  (@file.first_row..@file.last_row).each do |idx|
    next if @file.row(idx).all?(&:nil?)
    sheet.add_row @file.row(idx)
  end
end

Ruby version: 3.0.6
Roo version: roo-2.10.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants