Python Forum

Full Version: How to set majorGridLines in openpyxl?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Dear Experts,

Quite new at Python, so sorry fo stupid question but I have some experiences in C/C++ and Perl and some other languages. Now I need to come to Python...

I use openpyxl to read/write Excel files. To create a chart with logarithm scaled X-axis I need to switch on the majorGridlines. But I do not find any documentation about how to do this. All I found, that the value must be a type of <class ‘openpyxl.chart.axis.ChartLines’>.

# define chart
    chart = ScatterChart()
    chart.title = "FooBaa"
    chart.x_axis.title = "Frequency"
    chart.x_axis.scaling.logBase = 10
    chart.x_axis.scaling.min = 100 #Later dynmaic!
    chart.x_axis.scaling.max = 20000 #Later dynmaic!
    chart.x_axis.majorGridlines = ChartLines()
    chart.y_axis.title = "SPL"
    chart.legend = None
    
    # retrieve data
    x = Reference(ws1, min_col=3, min_row=1, max_row=staticlines)
    y = Reference(ws1, min_col=2, min_row=1, max_row=maxlines)
    s = Series(y, xvalues=x)
    chart.append(s)
Any tips or suggestions?
Thanks a lot for your help,
Karsten