We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Datetime convertion in excel sheet

Hi,


I want to convert string cell values to Datetime cell values in the same column.

For ex : My column contains below data:
Apple
Ball
2/1/12
4:59 PM
3/1/12 5:30 PM
Cat
Dog

i need to convert row 3 & 4 in datetime format and other’s in string format.

Hi,

Thanks for your posting and considering Aspose.Cells.

Please use the following code to convert the string type into Excel date format.

Please see the screenshot and the output file generated by this code (attached).

C#


Workbook workbook = new Workbook();

Worksheet worksheet = workbook.Worksheets[0];


Cell cell = worksheet.Cells[“A1”];

cell.PutValue(“2/1/12 4:59 PM”);


Style style = cell.GetStyle();

style.Number = 14; //try numbers from 14-22

cell.SetStyle(style);


workbook.Save(@“F:\Shak-Data-RW\Downloads\output.xlsx”);


Screenshot

Hi,

There are two methods that depends on type of your requirements.

If your requirement is that you want to convert existing cell’s string
value to datetime, please use the code provided by me and make a bit change:


cell.PutValue(“2/1/12 4:59 PM”, true);


If your requirement is that you are loading data from CSV file, please use

TxtLoadOptions.ConvertDateTimeData = true;