目标是使用xlwings将多个现有的工作表粘贴粘贴到新的工作簿中。我有:
app = xw.App(visible=False)
book = xw.Book(path)
sheet_1 = book.sheets["Sheet1"]
sheet_2 = book.sheets["Sheet2"]
wb_res = xw.Book()
sheet_active = wb_res.sheets.active
sheet_1.api.Copy(Before=sheet_active)
抛出:
TypeError: Objects for SAFEARRAYS must be sequences (of sequences), or a buffer object.
勇敢者的奖励问题:
-如何替换表格上的所有公式的值?
谢谢
答案 0 :(得分:0)
如果可以使用win32com
,则可以尝试以下操作:
from win32com.client import Dispatch
path1 = 'workbook1.xlsx'
path2 = 'workbook2.xlsx'
xl = Dispatch("Excel.Application")
wb1 = xl.Workbooks.Open(Filename=path1)
wb2 = xl.Workbooks.Open(Filename=path2)
ws1 = wb1.Worksheets(1)
ws1.Copy(Before=wb2.Worksheets(1))
wb2.Close(SaveChanges=True)
xl.Quit()