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

    Hi,

    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?

    Thanks.
  • Marked as Answer

    Replied 25 November 2018, 6:29 pm EST

    Hello,

    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:
    http://help.grapecity.com/gcdocs/gcexcel/onlinehelp/webframe.html#GrapeCity.Documents.Excel~GrapeCity.Documents.Excel.IRange~Value.html
    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);

    workbook.Save("NewWorkbook.xlsx");
    //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,
    Esha
    prj_GcExcel_CellDataType.zip
Need extra support?

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

Learn More

Forum Channels