Merging Excel cells using Xlsxwriter in Python

user3015703 picture user3015703 · Nov 10, 2014 · Viewed 17.3k times · Source

I want to merge several series of cell ranges in an Excel file using Python Xlsxwriter, I found the Python command in the Xlsxwriter documentation in this website http://xlsxwriter.readthedocs.org/en/latest/example_merge1.html as below:

worksheet.merge_range('B4:D4')

The only problem is that I have my ranges in row and columns numbers format for example (0,0) which is equal to A1. But Xlsxwriter seems to only accept format like A1. I was wondering if anybody else had the same problem and if there is any solution for that.

Answer

jmcnamara picture jmcnamara · Nov 10, 2014

Almost all methods in XlsxWriter support both A1 and (row, col) notation, see the docs. So the following are equivalent for merge_range():

worksheet.merge_range('B4:D4',    'Merged Range', merge_format)
worksheet.merge_range(3, 1, 3, 3, 'Merged Range', merge_format)