本篇文章给大家带来的内容是关于python实现读写excel和修改excel的代码,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
读Excel
#打开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)
立即学习“Python免费学习笔记(深入)”;
写Excel
#创建文件对象 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)
立即学习“Python免费学习笔记(深入)”;
修改已经存在的Excel文件
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的代码的详细内容,更多请关注php中文网其它相关文章!
全网最新最细最实用WPS零基础入门到精通全套教程!带你真正掌握WPS办公! 内含Excel基础操作、函数设计、数据透视表等
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号