Excel "dates" are doubles under the hood, and the XLOPER structure does not seem to have any concept of date, only xltypeNum (unlike Variants in VBA).
I have a simple XLL with a function that takes no arguments returns today's date as an LPXLOPER (type "P"). I have other functions that usually return dates but could also return errors which is why I am using "P" as the return value not "B".
DLLEXPORT LPXLOPER WINAPI epToday()
{
static XLOPER xResult;// Return value
xResult.xltype = xltypeNum;
xResult.val.num = ExcelDateForToday(); //A function that returns a double for today's date
return &xResult;
}
The return value appears in the calling spreadsheet as a number (eg 40303). I would like to be able to tell Excel to treat my returned double as a date: in the same way that the built-in function TODAY() does. Is there a way of doing this?
I see that =TODAY() changes the cell NumberFormat to "Date", should I be using a callback to change the format for the calling cell? This seems to be what Excel is doing: eg if I re-calc a cell with a =TODAY() function it again sets the NumberFormat to Date.