I need to load an existing Excel sheet, write a pandas dataframe to a named range and subsequently save the sheet under a new name. How am I supposed to do that?
import openpyxl
import pandas.util.testing as tm
from openpyxl import Workbook, load_workbook
from openpyxl.utils.dataframe import dataframe_to_rows
# Load Excel sheet, which contains the named range ('TestRange') in range A1:C2
wb = load_workbook('template.xlsx')
ws = wb['Tab1']
# Create dummy 2x3 dataframe
tm.N, tm.K = 2, 3
df = tm.makeDataFrame()
# Write dateframe to 'TestRange'
# That's the part in question!
# Save sheet under new name
wb.save('df1.xlsx')