No Matches
<< image_buffer.c merge_rich_string.c >>

Example of merging cells in a worksheet.

* An example of merging cells using libxlsxwriter.
* Copyright 2014-2021, John McNamara,
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("merge_range.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_format *merge_format = workbook_add_format(workbook);
/* Configure a format for the merged range. */
/* Increase the cell size of the merged cells to highlight the formatting. */
worksheet_set_column(worksheet, 1, 3, 12, NULL);
worksheet_set_row(worksheet, 3, 30, NULL);
worksheet_set_row(worksheet, 6, 30, NULL);
worksheet_set_row(worksheet, 7, 30, NULL);
/* Merge 3 cells. */
worksheet_merge_range(worksheet, 3, 1, 3, 3, "Merged Range", merge_format);
/* Merge 3 cells over two rows. */
worksheet_merge_range(worksheet, 6, 1, 7, 3, "Merged Range", merge_format);
return 0;
void format_set_align(lxw_format *format, uint8_t alignment)
Set the alignment for data in the cell.
Definition: format.h:296
void format_set_bold(lxw_format *format)
Turn on bold for the format font.
void format_set_border(lxw_format *format, uint8_t style)
Set the cell border style.
Definition: format.h:227
Definition: format.h:130
Definition: format.h:154
void format_set_bg_color(lxw_format *format, lxw_color_t color)
Set the pattern background color for a cell.
Struct to represent the formatting properties of an Excel format.
Definition: format.h:359
Struct to represent an Excel workbook.
Definition: workbook.h:293
Struct to represent an Excel worksheet.
Definition: worksheet.h:2108
lxw_workbook * workbook_new(const char *filename)
Create a new workbook object.
lxw_format * workbook_add_format(lxw_workbook *workbook)
Create a new Format object to formats cells in worksheets.
lxw_error workbook_close(lxw_workbook *workbook)
Close the Workbook object and write the XLSX file.
lxw_worksheet * workbook_add_worksheet(lxw_workbook *workbook, const char *sheetname)
Add a new worksheet to a workbook.
lxw_error worksheet_set_column(lxw_worksheet *worksheet, lxw_col_t first_col, lxw_col_t last_col, double width, lxw_format *format)
Set the properties for one or more columns of cells.
lxw_error worksheet_set_row(lxw_worksheet *worksheet, lxw_row_t row, double height, lxw_format *format)
Set the properties for a row of cells.
lxw_error worksheet_merge_range(lxw_worksheet *worksheet, lxw_row_t first_row, lxw_col_t first_col, lxw_row_t last_row, lxw_col_t last_col, const char *string, lxw_format *format)
Merge a range of cells.