利用xlwings在多個工作簿中批量新增工作表


在多個工作簿中批量新增工作表,利用OS和xlwings模塊

#d在多個工作簿中批量新增工作表
import os
import xlwings as xw
file_path = '/Users/hugua/Desktop/python_practise/銷售表'
file_list = os.listdir(file_path)
sheet_name = '產品銷售區域'
app = xw.App(visible=True,add_book=False)
for i in file_list:
if i.startswith('~$'):
continue
file_paths = os.path.join(file_path,i)
workbook = app.books.open(file_paths)
sheet_names = [j.name for j in workbook.sheets] #獲取打開的工作簿中所有工作表的名稱
if sheet_name not in sheet_names:
workbook.sheets.add(sheet_name)
workbook.save()
app.quit()


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM