File: format_font.c

package info (click to toggle)
libxlsxwriter 1.2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,888 kB
  • sloc: ansic: 65,861; python: 2,106; makefile: 693; perl: 229; sh: 224; xml: 168; cpp: 73; javascript: 5
file content (46 lines) | stat: -rw-r--r-- 1,391 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
 * Example of writing some data with font formatting to a simple Excel
 * file using libxlsxwriter.
 *
 * Copyright 2014-2026, 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. */
    format_set_italic(format2);

    /* Set the bold and italic properties for format 3. */
    format_set_bold  (format3);
    format_set_italic(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;
}