Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging Excel cells using Xlsxwriter in Python

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.

like image 983
user3015703 Avatar asked Nov 10 '14 06:11

user3015703


People also ask

How do you merge two cells in Excel using Python?

Merged cells in openpyxl change from type 'Cell' to type 'MultiCellRange', which is specified as a particular range of cell coordinates. Openpyxl will let you overlap merge ranges without throwing an error, but Excel won't let you open the resulting file without a warning (and probably removing the later merges).

How do I merge cells in Xlsx?

Highlight or select a range of cells. Right-click on the highlighted cells and select Format Cells.... Click the Alignment tab and place a checkmark in the checkbox labeled Merge cells.


1 Answers

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)
like image 100
jmcnamara Avatar answered Sep 23 '22 15:09

jmcnamara