Resize: having one column in date format

Dec 13, 2012 at 7:59 AM

Hello

I am coding an excel-dna add-in in C#. The user enter some parameters and the excelFunction return an array of result by calling XlCall.Excel(XlCall.xlUDF, "Resize" , output);

The fact is that some cells are dates and from now, I format them by returning a string. In excel, the type is "general". The users need these cells to be in "date" format. I tried to return directly the DateTime but I got only a number.

I tried to find a solution (even a workaround) but don't find anyone.

Do you have any idea to help me?

Thank you

Loïc

Coordinator
Dec 14, 2012 at 8:25 AM

Hi Loïc,

Returning a DateTime is certainly the right thing to do. The numbers you see are the correct Excel representation for the dates.

Maybe your users could just reformat those cells to a date format (by pressing Ctrl+Shift+#).

You could also make a custom version of the Resize function that also applies formatting to the target range, but that's a bit more work to figure out.

-Govert

Dec 14, 2012 at 2:54 PM

Hello Govert and thank you for your answer.

I am not afraid of working a little more so if it's not too difficult to explain, please, tell me more about the long way :)

 

Coordinator
Dec 14, 2012 at 3:15 PM

Hi Loïc,

Well, you'd have to poke around in the resizer code, and where the target formulae are set you might also examine the array and set the target region's numeric formats according to the array contents.

-Govert

Dec 14, 2012 at 3:27 PM

ok thanks, I think I need to take a look before bothering you again :)