libxlsxwriter
Loading...
Searching...
No Matches
Functions | Macros
utility.h File Reference

Description

Functions

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

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());
const char * lxw_version(void)
Retrieve the library 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());
uint16_t lxw_version_id(void)
Retrieve the library 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));
lxw_error
Error codes from libxlsxwriter functions.
Definition: common.h:66
char * lxw_strerror(lxw_error error_num)
Converts a libxlsxwriter error number to a string.
lxw_error workbook_close(lxw_workbook *workbook)
Close the Workbook object and write the XLSX file.

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);
Struct to represent a date and time in Excel.
Definition: common.h:159

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);
double lxw_unixtime_to_excel_date(int64_t unixtime)
Converts a unix datetime to an Excel datetime number.

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);
#define CELL(cell)
Convert an Excel A1 cell string into a (row, col) pair.
Definition: utility.h:46
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.
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, embed_image_buffer.c, embed_images.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);
#define COLS(cols)
Convert an Excel A:B column range into a (col1, col2) pair.
Definition: utility.h:64
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.
Examples
dynamic_arrays.c, embed_images.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"));
#define RANGE(range)
Convert an Excel A1:B2 range into a (first_row, first_col, last_row, last_col) sequence.
Definition: utility.h:83
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.
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.
 
#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.
 
#define RANGE(range)
 Convert an Excel A1:B2 range into a (first_row, first_col, last_row, last_col) sequence.