roo-gem

Formatting Excel cell from number to text in rails

落花浮王杯 提交于 2021-02-07 07:59:34
问题 I have made an application on which I have provide the feature to import the records from CSV and Excel file. I am using roo gem for it. The record added successfully but the problem is at the time of importing records from excel, it adds .0 to every field which is number. I don't want it because i have some fields like enrollment_no, roll_no, contact_no and it adds .0 to every filed like it made 23 to 23.0. I already had converted these filed to varchar in database and now i want to format

How do I parse an Excel file that will give me data exactly as it appears visually?

狂风中的少年 提交于 2019-12-08 17:35:55
问题 I'm on Rails 5 (Ruby 2.4). I want to read an .xls doc and I would like to get the data into CSV format, just as it appears in the Excel file. Someone recommended I use Roo, and so I have book = Roo::Spreadsheet.open(file_location) sheet = book.sheet(0) text = sheet.to_csv arr_of_arrs = CSV.parse(text) However what is getting returned is not the same as what I see in the spreadsheet. For isntance, a cell in the spreadsheet has 16:45.81 and when I get the CSV data from above, what is returned

Trim a trailing .0

て烟熏妆下的殇ゞ 提交于 2019-12-05 12:03:27
问题 I have an Excel column containing part numbers. Here is a sample As you can see, it can be many different datatypes: Float , Int , and String . I am using roo gem to read the file. The problem is that roo interprets integer cells as Float , adding a trailing zero to them (16431 => 16431.0). I want to trim this trailing zero. I cannot use to_i because it will trim all the trailing numbers of the cells that require a decimal in them (the first row in the above example) and will cut everything

Roo with rails4 giving undefined method `[]' for nil:NilClass

十年热恋 提交于 2019-12-02 07:11:54
问题 I'm trying to import CSV and Excel files into a rails 4 project (with validation) using the Roo gem, based on http://railscasts.com/episodes/396-importing-csv-and-excel. I've made some changes to account for Rails4 instead of Rails3 and for changes to Roo, and my ProjectImporter model now looks like: class ProductImport include ActiveModel::Model attr_accessor :file def initialize(attributes = {}) attributes.each { |name, value| send("#{name}=", value) } end def persisted? false end def save

Roo with rails4 giving undefined method `[]' for nil:NilClass

隐身守侯 提交于 2019-12-01 23:31:38
I'm trying to import CSV and Excel files into a rails 4 project (with validation) using the Roo gem, based on http://railscasts.com/episodes/396-importing-csv-and-excel . I've made some changes to account for Rails4 instead of Rails3 and for changes to Roo, and my ProjectImporter model now looks like: class ProductImport include ActiveModel::Model attr_accessor :file def initialize(attributes = {}) attributes.each { |name, value| send("#{name}=", value) } end def persisted? false end def save if imported_products.map(&:valid?).all? imported_products.each(&:save!) true else imported_products