Date Time format for my excel sheet not calculating properly. RRS feed

  • Question

  • Hi,

    I am new to this DocumentFormat.openXML feature, my problem area is that i am unable to apply datetime format to a particular cell.

    My code for applying date time format is as follows:


     if (DateTime.TryParse(cellData.Text.ToString(), out dateValue))
                    DateTime epoch = new DateTime(1900, 1, 1);
                    TimeSpan diff = DateTime.Now.Subtract(epoch);
                    int number = Convert.ToInt32(diff.Days);
                    cellRange.StyleIndex = new UInt32Value(cellStyleIndex);
                    //Assign the datetime data to the cell.
                    cellRange.CellValue = new CellValue(number.ToString());


    my inserted date and the calculated date are very much different

    For example my date was 01/01/2009 where after calculating with this code it shows me 9/19/2010 which is wrong, what do i do to get the exact date in the cell which i am trying to insert.

    In the above code the cellData.Text has the datetime from which i am getting a output value in datetime format. the datetime variable is dateValue. i tried to Subtract with that date too but all in vain. it shows wrong date. please give me some suggestions as soon as possible. Any help will be deeply appreciated.


    I also have problems with double data which i want it to represent it as currency column. the digits look gud but $ sign is not applieed to the digit before it.

    Tuesday, September 21, 2010 2:25 PM