本文摘自php中文网,作者不言,侵删。
本篇文章给大家带来的内容是关于Python实现读写Excel和修改Excel的代码,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。读Excel
1 2 3 4 5 6 | #打开Excek,xlsfile为Excel路径+文件名
boorRead = xlrd.open_workbook(xlsfile)
#读取sheet,sheet_name为Excel中sheet的名称
sheetRead = boorRead.sheet_by_name(sheet_name)
#读取单元格内容
data = sheetRead.cell_value(row, col)
|
写Excel
1 2 3 4 5 6 7 8 | #创建文件对象
wrbook = xlwt.Workbook(encoding= 'utf-8' , style_compression=0)
#增加sheet
wrsheet = wrbook.add_sheet(sheet_name, cell_overwrite_ok=True)
#向单元格写数据,
wrsheet.write(row,col,data)
#保存文件
wrbook.save(xlsname)
|
修改已经存在的Excel文件
1 2 3 4 5 | book = xlrd.open_workbook(xlsfile,formatting_info=True)
book_wr = copy (book)
sheet_wr = bookWr.get_sheet(sheet_name)
sheet_wr.write(row,clo,data)
book_wr.save(file_name)
|
以上就是Python实现读写Excel和修改Excel的代码的详细内容,更多文章请关注木庄网络博客!!
相关阅读 >>
Python中线程终止与挂起的实现方法
Python model怎么用
Python 列表推导式使用的注意事项
利用Python将pdf输出为txt的实例
Python中filecmp的简单使用
Python实现跨excel的工作表sheet之间的复制方法
Python中sort是什么意思
Python怎么调用自定义函数
Python除法运算符是什么
Python爬虫对dota排行榜爬取的实例
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » Python实现读写Excel和修改Excel的代码