Sure you can, read the docs: https://openpyxl.readthedocs.io/en/stable/
you can have more that one worksheet open at a time (which you are doing on line 3)
Since you're buildng a dictionary (writer.sheets) to contain all worksheets,
you extract the sheet by title.
It would be easier (if only two sheets were involved, to open each with separate names)
using the attached simple spreadsheet, copy sheet 1 A1 to sheet2 B1:
you can have more that one worksheet open at a time (which you are doing on line 3)
Since you're buildng a dictionary (writer.sheets) to contain all worksheets,
you extract the sheet by title.
It would be easier (if only two sheets were involved, to open each with separate names)
using the attached simple spreadsheet, copy sheet 1 A1 to sheet2 B1:
from openpyxl import Workbook, load_workbook, cell import os os.chdir(os.path.abspath(os.path.dirname(__file__))) def A1_to_B1(): # move sheet 1 cell a1 to sheet2 cell b1 wb = load_workbook('Sheettest.xlsx') wb1 = sheet_object = wb.worksheets[0] wb2 = sheet_object = wb.worksheets[1] wb2.cell(row=1, column=2).value = wb1.cell(row=1, column=1).value wb.save('Sheettest.xlsx') A1_to_B1()
Attached Files
Sheettest.xlsx (Size: 8.12 KB / Downloads: 149)