I have creates the following function to insert a chart into a excel sheet. However, the ranges here are constant (e.g., !$C$1:$CT$1"). My question is how can I change the range to be dynamic?
import xlsxwriter
outputs = xlsxwriter.Workbook(output_path)
def draw_charts(sheet_name, data_sheet):
"""Draw the excel charts."""
# Create a new chart object.
chart = outputs.add_chart({"type": "column", "subtype": "stacked"})
# create a worksheet that only holds a chart
chartsheet = outputs.add_chartsheet(sheet_name)
# Add a series to the chart.
chart.add_series(
{
"name": "=" + data_sheet + "!$A$2:$B$2",
"categories": "=" + data_sheet + "!$C$1:$CT$1",
"values": "==" + data_sheet + "!$C$2:$CT$2",
}
)
# Insert the chart into the worksheet.
chartsheet.set_chart(chart)