dateTimeCell.UserDefinedFormat = "HH:mm:ss.fff"; does not work!

Posted by: peteryfang on 1 October 2017, 4:47 am EST

    • Post Options:
    • Link

    Posted 1 October 2017, 4:47 am EST

    Hello, I am using Spread studio 8 for winForm, the custom format for date time cell does not work for me.

    var dateTimeCell = new CellType.DateTimeCellType();

    dateTimeCell.DateTimeFormat = CellType.DateTimeFormat.UserDefined;

    dateTimeCell.UserDefinedFormat = “HH:mm:ss.fff”;

    Any idea?

    Thanks a lot!

    Peter

  • Posted 4 October 2017, 2:21 am EST

    Hello,

    You can use the code below to make the custom date format working:

    private void button1_Click(object sender, EventArgs e)

    {

    String FromDate = ((DateTime)(fpSpread1.ActiveSheet.Cells[0, 0].Value)).ToString(“yyyy-MM-dd HH:mm:ss.fff”, System.Globalization.CultureInfo.InvariantCulture);

    FarPoint.Win.Spread.CellType.DateTimeCellType dt = new FarPoint.Win.Spread.CellType.DateTimeCellType();

    dt.DateTimeFormat = FarPoint.Win.Spread.CellType.DateTimeFormat.UserDefined;

    dt.UserDefinedFormat = FromDate;

    fpSpread1.ActiveSheet.Cells[0, 0].CellType = dt;

    fpSpread1.ActiveSheet.Cells[0, 0].Value = System.DateTime.Now;

    fpSpread1.ActiveSheet.Columns[0].Width = 130;

    }

    I hope it helps.

    Thanks,

    Deepak Sharma

  • Posted 4 October 2017, 10:13 pm EST

    Hello,

    We are able to replicate the issue and hence we are escalating the same to the concerned team for the fix.

    Tracking id for the issue is #246839

    We will update you as soon as we hear anything from our concerned team.

    Thanks,

    Reeva

  • Posted 8 October 2017, 6:14 pm EST

    Hello,

    1. This case is not bug of Spread. We only support below list for datetime format:-
            char[] dateChars = { 'd', 'M', 'y' };
            char[] timeChars = { 'h', 'm', 's' };
    
    

    Although .Net support more datetime format like:- F, f, g, t, z but Spread don’t support them directly. If you want to use these formats then please use the workaround below:-

    FarPoint.Win.Spread.CellType.DateTimeCellType dt = new FarPoint.Win.Spread.CellType.DateTimeCellType();
          dt.DateTimeFormat = FarPoint.Win.Spread.CellType.DateTimeFormat.UserDefined;
          dt.UserDefinedFormat = "";
          fpSpread1.ActiveSheet.Cells[0, 0].CellType = dt;
          fpSpread1.ActiveSheet.Columns[0].Width = 130;
          fpSpread1.ActiveSheet.Cells[0, 0].Value = System.DateTime.Now;
          String FromDate = ((DateTime)(fpSpread1.ActiveSheet.Cells[0, 0].Value)).ToString("HH:mm:ss.fff");
          dt.UserDefinedFormat = FromDate;
    
    

    Hope it helps.

    Thanks,

    Reeva

Need extra support?

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

Learn More

Forum Channels