Forum: Ruby how to open dbf file with ruby?

F4666cdb6d09eb3511209deb16c337b0?d=identicon&s=25 Pen Ttt (luofeiyu)
on 2010-04-12 08:14
there is a dbf  file , can i open it with ruby?
Ac4123f7af05808b1ec7a1bbdb69ce07?d=identicon&s=25 Priyanka Pathak (priyanka-pathak)
on 2010-04-12 09:04
Hi,

   For .dbf  file access you have to use "dbf" gem. see this for more
information http://github.com/infused/dbf. hope that will help you.
55e8441972b0e0740e34161a493e902d?d=identicon&s=25 GianFranco Bozzetti (Guest)
on 2010-04-12 09:10
(Received via mailing list)
"Pen Ttt" <myocean135@yahoo.cn> wrote in message
news:39ae7de1fd20340c05bed8c0589a3d8b@ruby-forum.com...
> there is a dbf  file , can i open it with ruby?
> --
> Posted via http://www.ruby-forum.com/.
>


Http://rubyforge.org has snippets for

- XBase/DBase Reader class
- XBase/DBase Writer class

HTH gfb
2bf5c0554c7929ab2f26d683be28e68e?d=identicon&s=25 Sasa Babic (Guest)
on 2010-04-12 09:45
(Received via mailing list)
On 12.04.2010. 08:14, Pen Ttt wrote:
> there is a dbf  file , can i open it with ruby?

http://github.com/infused/dbf
B397b498cc02503a2d86c86176f7fd3e?d=identicon&s=25 Magnus Holm (judofyr)
on 2010-04-12 11:28
(Received via mailing list)
Depends.

If it's a dBase file, then use http://github.com/infused/dbf
If it's a Mimer DB, then it's not possible :(

// Magnus Holm
F4666cdb6d09eb3511209deb16c337b0?d=identicon&s=25 Pen Ttt (luofeiyu)
on 2010-04-12 13:06
hai ,everyone
i have installed  dbf,
gem install dbf
require 'dbf'
table = DBF::Table.new("/home/pt/test/sh.dbf")
#  /home/pt/test/sh.dbf  is  my dbf file.
table.each do |record|
  puts record
end
there is the output
#<DBF::Record:0x9e22cfc>
#<DBF::Record:0x9dbbdcc>
#<DBF::Record:0x9d90cf4>
#<DBF::Record:0x9cd53b4>
#<DBF::Record:0x9c07260>
#<DBF::Record:0x9a8faa0>
#<DBF::Record:0x993f2dc>
#<DBF::Record:0x96fd2c4>
#<DBF::Record:0xa22019c>
#<DBF::Record:0xa19e6fc>
#<DBF::Record:0xa185888>
#<DBF::Record:0xa174590>
#<DBF::Record:0xa124404>
#<DBF::Record:0xa0d1d64>
#<DBF::Record:0xa089364>
#<DBF::Record:0x9fdb688>
#<DBF::Record:0x9f6cd64>
#<DBF::Record:0x9f0ca98>
#<DBF::Record:0x9ef7344>
#<DBF::Record:0x9ea89e4>
#<DBF::Record:0x9e0c038>
#<DBF::Record:0x9d9faf4>
#<DBF::Record:0x9d2c524>
#<DBF::Record:0x9cd204c>
#<DBF::Record:0x9c002b4>
#<DBF::Record:0x99e0560>
#<DBF::Record:0x98b1f48>
#<DBF::Record:0x967a90c>
=> 0
many many
1\how can i know how many fields in the dbf (/home/pt/test/sh.dbf )?
F4666cdb6d09eb3511209deb16c337b0?d=identicon&s=25 Pen Ttt (luofeiyu)
on 2010-04-12 13:34
i haved solved this problem myself
1、to get schema  in ubuntu console:
pt@pt-laptop:~$ dbf  -a   /home/pt/test/sh.dbf
2、to get csv file   in ubuntu console:
dbf  -c   /home/pt/test/sh.dbf
there is a file named  /home/pt/sh.csv
everything is ok.
F4666cdb6d09eb3511209deb16c337b0?d=identicon&s=25 Pen Ttt (luofeiyu)
on 2010-04-13 02:09
hi ,here is my programm:
require 'iconv'
require 'dbf'
table = DBF::Table.new("/home/pt/test/shbase.dbf")
table.each do |record|
print
Iconv.iconv('UTF-8','GBK',record.stock_name),",",record.stock_code,"\n"
end
the output is:
["工商银行"],601398
["吉林高速"],601518
["北辰实业"],601588
["中国铝业"],601600
["中国太保"],601601
["上海医药"],601607
what i want to get is:
工商银行,601398
吉林高速,601518
北辰实业,601588
中国铝业,601600
中国太保,601601
上海医药,601607
how can i get it?
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.