更新:だから私たちは機能
を呼び出すとき>ここ
import xlrd
xl_ref = xlrd.open_workbook('Path to file')
タイプ(xl_ref)< クラスのxlrd.book.Bookです:新しいシートを作成する答え
が見つかり
xl_ref.add_sheet('Test1')
エラーブックオブジェクトには属性がありません。基本的にはいつでも既存の変更に影響を与えることなく.xlsファイルを操作したい。最初に、ブックオブジェクトに変換する。
from xlutils.copy import copy
xlwb_ref=copy(xl_ref)
xlwb_ref.add_sheet('Test1')
xlwb_ref.save('Path to file')
参考:
import pythoncom
from win32com.client.gencache import EnsureDispatch
pythoncom.CoInitialize() #if Calling same thing again and again so better reinitialize.
excel = EnsureDispatch("Excel.Application")
excel_file = excel.Workbooks.Open("Path to file")
sheet = excel.Sheets("Sheet name")
sheet.Delete()
excel_file.Close(True)
:シートを削除
Python_doc