Open MDB file on Ubuntu, convert it to CSV, import it to Rails

Open MDB file on Ubuntu, convert it to CSV, import it to Rails
MDB is a data file format used by Microsoft Office Access. To open and view MDB files on ubuntu, you can install a tools named mdbtools :

sudo apt-get install libmdbtools mdbtools mdbtools-gmdb

This will also install MDB viewer, and you can use it to open and view MDB files. It also can be used to export tables to CSV(Comma-separated_values) files.

And here is an example importing CSV data into Rails model:
require ‘csv’
CSV::Reader.parse(File.open(‘/path/to/file’, ‘rb’)).each do |row|
    Production.create(:name => row[1],
        :price => row[3])
end

转载请注明: 转自船长日志, 本文链接地址: http://www.cslog.cn/Content/csv/

此条目发表在 Ruby on Rails, 信息处理 分类目录。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>