alwbtc
alwbtc

Reputation: 29445

Excel sheet created with pythons xlsxwriter module runs too slow

I have created a column chart with 2 series using xlsxwriter python module with the code below. When I open up the file in Microsoft Excel, navigating it is slow.

def create_2_series_column_chart(self, sheet_obj, series_1, series_2, chart_name, x_axis_name, y_axis_name, location):
    chart1 = self.output_workbook.add_chart({'type': 'column'})
    chart1.add_series(series_1)
    chart1.add_series(series_2)
    chart1.set_title({'name': chart_name})
    chart1.set_x_axis({'name': x_axis_name})
    chart1.set_y_axis({'name': y_axis_name})

    chart1.set_style(42)

    sheet_obj.insert_chart(location, chart1, {'x_offset': 25, 'y_offset': 10})


    series_1 = {
        'name':       ["MY_SHEET", 2, 1],
        'categories': ['MY_SHEET', 3, 0, 2+num_days_in_month, 0],
        'values':     ['MY_SHEET', 3, 15+2*ix+1, 2+num_days_in_month, 15+2*ix+1],
        }

    series_2 = {
        'name':       ["MY_SHEET", 2, 2],
        'categories': ['MY_SHEET', 3, 0, 2+num_days_in_month, 0],
        'values':     ['MY_SHEET', 3, 16+2*ix+1, 2+num_days_in_month, 16+2*ix+1],
        #'data_labels': {'value': True, 'position': 'top'}
        }

location = ["A", "J", "S", "AB"][ix]+ "54"
self.create_2_series_column_chart(self.my_worksheet, series_1, series_2, "CHARTS", 'days', 'count', location)

Any ideas?

Upvotes: 0

Views: 579

Answers (1)

jmcnamara
jmcnamara

Reputation: 41554

XlsxWriter creates charts in exactly the same way that Excel does and there are over 200 comparison tests against chart spreadsheets created in Excel to verify that. So, in theory there isn't anything that XlsxWriter is doing that would produce slow charts. Also, no-one else has reported any similar issues and the charting feature in XlsxWriter is used quite heavily.

Nevertheless, you are clearly seeing a issue so here are some things to look into:

  1. Check the data ranges that the chart is using to plot the data. In Excel right click on the chart and choose "Select Data". Then verify that the data being plotted is correct. In particular look for an accidentally long data range or a data range that contains incorrect data.
  2. Save the file in Excel, close it, and then re-open it. In this case do you see the same behaviour?

If both of those don't highlight the problem or give you further clues then you can submit a bug report. However, that will need to be a small, complete, working example that demonstrates the issue. A code snippet such as the above isn't enough information to find an issue like this.

P.S. I am the author of XlsxWriter.

Upvotes: 2

Related Questions