Python导出DBF文件到Excel的方法
作者:Sephiroth 时间:2023-03-12 20:50:15
本文实例讲述了Python导出DBF文件到Excel的方法。分享给大家供大家参考。具体如下:
from dbfpy import dbf
from time import sleep
from win32com import client
def 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)
希望本文所述对大家的Python程序设计有所帮助。
标签:Python,DBF,Excel
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
6行的js上下滑动广告效果
2008-11-27 12:26:00
![](https://img.aspxhome.com/file/UploadPic/200811/27/time-58s.gif)
Python使用Plotly绘制常见5种动态交互式图表
2023-06-08 06:27:59
![](https://img.aspxhome.com/file/2023/1/114581_0s.gif)
Python OpenCV对本地视频文件进行分帧保存的实例
2021-09-15 23:03:18
基于PyTorch实现一个简单的CNN图像分类器
2021-08-16 21:52:31
JavaScript判断对象是否为数组
2024-04-22 22:42:14
MYSQL大数据导入
2024-01-18 18:09:36
Python实现RLE格式与PNG格式互转
2021-07-11 18:23:19
python用于url解码和中文解析的小脚本(python url decoder)
2023-01-28 06:19:00
javascript canvas实现雨滴效果
2024-04-17 10:02:45
![](https://img.aspxhome.com/file/2023/1/136421_0s.jpg)
Python基础之元编程知识总结
2023-03-17 11:06:36
跟老齐学Python之画圈还不简单吗?
2022-06-07 04:57:11
![](https://img.aspxhome.com/file/2023/2/77022_0s.png)
sqlserver 日期比较、日期查询常用语句:月的第一天,季度的第一天等
2010-08-01 18:58:00
SQL Server 2008主要功能在兼容性上的问题
2009-03-25 16:43:00
C#操作本地文件及保存文件到数据库的基本方法总结
2024-01-17 10:27:55
Python走楼梯问题解决方法示例
2021-07-07 22:57:51
浅谈Python数学建模之固定费用问题
2022-09-08 10:26:41
![](https://img.aspxhome.com/file/2023/6/135326_0s.png)
模仿PHP写的ASP分页函数
2008-04-13 06:11:00
关于networkx返回图的邻接矩阵问题
2021-04-09 13:10:35
![](https://img.aspxhome.com/file/2023/0/134730_0s.png)
3段Python图像处理的实用代码的分享
2021-10-19 08:06:58
![](https://img.aspxhome.com/file/2023/7/75927_0s.png)
详解MySQL数据库中字符串的正确使用
2010-06-20 15:01:00
![](https://img.aspxhome.com/file/UploadPic/20106/20/2010620152746558s.gif)