How to export DBF Files to Excel using Python

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.