简体   繁体   English

如何最轻松地从XLS导入我的Rails应用数据库?

[英]How do I most easily import from XLS into my rails app database?

I started a project in Google Spreadsheets. 我在Google Spreadsheets中启动了一个项目。 I am now learning Rails instead. 我现在正在学习Rails。 But I still have about 1000 records I'd like to import, to kick off my database. 但是我仍然要导入约1000条记录,以启动数据库。

This railcast is great, but I don't need users to do it, and I only need to do it once. 这次广播很棒,但是我不需要用户这样做,只需要执行一次。

I'd love a one-line solution like this provides for SQL files... except that even if I had an SQL file (not an export option), I wouldn't know where to call that one line. 我很喜欢像这样提供SQL文件的单行解决方案……除了即使我有一个SQL文件(不是导出选项),​​我也不知道在哪里调用那一行。

Thank you. 谢谢。

Try this: 尝试这个:

How to import CSV file data into a PostgreSQL table? 如何将CSV文件数据导入PostgreSQL表?

In short you basically setup a CSV file that reflects the structure of the database table you're importing to 简而言之,您基本上可以设置一个CSV文件,该文件反映要导入到的数据库表的结构

If you have to do some manipulation of the data you might find it easier to write something that reads your existing CSV format file and creates database records for each row. 如果您必须对数据进行某种处理,您可能会发现编写一些读取现有CSV格式文件并为每一行创建数据库记录的操作更加容易。

Either using the csv gem or something like this: 使用csv gem或类似的东西:

https://github.com/pillowfactory/csv-mapper https://github.com/pillowfactory/csv-mapper

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM