This article mainly introduces how to export DBF Files to Excel using Python. The example shows how to export and convert Python files based on the win32com module, for more information about how to export a DBF file to Excel using Python, see the following example. Share it with you for your reference. The details are as follows:
From dbfpy import dbffrom time import sleepfrom win32com import clientdef dbf2xls (dbfilename, exfilename): db = dbf. dbf (dbfilename, True) ex = client. dispatch ('excel. application ') wk = ex. workbooks. add () ws = wk. activeSheet ex. visible = True sleep (1) r = 1 c = 1 for field in db. fieldNames: ws. cells (r, c ). value = field c = c + 1 r = 2 for record in db: c = 1 for field in db. fieldNames: ws. cells (r, c ). value = record [field] c = c + 1 r = r + 1 wk. saveAs (exfilename) wk. close (False) ex. application. quit () db. close () if _ name __= = '_ main _': dbffilename = "test. dbf "xlsfilename =" text.xls "dbf2xls (dbffilename, xlsfilename)
I hope this article will help you with Python programming.