问题标签 [roo-gem]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
360 浏览

csv - 使用 Roo gem 并遵循 railscast 通过文件导入创建记录时的验证问题

我正在尝试通过文件导入格式创建记录,可以是 csv excel 等,我已经按照 Railscast396 实现了它。但是当我导入文件时,它显示“验证失败:电子邮件不能为空,密码不能为空。这是我的代码

观点是

routes.rb 资源 :classrooms 收集 { post :addStudents }

我正在尝试加载的 csv 文件

0 投票
0 回答
26 浏览

ruby - 如何让 XLS 数据以 CSV 格式显示,与在文件中显示的方式相同?

我正在使用 Rails 4.2.7 并且正在使用 roo-xls gem。我使用以下代码解析我的 .xls 文件

我注意到一个奇怪的是,我的 XLS 文件中读取为“53:52.56”的单元格在我的 CSV 数据中显示为“0.037413888888888885”。所有其他单元格在 CSV 数据中的显示方式与在 XLS 文件中的显示方式相同。如何让这一行显示在我的 CSV 数据中,就像它出现在 XLS 文件中一样?

0 投票
1 回答
1030 浏览

ruby - Roo - 按内容查找单元格

使用roo获取包含预定义值的单元格(或仅行)的坐标时,有没有办法?

例如,让单元格 A,3 的内容为“HERE”,我需要通过“HERE”来获取 (A,3) 或仅 3。

谢谢。

0 投票
1 回答
195 浏览

ruby-on-rails - Saving Blank Excel Cells to Rails Postgres Database

I've managed to get the Roo Gem working so that I can import an Excel file and save it to the database of my app. This has been successful a few times, but it appears that in spreadsheets that contain blanks in certain rows it brings up an error. My code is as follows:

require 'roo'

I read that from Ruby 2.3.0 by including an & before the method it doesn't include nil method errors, so I was hoping this would work.

The first 4 rows seem to work fine but as it gets to a row with blanks in Below is a snippet of the error I get:

I assume that Postgres is not content with the null data being saved in the database and therefore the "Abingdon & Witney College (Abingdon Campus)" is moved to another column, because the relevant record is a string as shown in the migration record below:

Is this what's going wrong, and are there any suggestions as to how to solve this?

0 投票
0 回答
622 浏览

ruby-on-rails - 电子表格未保存到 Rails 数据库

我已经设法使用 Roo gem 通过我的 Rails 5 应用程序解析了一个电子表格,但是一旦它完成了这个过程,它似乎并没有保存到数据库中。

这是我的代码:

这将遍历具有正确属性的每一行,给出以下结果:

并继续遍历所有行,直到最后一行:

但是,无论出于何种原因,这都不会将数据提交到 postgres 数据库。我不确定这是为什么。

如果我将代码更改为Location.create!(ukprn: row[0]&.value, accomurl: row[1]&.value, instbeds: row[3]&.value, instlower: row[4]&.value, instupper: row[5]&.value, locid: row[6]&.value, name: row[7]&.value, lat: row[9]&.value, long: row[10]&.value, locukprn: row[11]&.value, loccountry: row[12]&.value, privatelower: row[13]&.value, privateupper: row[14]&.value, suurl: row[15]&.value)它会出现以下错误:

其中 Institute 是参考(外键)。任何意见,将不胜感激。

0 投票
2 回答
208 浏览

mysql - 将数据从excel表存储到ror中的db

假设我有一个 excel 表,其中包含要存储在 db 中的数据。我使用 roo gem 并成功插入了 excel 表中的数据。现在我正在尝试验证。假设我的excel表为:

当我上传这张表时,2 行数据被回滚,1,3 行数据存储在 db 中。我想要做的是,如果发生回滚操作,那么剩余的记录不应存储在 db 中。即第 3 行数据不应存储为第 2 行已回滚。感谢任何帮助。谢谢。

更新:这是我在控制器中的代码:

我想回滚整个 excel 表不仅记录..有什么办法吗?

0 投票
4 回答
1378 浏览

ruby-on-rails - 如何解析一个 Excel 文件,它会给我的数据与它在视觉上显示的完全一样?

我在 Rails 5 (Ruby 2.4) 上。我想阅读一个 .xls 文档,并且我想将数据转换为 CSV 格式,就像它出现在 Excel 文件中一样。有人推荐我使用 Roo,所以我有

但是,返回的内容与我在电子表格中看到的不同。例如,电子表格中的一个单元格有

当我从上面获取 CSV 数据时,返回的是

如何解析 Excel 文档并准确获取我所看到的内容?我不在乎我是否使用 Roo 来解析,只要我能得到 CSV 数据,它代表我所看到的,而不是一些奇怪的内部表示。作为参考,当我运行“file name_of_file.xls”时,我正在解析的文件类型给出了这个......

0 投票
1 回答
95 浏览

ruby - 我想通过 ruby​​ 解析 csv 来创建报告

我有一个 csv 报告,其中有两行标题为“日期”和“客户名称”:

我正在尝试打印一份声明以显示当天的客户是谁,因此它会显示如下:星期一有客户 John、David、Sam 和 Kenny。\n 星期二有 Mary、Jade 和 Lindsay

我的代码是:

但我没有得到正确的输出,很可能我是编程新手。请帮助我应该如何达到要求?

["Date", "Monday", nil, nil, nil, "Tuesday", nil, nil, "Wednesday", nil, nil] 有客户 ["Customer_Name", "John", "David", "Sam", “Kenny”、“Mary”、“Jade”、“Lindsay”、“Tom”、“Lindon”、“Peter”] 参观了商店。C02S51D2G8WL:RubySQL

问候

0 投票
0 回答
658 浏览

ruby-on-rails - nil:NilClass 的未定义方法“fetch_value”

我正在使用 words_import 类/控制器来验证我的单词,因为我从 csv 文件或 excel 电子表格导入它们。不幸的是,我收到一个错误:

undefined method 'fetch_value' for nil:NilClass

当我尝试加载 words_import#new 页面时。如果可以的话请帮忙!

importer/app/controllers/word_imports_controller.rb

importer/app/models/word_import.rb

importer/app/views/product_imports/new.html.erb

importer/config/routes.rb

importer/app/controllers/words_controller

importer/app/models/word

GitHub 回购: https://github.com/bburnett86/cpf_dictionary

0 投票
1 回答
168 浏览

ruby-on-rails - Rails - 无法在控制器中使用 gem

我正在尝试使用Roo gem来解析我的 Rails 控制器中的电子表格文件。我已将适当的行添加到我Gemfile并运行bundle命令。这是我的控制器中所有中断的行:

我收到一个错误:uninitialized constant MyController::Roo。然后,我将以下行添加到我的控制器文件的顶部(如 Roo 自述文件中所述):

现在我得到一个不同的错误:Error during failsafe response: cannot load such file -- roo.

我究竟做错了什么?