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/zh-hant/

此條目發表在 Ruby on Rails, 信息處理 分類目錄。將固定鏈接加入收藏夾。

發表評論