python xlsxwriter change all cell widths when using write_row

jes516 picture jes516 · Jan 7, 2015 · Viewed 11.7k times · Source

How would i define a column width for the entire 'worksheet' or for each column when using write_row()?

For example i have:

workbook = xlsxwriter.Workbook(loc_path + 'monbatch_test1.xlsx')
worksheet = workbook.add_worksheet()

monbatch = [
    [a,b,c,],
    [a,b,c,],
    [a,b,c,]
    ]

row, col = 3, 0

for mon in monbatch:
    worksheet.write_row(row, col, mon, rows_format)
    row += 1
workbook.close()

I would like to change the column width for all columns (a,b,c)..

Answer

alecxe picture alecxe · Jan 7, 2015

There is a relevant set_column() method that accept width:

set_column(first_col, last_col, width, cell_format, options)

Set properties for one or more columns of cells.

Here is how you can apply it:

worksheet.set_column(0, 2, 100)