用python刪除一個excel中的空子表,可以經過靈活更改,滿足自己個人相關需求
import openpyxl
# 文件路徑
workbook = './data/新數據整理/京滬.xlsx'
# 主函數
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) # 記得保存