如何使用xlutils,xlwt,xlrd和python删除excel文件中的现有工作表 [英] How to delete an existing worksheet in excel file using xlutils, xlwt, xlrd with python

查看:1441
本文介绍了如何使用xlutils,xlwt,xlrd和python删除excel文件中的现有工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试搜索许多地方,但没有看到关于如何通过使用xlutils或xlwt和python删除excel文件中现有工作表的代码示例片段.谁能帮助我?

I tried to search many places but dit not see any example snippet of code about how to delete an existing worksheet in excel file by using xlutils or xlwt with python. Who can help me, please?

推荐答案

我刚刚处理了这个问题,尽管通常这不是一个好的编码选择,但是您可以使用内部的 Workbook _worksheets进行访问和设置工作簿对象的工作表.

I just dealt with this and although this is not generally a good coding choice, you can use the internal Workbook_worksheets to access and set the worksheets for a workbook object.

write_book._Workbook__worksheets = [write_book._Workbook__worksheets[0]]

这将去除除与工作簿相关的第一个工作表以外的所有内容

this would strip everything but the first worksheet associated with a Workbook

这篇关于如何使用xlutils,xlwt,xlrd和python删除excel文件中的现有工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆