libxlsxwriter/include/xlsxwriter/utility.h in fast_excel-0.4.1 vs libxlsxwriter/include/xlsxwriter/utility.h in fast_excel-0.5.0

- old
+ new

@@ -1,25 +1,27 @@ /* * libxlsxwriter * - * Copyright 2014-2019, John McNamara, jmcnamara@cpan.org. See LICENSE.txt. + * Copyright 2014-2022, John McNamara, jmcnamara@cpan.org. See LICENSE.txt. */ /** * @file utility.h * * @brief Utility functions for libxlsxwriter. * - * <!-- Copyright 2014-2019, John McNamara, jmcnamara@cpan.org --> + * <!-- Copyright 2014-2022, John McNamara, jmcnamara@cpan.org --> * */ #ifndef __LXW_UTILITY_H__ #define __LXW_UTILITY_H__ #include <stdint.h> +#ifndef _MSC_VER #include <strings.h> +#endif #include "common.h" #include "xmlwriter.h" /** * @brief Convert an Excel `A1` cell string into a `(row, col)` pair. @@ -100,10 +102,24 @@ * */ const char *lxw_version(void); /** + * @brief Retrieve the library version ID. + * + * @return The version ID. + * + * Get the library version such as "X.Y.Z" as a XYZ integer. + * + * @code + * printf("Libxlsxwriter version id = %d\n", lxw_version_id()); + * @endcode + * + */ +uint16_t lxw_version_id(void); + +/** * @brief Converts a libxlsxwriter error number to a string. * * 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. @@ -153,15 +169,57 @@ lxw_row_t first_row, lxw_col_t first_col, lxw_row_t last_row, lxw_col_t last_col); uint32_t lxw_name_to_row(const char *row_str); uint16_t lxw_name_to_col(const char *col_str); + uint32_t lxw_name_to_row_2(const char *row_str); uint16_t lxw_name_to_col_2(const char *col_str); -double lxw_datetime_to_excel_date(lxw_datetime *datetime, uint8_t date_1904); +/** + * @brief Converts a #lxw_datetime to an Excel datetime number. + * + * @param datetime A pointer to a #lxw_datetime struct. + * + * @return A double representing an Excel datetime. + * + * The `%lxw_datetime_to_excel_datetime()` function converts a datetime in + * #lxw_datetime to an Excel datetime number: + * + * @code + * lxw_datetime datetime = {2013, 2, 28, 12, 0, 0.0}; + * + * double excel_datetime = lxw_datetime_to_excel_date(&datetime); + * @endcode + * + * See @ref working_with_dates for more details on the Excel datetime format. + */ +double lxw_datetime_to_excel_datetime(lxw_datetime *datetime); +double lxw_datetime_to_excel_date_epoch(lxw_datetime *datetime, + uint8_t date_1904); + +/** + * @brief Converts a unix datetime to an Excel datetime number. + * + * @param unixtime Unix time (seconds since 1970-01-01) + * + * @return A double representing an Excel datetime. + * + * The `%lxw_unixtime_to_excel_date()` function converts a unix datetime to + * an Excel datetime number: + * + * @code + * double excel_datetime = lxw_unixtime_to_excel_date(946684800); + * @endcode + * + * See @ref working_with_dates for more details. + */ +double lxw_unixtime_to_excel_date(int64_t unixtime); + +double lxw_unixtime_to_excel_date_epoch(int64_t unixtime, uint8_t date_1904); + char *lxw_strdup(const char *str); char *lxw_strdup_formula(const char *formula); size_t lxw_utf8_strlen(const char *str); @@ -172,18 +230,22 @@ #define lxw_strcasecmp _stricmp #else #define lxw_strcasecmp strcasecmp #endif -FILE *lxw_tmpfile(char *tmpdir); +FILE *lxw_tmpfile(const char *tmpdir); +FILE *lxw_get_filehandle(char **buf, size_t *size, const char *tmpdir); +FILE *lxw_fopen(const char *filename, const char *mode); -/* Use a user defined function to format doubles in sprintf or else a simple - * macro (the default). */ -#ifdef USE_DOUBLE_FUNCTION +/* Use the third party dtoa function to avoid locale issues with sprintf + * double formatting. Otherwise we use a simple macro that falls back to the + * default c-lib sprintf. + */ +#ifdef USE_DTOA_LIBRARY int lxw_sprintf_dbl(char *data, double number); #else #define lxw_sprintf_dbl(data, number) \ - lxw_snprintf(data, LXW_ATTR_32, "%.16g", number) + lxw_snprintf(data, LXW_ATTR_32, "%.16G", number) #endif uint16_t lxw_hash_password(const char *password); /* *INDENT-OFF* */