Python实现读写Excel和修改Excel的代码


本文摘自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有什么简单项目适合初学者?

input Python怎么用

Python--dicom图像的研究

Python第三方库安装在哪

如何用Python做游戏

Python运维学什么

Python中import如何使用

Python不能做什么

Python e怎么表示

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...