import xlsxwriter
# Create an new Excel file and add a worksheet.
workbook = xlsxwriter.Workbook('merge1.xlsx')
worksheet = workbook.add_worksheet()
# Create a format to use in the merged range.
merge_format = workbook.add_format({
'bold': 1,
'border': 1,
'align': 'center',
'valign': 'vcenter',
'fg_color': 'yellow'})
# Test to add in merged cell
text = "This is a merged cell!"
# Merge 3 cells.
worksheet.merge_range('B4:D4', text, merge_format)
# Merge 3 cells over two rows.
worksheet.merge_range('B7:D8', text, merge_format)
# Will save on file
workbook.close()