libxlsxwriter
Functions | Macros
utility.h File Reference

Functions

const char * lxw_version (void)
 Retrieve the library version. More...
 
uint16_t lxw_version_id (void)
 Retrieve the library version ID. More...
 
char * lxw_strerror (lxw_error error_num)
 Converts a libxlsxwriter error number to a string. More...
 
double lxw_datetime_to_excel_datetime (lxw_datetime *datetime)
 Converts a lxw_datetime to an Excel datetime number. More...
 
double lxw_unixtime_to_excel_date (int64_t unixtime)
 Converts a unix datetime to an Excel datetime number. More...
 

Function Documentation

◆ lxw_version()

const char* lxw_version ( void  )
Returns
The "X.Y.Z" version string.

Get the library version as a "X.Y.Z" version string

printf("Libxlsxwriter version = %s\n", lxw_version());

◆ lxw_version_id()

uint16_t lxw_version_id ( void  )
Returns
The version ID.

Get the library version such as "X.Y.Z" as a XYZ integer.

printf("Libxlsxwriter version id = %d\n", lxw_version_id());

◆ lxw_strerror()

char* lxw_strerror ( lxw_error  error_num)

The lxw_strerror function converts a libxlsxwriter error number defined by lxw_error to a pointer to a string description of the error. Similar to the standard library strerror(3) function.

For example:

lxw_error error = workbook_close(workbook);
if (error)
printf("Error in workbook_close().\n"
"Error %d = %s\n", error, lxw_strerror(error));

This would produce output like the following if the target file wasn't writable:

Error in workbook_close().
Error 2 = Error creating output xlsx file. Usually a permissions error.
Parameters
error_numThe error number returned by a libxlsxwriter function.
Returns
A pointer to a statically allocated string. Do not free.
Examples
anatomy.c.

◆ lxw_datetime_to_excel_datetime()

double lxw_datetime_to_excel_datetime ( lxw_datetime datetime)
Parameters
datetimeA pointer to a lxw_datetime struct.
Returns
A double representing an Excel datetime.

The lxw_datetime_to_excel_datetime() function converts a datetime in lxw_datetime to an Excel datetime number:

lxw_datetime datetime = {2013, 2, 28, 12, 0, 0.0};
double excel_datetime = lxw_datetime_to_excel_date(&datetime);

See Working with Dates and Times for more details on the Excel datetime format.

◆ lxw_unixtime_to_excel_date()

double lxw_unixtime_to_excel_date ( int64_t  unixtime)
Parameters
unixtimeUnix time (seconds since 1970-01-01)
Returns
A double representing an Excel datetime.

The lxw_unixtime_to_excel_date() function converts a unix datetime to an Excel datetime number:

double excel_datetime = lxw_unixtime_to_excel_date(946684800);

See Working with Dates and Times for more details.

Macro Definition Documentation

◆ CELL

#define CELL (   cell)     lxw_name_to_row(cell), lxw_name_to_col(cell)

Convert an Excel A1 cell string into a (row, col) pair.

This is a little syntactic shortcut to help with worksheet layout:

worksheet_write_string(worksheet, CELL("A1"), "Foo", NULL);
//Same as:
worksheet_write_string(worksheet, 0, 0, "Foo", NULL);
Note

This macro shouldn't be used in performance critical situations since it expands to two function calls.

Examples
chart.c, chart_area.c, chart_bar.c, chart_clustered.c, chart_column.c, chart_data_labels.c, chart_data_table.c, chart_data_tools.c, chart_doughnut.c, chart_fonts.c, chart_line.c, chart_pattern.c, chart_pie.c, chart_radar.c, chart_scatter.c, chartsheet.c, comments2.c, conditional_format1.c, conditional_format2.c, data_validate.c, diagonal_border.c, dynamic_arrays.c, ignore_errors.c, image_buffer.c, images.c, lambda.c, outline.c, outline_collapsed.c, rich_strings.c, and tables.c.

◆ COLS

#define COLS (   cols)     lxw_name_to_col(cols), lxw_name_to_col_2(cols)

Convert an Excel A:B column range into a (col1, col2) pair.

This is a little syntactic shortcut to help with worksheet layout:

worksheet_set_column(worksheet, COLS("B:D"), 20, NULL, NULL);
// Same as:
worksheet_set_column(worksheet, 1, 3, 20, NULL, NULL);
Examples
dynamic_arrays.c, hide_row_col.c, images.c, macro.c, outline.c, outline_collapsed.c, and tables.c.

◆ RANGE

#define RANGE (   range)
Value:
lxw_name_to_row(range), lxw_name_to_col(range), \
lxw_name_to_row_2(range), lxw_name_to_col_2(range)

Convert an Excel A1:B2 range into a (first_row, first_col, last_row, last_col) sequence.

This is a little syntactic shortcut to help with worksheet layout.

worksheet_print_area(worksheet, 0, 0, 41, 10); // A1:K42.
// Same as:
worksheet_print_area(worksheet, RANGE("A1:K42"));
Examples
array_formula.c, conditional_format1.c, conditional_format2.c, dynamic_arrays.c, and tables.c.

Macros

#define CELL(cell)    lxw_name_to_row(cell), lxw_name_to_col(cell)
 Convert an Excel A1 cell string into a (row, col) pair. More...
 
#define COLS(cols)    lxw_name_to_col(cols), lxw_name_to_col_2(cols)
 Convert an Excel A:B column range into a (col1, col2) pair. More...
 
#define RANGE(range)
 Convert an Excel A1:B2 range into a (first_row, first_col, last_row, last_col) sequence. More...
 
workbook_close
lxw_error workbook_close(lxw_workbook *workbook)
Close the Workbook object and write the XLSX file.
lxw_version
const char * lxw_version(void)
Retrieve the library version.
lxw_strerror
char * lxw_strerror(lxw_error error_num)
Converts a libxlsxwriter error number to a string.
lxw_version_id
uint16_t lxw_version_id(void)
Retrieve the library version ID.
worksheet_print_area
lxw_error worksheet_print_area(lxw_worksheet *worksheet, lxw_row_t first_row, lxw_col_t first_col, lxw_row_t last_row, lxw_col_t last_col)
Set the print area for a worksheet.
lxw_unixtime_to_excel_date
double lxw_unixtime_to_excel_date(int64_t unixtime)
Converts a unix datetime to an Excel datetime number.
lxw_error
lxw_error
Error codes from libxlsxwriter functions.
Definition: common.h:65
RANGE
#define RANGE(range)
Convert an Excel A1:B2 range into a (first_row, first_col, last_row, last_col) sequence.
Definition: utility.h:82
COLS
#define COLS(cols)
Convert an Excel A:B column range into a (col1, col2) pair.
Definition: utility.h:63
lxw_datetime
Struct to represent a date and time in Excel.
Definition: common.h:155
worksheet_write_string
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.
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.
CELL
#define CELL(cell)
Convert an Excel A1 cell string into a (row, col) pair.
Definition: utility.h:45