C1Excel Format column as Date

Posted by: paul on 10 February 2019, 10:14 pm EST

    • Post Options:
    • Link

    Posted 10 February 2019, 10:14 pm EST

    Hi,

    I am trying to export the contents of a list view into excel but am having trouble formatting a column as a date. Everything I have tried formats the cells as general but displays the date as a number.

    Can anyone point me in the direction of the correct style format syntax to use?

    Thanks

    Paul

  • Posted 11 February 2019, 3:38 pm EST

    Hi Paul,

    You can Format property of the XLColumn’s Style:

    C1.C1Excel.C1XLBook workbook = new C1.C1Excel.C1XLBook();
    workbook.Sheets.Clear();
    var worksheet = workbook.Sheets.Add("Sheet1");
    
    var column = worksheet.Columns.Add();
    column.Width = C1.C1Excel.C1XLBook.PixelsToTwips(100);
    column.Style = new C1.C1Excel.XLStyle(workbook);
    column.Style.Format = "MM-dd-yyyy";
    
    DateTime date = DateTime.Now;
    for (int i = 0; i < 10; ++i)
    {
        worksheet[i, 0].Value = date;
        date = date.AddDays(1);
    }
    

    Regards,

    Jitender

  • Posted 11 February 2019, 7:40 pm EST

    Hi Jitender,

    Many thanks for your reply, this works great

    Paul

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels