How to get type of a Cell Value? Any API for that?

Posted by: nchalla on 22 November 2018, 1:31 am EST

  • Posted 22 November 2018, 1:31 am EST


    If I want to know the value type of a cell (like numeric, string, date ..etc) then how can I get that? Is there any API?

  • Marked as Answer

    Replied 25 November 2018, 6:29 pm EST


    You can fetch the data type related to cell values, using the Value.GetType method of IRange.
    You can learn about the Value property from here:
    The sample code is:

    var workbook = new Workbook();
    var sheet = workbook.Worksheets["Sheet1"];
    sheet.Range["A1"].Value = "Name";
    sheet.Range["A2"].Value = 123456789.9;
    sheet.Range["A3"].Value = new DateTime(2018, 11, 26);

    //Return cell value types
    Console.WriteLine("A1 Value Type:" + sheet.Range["A1"].Value.GetType());
    Console.WriteLine("A2 Value Type:" + sheet.Range["A2"].Value.GetType());
    Console.WriteLine("A3 Value Type:" + sheet.Range["A3"].Value.GetType());

    A sample implementing the same is attached for your reference.

    Best Regards,
Need extra support?

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

Learn More

Forum Channels