Search code examples
pythonexcelcell

Parametrization of A1 notation cell value in python


How can I dynamically define the cell location. For example, suppose I have a worksheet consisting of six rows.

I am able to get the rows count using Count_Row = df.shape[0] but not sure how do I reference Count_Row parameter in the below statement.

worksheet.conditional_format('A1:A[Count_Row]',
                            {'type':'cell','criteria': '>=','value':0,'format':format2})

Thanks


Solution

  • Simply use .format (or any other string interpolation method of your liking):

    worksheet.conditional_format('A1:A{}'.format(Count_Row),
                                {'type':'cell','criteria': '>=','value':0,'format':format2})