复制到特定 sheet:openpyxl - 使用 copy_worksheet 时忽略目标 sheet
Copying to a specific sheet: openpyxl - destination sheet ignored when using copy_worksheet
根据这个 answer and these documents 我尝试指定要写入的 source
和 target
sheet,但是当我这样做时,结果和我一样没有指定目标:
from openpyxl import load_workbook
wb = load_workbook('MyFile.xlsx')
ws = 'Sheet1'
idx = book.index(ws)
new_ws = 'Test'
book.create_sheet(new_ws, idx+1)
source = book[ws]
target = book[new_ws]
target = book.copy_worksheet(source)
wb.save('Output.xlsx')
对
source = book[ws]
book.copy_worksheet(source)
wb.save('Output.xlsx')
两者都会将名为 Sheet1 Copy
的新作品sheet 添加到工作簿的末尾。 如何将一个 sheet 复制到另一个空的 sheet 或工作簿中的特定位置?
# new copied sheet was assigned to target
target = wb.copy_worksheet(wb.source_sheet)
# now just change the name to desired one
target.title = desired_name
根据这个 answer and these documents 我尝试指定要写入的 source
和 target
sheet,但是当我这样做时,结果和我一样没有指定目标:
from openpyxl import load_workbook
wb = load_workbook('MyFile.xlsx')
ws = 'Sheet1'
idx = book.index(ws)
new_ws = 'Test'
book.create_sheet(new_ws, idx+1)
source = book[ws]
target = book[new_ws]
target = book.copy_worksheet(source)
wb.save('Output.xlsx')
对
source = book[ws]
book.copy_worksheet(source)
wb.save('Output.xlsx')
两者都会将名为 Sheet1 Copy
的新作品sheet 添加到工作簿的末尾。 如何将一个 sheet 复制到另一个空的 sheet 或工作簿中的特定位置?
# new copied sheet was assigned to target
target = wb.copy_worksheet(wb.source_sheet)
# now just change the name to desired one
target.title = desired_name