1

Can I use column header names instead of column alphabets for editing in pandas xlsxwriter?

This is for python 3.x using pandas and latest xlsx writer

worksheet.set_column('F:H', 30)

I want something like

worksheet.set_column('colname1:colname2', 30)

I don't want to use dictionary or assign column names to the default cell notation, it has to be dynamic(the position of the column shouldn't matter)

1 Answers1

0

In almost all cases in XlsxWriter you can use zero indexed (Row, Col) notation instead of A1 range notation.

From the XlsxWriter docs on set_column()

It is also possible, and generally clearer, to specify a column range using the form of A1 notation used for columns. See Working with Cell Notation for more details.

Examples:

worksheet.set_column(0, 0, 20)   # Column  A   width set to 20.
worksheet.set_column(1, 3, 30)   # Columns B-D width set to 30.
worksheet.set_column('E:E', 20)  # Column  E   width set to 20.
worksheet.set_column('F:H', 30)  # Columns F-H width set to 30.
Community
  • 1
  • 1
jmcnamara
  • 38,196
  • 6
  • 90
  • 108
  • Hey so what I actually need is a dynamic way to select the column using column header names specified by me because the columns might shift depending on various cases and if I use (Row, Col) notation or range notation it will format any column that comes under the notation so I don't want the formatting to get mixed up – Aatish Kayyath Nov 08 '19 at 10:58