When I run my program without the code to create a chart, it works fine and converts from a .csv to an .xlsx and opens normally. When I include the code to create the graph it opens to a blank page without a workbook. Because of this I know the problem is with something after my write statements. 'col[]' is a list of user input strings that I am using to title each series, and 'colors[]' is a list of hex values I am using to pick the colors for each series. I have limited experience with C++ and only began learning Python a week ago so please forgive my messy code.
workbook = xlsxwriter.workbook.Workbook(cognomen, {'strings_to_numbers': True})
sheet = workbook.add_worksheet("Sheet1")
with open(file, "r") as f:
reader = csv.reader((line.replace('\0', '') for line in f), delimiter=',')
for r, row in enumerate(reader):
for c, val in enumerate(row):
sheet.write(r, c, val)
while v < len(my_entries):
sheet.write(col[v] + str(5), str(my_entries[v].get()))
v = v + 1
chart = workbook.add_chart({
'type': 'scatter',
'subtype': 'smooth'
})
h = 0
while h < len(my_entries):
chart.add_series({
'name': str(my_entries[h].get()),
'categories': '=Sheet1!$' + str(len(my_entries) + 10) + ':$B' + str(r),
'values': '=Sheet1!$' + col[h] + ':' + str(len(my_entries) + 10) + col[h] + str(r),
'line': {
'colors': colors[h]
}
})
v = v + 1
chart.set_plotarea({
'border': {'color': 'black'}
})
chart.set_legend({
'position': 'bottom'
})
chart.set_title({
'name': new_nomen.removesuffix(".xlsx"),
'name_font': {
'name': 'Calibri',
'color': '#0066CC',
'bold': False
}
})
chart.set_x_axis({
'name': 'Time',
'name_font': {
'name': 'Calibri',
'color': '#000000',
'bold': False
},
'time_axis': True,
'num_format': 'h:mm:ss',
'min': 0,
})
chart.set_y_axis({
'name': 'Temperature (' + degree_sign + 'C)',
'name_font': {
'name': 'Calibri',
'color': '#000000',
'bold': False
},
'min': 0,
})
chart.set_style(15)
sheet.insert_chart('C1', chart, {'x_offset': 25, 'y_offset': 10})
workbook.close()