No Matches
<< dates_and_times02.c dates_and_times04.c >>

Example of writing dates and times in Excel using Unix datetimes and formatting.

* Example of writing dates and times in Excel using a Unix datetime and date
* formatting.
* Copyright 2014-2021, John McNamara,
#include "xlsxwriter.h"
int main() {
/* Create a new workbook and add a worksheet. */
lxw_workbook *workbook = workbook_new("date_and_times03.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
/* Add a format with date formatting. */
lxw_format *format = workbook_add_format(workbook);
format_set_num_format(format, "mmm d yyyy hh:mm AM/PM");
/* Widen the first column to make the text clearer. */
worksheet_set_column(worksheet, 0, 0, 20, NULL);
/* Write some Unix datetimes with formatting. */
/* 1970-01-01. The Unix epoch. */
worksheet_write_unixtime(worksheet, 0, 0, 0, format);
/* 2000-01-01. */
worksheet_write_unixtime(worksheet, 1, 0, 1577836800LL, format);
/* 1900-01-01. */
worksheet_write_unixtime(worksheet, 2, 0, -2208988800LL, format);
return workbook_close(workbook);
void format_set_num_format(lxw_format *format, const char *num_format)
Set the number format for a cell.
Struct to represent the formatting properties of an Excel format.
Definition: format.h:359
Struct to represent an Excel workbook.
Definition: workbook.h:293
Struct to represent an Excel worksheet.
Definition: worksheet.h:2108
lxw_workbook * workbook_new(const char *filename)
Create a new workbook object.
lxw_format * workbook_add_format(lxw_workbook *workbook)
Create a new Format object to formats cells in worksheets.
lxw_error workbook_close(lxw_workbook *workbook)
Close the Workbook object and write the XLSX file.
lxw_worksheet * workbook_add_worksheet(lxw_workbook *workbook, const char *sheetname)
Add a new worksheet to a workbook.
lxw_error worksheet_write_unixtime(lxw_worksheet *worksheet, lxw_row_t row, lxw_col_t col, int64_t unixtime, lxw_format *format)
Write a Unix datetime to a worksheet cell.
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.