This script uses the dbfpy module from http://dbfpy.sourceforge.net/.
import csv
from dbfpy import dbf
import sys
dbf_fn = sys.argv[1]
csv_fn = sys.argv[2]
in_db = dbf.Dbf(dbf_fn)
out_csv = csv.writer(open(csv_fn, 'wb'))
names = []
for field in in_db.header.fields:
names.append(field.name)
out_csv.writerow(names)
for rec in in_db:
out_csv.writerow(rec.fieldData)
in_db.close()
from dbfpy import dbf
import sys
dbf_fn = sys.argv[1]
csv_fn = sys.argv[2]
in_db = dbf.Dbf(dbf_fn)
out_csv = csv.writer(open(csv_fn, 'wb'))
names = []
for field in in_db.header.fields:
names.append(field.name)
out_csv.writerow(names)
for rec in in_db:
out_csv.writerow(rec.fieldData)
in_db.close()
Had a similar problem and solved it with PERL and DBI:XBase:
ReplyDeletehttp://blog.dev001.net/post/14563495366/converting-dbf-to-csv-files
Great.. thanks for sharing.
ReplyDeleteThanks for sharing, found this very helpful!
ReplyDeleteThanks, worked perfectly!
ReplyDeleteJust for remembering users the usage of the script:
import csv
from dbfpy import dbf
import sys
if(len(sys.argv) < 2):
print "Error: Missing arguments.\n\tUsage: python dbf2csv.py in_dbf_file out_csv_filename"
exit (1)
dbf_fn = sys.argv[1]
csv_fn = sys.argv[2]
in_db = dbf.Dbf(dbf_fn)
out_csv = csv.writer(open(csv_fn, 'wb'))
names = []
for field in in_db.header.fields:
names.append(field.name)
out_csv.writerow(names)
for rec in in_db:
out_csv.writerow(rec.fieldData)
in_db.close()
Thank you!
ReplyDeleteEach record is separated by a delimiter such as a comma or a semi colon and every new row of data indicates a new record.excel dashboard software
ReplyDelete