openxml sdk 2.0 (version 2.0.5022.0) inserting date in cell format with excel date format selection RRS feed

  • Question

  • Hi All,

    We are facing an issue related to date value. If we insert it as string it works fine but in the excel file the cell format is string

    Cell cell = new Cell() { CellReference = cellReference, DataType = CellValues.String };            
    cell.StyleIndex = 1;
    cell.CellValue = new CellValue(cellStringValue);

    So in order to change the cell format to date in excel file we have written the below code

    var c = new Cell { CellReference = cellReference, StyleIndex = 1 };
     var value = new CellValue { Text = cellStringValue.ToOADate().ToString() };
     c.DataType = CellValues.Number;

    Now the time we open the excel file a pop comes say the following (seems to be corrupted file)

    "Excel found unreadable content in 'sample.xlsx'. Do you wan to to recover the contents of this workbook? If you trust the the s source of this workbook click yes"

    Tuesday, November 24, 2020 1:21 PM