We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Defining cell as date in spreadsheet

How can I set the cell in the worksheet as a date? Using setValue seems to define it as a string, which makes it hard for sorting in Excel.

3 Replies

MW Melba Winshia Syncfusion Team May 16, 2007 12:11 PM UTC

Hi Fenella,

Thanks for your interest in Essential XlsIO.

You can set the cell in the worksheet as Date by using Value property. Please refer the following code snippet to achieve this:

//Inserting Date into the first worksheet
sheet.Range["A1"].Value = "12/05/2005";
sheet.Range["A2"].Value = "11/05/2005";

Here is the sample for your reference:

http://websamples.syncfusion.com/samples/XlsIO.Windows/F60933/main.htm

Kindly let me know if you have any other questions.

Thanks,
Melba


AN Anonymous May 16, 2007 01:33 PM UTC

also you can use
DateTime value = DateTime.Now

sheet.Range[ "A1" ].DateTime = value;
sheet.Range[ "A2" ].Value2 = value;

or

sheet.Range[ "A1" ].Number = 100;
sheet.Range[ "A1" ].NumberFormat = "mm dd yyyy";// or any other date format


MW Melba Winshia Syncfusion Team May 17, 2007 10:32 AM UTC

Hi,

Yes, you can also use DateTime and Value2 property to set the cell in the worksheet as Date.

Kindly let me know if you have any other questions.

Thanks,
Melba

Loader.
Live Chat Icon For mobile
Up arrow icon