说明
用python删除一个excel中的空子表,可以经过灵活更改,满足自己个人相关需求
代码
1. 导包
import openpyxl
2. 加载表格信息
# 文件路径
workbook = './data/新数据整理/京沪.xlsx'
3. 核心代码
# 主函数
if __name__ == "__main__":
wb = openpyxl.load_workbook(workbook)
sheet = []
for sheetlist in wb:
# print("sheetTitle:", sheetlist.title)
if sheetlist.max_row == 1:
print("删除子表:", sheetlist.title)
wb.remove_sheet(sheetlist)
continue
sheet.append(sheetlist.title)
print(sheet)
print(len(sheet))
wb.save(workbook) # 记得保存