Reading and writing date/time values

This examples shows how to read and write date/time values.

#include "libxl.h"
#include <iostream>

using namespace libxl;

int main() 
{
    Book* book = xlCreateBook();    

    Format* format1 = book->addFormat();
    format1->setNumFormat(NUMFORMAT_DATE);

    Format* format2 = book->addFormat();
    format2->setNumFormat(NUMFORMAT_CUSTOM_MDYYYY_HMM);

    Format* format3 = book->addFormat();
    format3->setNumFormat(book->addCustomNumFormat(L"d mmmm yyyy"));

    Format* format4 = book->addFormat();
    format4->setNumFormat(NUMFORMAT_CUSTOM_HMM_AM);
       
    Sheet* sheet = book->addSheet(L"Sheet1");

    if(sheet)
    {   
        sheet->setCol(1, 1, 15);

        // writing

        sheet->writeNum(2, 1, book->datePack(2010, 3, 11), format1);       
        sheet->writeNum(3, 1, book->datePack(2010, 3, 11, 10, 25, 55), format2);
        sheet->writeNum(4, 1, book->datePack(2010, 3, 11), format3);       
        sheet->writeNum(5, 1, book->datePack(2010, 3, 11, 10, 25, 55), format4);

        // reading

        int year, month, day;
        book->dateUnpack(sheet->readNum(2, 1), &year, &month, &day);
        std::cout << year << "-" << month << "-" << day << std::endl;
            
        int hour, min, sec;
        book->dateUnpack(sheet->readNum(3, 1), &year, &month, &day, &hour, &min, &sec);
        std::cout << year << "-" << month << "-" << day << " " 
                  << hour << ":" << min << ":" << sec << std::endl;
    }

    book->save(L"datetime.xls");
    book->release();

    return 0;
}