how to open dbf file with ruby?

P

Pen Ttt

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 )?
 
P

Pen Ttt

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.
 
P

Pen Ttt

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top