i am binding an excel coloumn using c#.I need to bind the date coloumn in my excel.There is a constant year alredy in my excel cell like 1980. I need to append random "mm/dd "to it.I am using Microsoft.Office.Interop.Excel here. i have tried the following code but it lost the constant year value.how can i fix? My cell format in excel is General.I tried diffrent formath though. i am getting like 8/6/System.__ComObject instead of 08/06/1
for (int i = 2; i <= totalRows; i++) { xlWorksheet.Cells[i, 8] = GenerateRandomDates()+ xlWorksheet.Cells[i, 8] ; //not working expected 02/03/1980 } public string GenerateRandomDates() { DateTime start = new DateTime(1995, 1, 1); int range = (DateTime.Today - start).Days; DateTime dt = start.AddDays(gen.Next(range)); int month = dt.Month; int day = dt.Day; string formatted = string.Format("{0}/{1}/", month, day); return formatted; }
xlWorksheet.Cells[i, 8] = GenerateRandomDates()+ xlWorksheet.Cells[i, 8].Value;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)