libxlsxwriter
Loading...
Searching...
No Matches
format_font.c
<< demo.c format_num_format.c >>

Example of writing some data with font formatting to a simple Excel file using libxlsxwriter.

/*
* Example of writing some data with font formatting to a simple Excel
* file using libxlsxwriter.
*
* Copyright 2014-2024, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
/* Create a new workbook. */
lxw_workbook *workbook = workbook_new("format_font.xlsx");
/* Add a worksheet. */
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
/* Widen the first column to make the text clearer. */
worksheet_set_column(worksheet, 0, 0, 20, NULL);
/* Add some formats. */
lxw_format *format1 = workbook_add_format(workbook);
lxw_format *format2 = workbook_add_format(workbook);
lxw_format *format3 = workbook_add_format(workbook);
/* Set the bold property for format 1. */
format_set_bold(format1);
/* Set the italic property for format 2. */
/* Set the bold and italic properties for format 3. */
format_set_bold (format3);
/* Write some formatted strings. */
worksheet_write_string(worksheet, 0, 0, "This is bold", format1);
worksheet_write_string(worksheet, 1, 0, "This is italic", format2);
worksheet_write_string(worksheet, 2, 0, "Bold and italic", format3);
/* Close the workbook, save the file and free any memory. */
workbook_close(workbook);
return 0;
}
void format_set_italic(lxw_format *format)
Turn on italic for the format font.
void format_set_bold(lxw_format *format)
Turn on bold for the format font.
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:2115
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_write_string(lxw_worksheet *worksheet, lxw_row_t row, lxw_col_t col, const char *string, lxw_format *format)
Write a string to a worksheet cell.