libxlsxwriter
merge_range.c
<< constant_memory.c merge_rich_string.c >>

Example of merging cells in a worksheet.

/*
* An example of merging cells using libxlsxwriter.
*
* Copyright 2014-2018, John McNamara, jmcnamara@cpan.org
*
*/
#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. */
format_set_bold(merge_format);
/* 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);
workbook_close(workbook);
return 0;
}
workbook_close
lxw_error workbook_close(lxw_workbook *workbook)
Close the Workbook object and write the XLSX file.
LXW_ALIGN_VERTICAL_CENTER
@ LXW_ALIGN_VERTICAL_CENTER
Definition: format.h:153
format_set_align
void format_set_align(lxw_format *format, uint8_t alignment)
Set the alignment for data in the cell.
workbook_new
lxw_workbook * workbook_new(const char *filename)
Create a new workbook object.
format_set_border
void format_set_border(lxw_format *format, uint8_t style)
Set the cell border style.
format_set_bold
void format_set_bold(lxw_format *format)
Turn on bold for the format font.
LXW_COLOR_YELLOW
@ LXW_COLOR_YELLOW
Definition: format.h:226
lxw_worksheet
Struct to represent an Excel worksheet.
Definition: worksheet.h:1603
lxw_format
Struct to represent the formatting properties of an Excel format.
Definition: format.h:358
format_set_bg_color
void format_set_bg_color(lxw_format *format, lxw_color_t color)
Set the pattern background color for a cell.
LXW_ALIGN_CENTER
@ LXW_ALIGN_CENTER
Definition: format.h:129
lxw_workbook
Struct to represent an Excel workbook.
Definition: workbook.h:273
worksheet_set_row
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.
worksheet_set_column
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_BORDER_THIN
@ LXW_BORDER_THIN
Definition: format.h:295
workbook_add_worksheet
lxw_worksheet * workbook_add_worksheet(lxw_workbook *workbook, const char *sheetname)
Add a new worksheet to a workbook.
workbook_add_format
lxw_format * workbook_add_format(lxw_workbook *workbook)
Create a new Format object to formats cells in worksheets.
worksheet_merge_range
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.