Neenarg
Guest
|
Using ADX2008, VS2005
I must be missing something obvious but I am trying to to get a date from a cell in excel and place a date based on that date (plus 5 days for example).
I have tried innumerable variations of the following but I always seem to get an error and can not work out how the code should be..
The error I get from the following is "Conversion from type 'Range' to type 'Date' is not valid."
wksheet is my worksheet, c is a row reference in a for x = 1 to y loop. dateposted is based on a string which is a UK format date.
Dim dateposted as Date
dateposted = CDate(wksheet.Cells(c, 6)).AddDays(5)
wksheet.Cells(c, 13).value = dateposted.ToShortDateString
Is it a problem with the original date cell ? Any suggestions? |
|
Neenarg
Guest
|
I just read something about the date format in COM objects not being compatible with .NET
Something to do with converting them to a double, and using .ToOADate - anybody know how to do this in ADX? (add n days to a UK format date string)
Thanks,
Trevor |
|
Sergey Grischenko
Add-in Express team
Posts: 7233
Joined: 2004-07-05
|
Hi Trevor.
private void adxCommandBarButton1_Click(object sender)
{
Excel.Worksheet sheet =
ExcelApp.ActiveSheet as Excel.Worksheet;
object date = (sheet.Cells[1, 1] as Excel.Range).Value2;
if (date is double)
{
DateTime dateValue = DateTime.FromOADate((double)date);
dateValue = dateValue.AddDays(5);
}
}
|
|
Neenarg
Guest
|
Thats perfect! Thanks Sergey! |
|