File: ignore_errors.c

package info (click to toggle)
libxlsxwriter 1.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 37,864 kB
  • sloc: ansic: 65,601; python: 2,106; makefile: 693; perl: 229; sh: 224; xml: 168; cpp: 73; javascript: 5
file content (38 lines) | stat: -rw-r--r-- 1,471 bytes parent folder | download | duplicates (2)
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
/*
 * An example of turning off worksheet cells errors/warnings using
 * libxlsxwriter.
 *
 * Copyright 2014-2025, John McNamara, jmcnamara@cpan.org
 *
 */

#include "xlsxwriter.h"

int main() {

    lxw_workbook  *workbook  = workbook_new("ignore_errors.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);

    /* Write strings that looks like numbers. This will cause an Excel warning. */
    worksheet_write_string(worksheet, CELL("C2"), "123", NULL);
    worksheet_write_string(worksheet, CELL("C3"), "123", NULL);

    /* Write a divide by zero formula. This will also cause an Excel warning. */
    worksheet_write_formula(worksheet, CELL("C5"), "=1/0", NULL);
    worksheet_write_formula(worksheet, CELL("C6"), "=1/0", NULL);

    /* Turn off some of the warnings: */
    worksheet_ignore_errors(worksheet, LXW_IGNORE_NUMBER_STORED_AS_TEXT, "C3");
    worksheet_ignore_errors(worksheet, LXW_IGNORE_EVAL_ERROR,            "C6");

    /* Write some descriptions for the cells and make the column wider for clarity. */
    worksheet_set_column(worksheet, 1, 1, 16, NULL);
    worksheet_write_string(worksheet, CELL("B2"), "Warning:",            NULL);
    worksheet_write_string(worksheet, CELL("B3"), "Warning turned off:", NULL);
    worksheet_write_string(worksheet, CELL("B5"), "Warning:",            NULL);
    worksheet_write_string(worksheet, CELL("B6"), "Warning turned off:", NULL);

    workbook_close(workbook);

    return 0;
}