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

Free Support Forum - aspose.com

Excel dattime format doesn't get recognized

Hi,

I try to get a datetime format set in a cell.
I have this input (1990.05.15 22:23:15.000000000) from a third party porject.
this gets splited in year, month, day, hour, minute, second, millisecond. Now I try to create a datetime.

intrusive_ptr dt;
DateTime::TryCreate(year, month, day, hour, minute, second, millisecond, dt)

Then I set it to a cell, but the output is this (1990-05-15T20:23:15.000Z) and not datetime.
When I write manually in Excel (1990-05-15 20:23:15.00) I get de-DE (15.05.1990 20:23:15).
Is it possible to convert it, or is there another function which gives me the right format?

@Janosh,

Could you please share your sample code and template Excel file(s) to show the issue, we will check it soon.

PS. please zip the files prior attaching here.

@Amjad_Sahi

I’m sorry it is not possible to share the code, it is connected with a thir party software, and the code is confidential. I can pick some code lines, like in the first post, but not a sample code. I hope it is possible to help without.

@Janosh,

In MS Excel, when I enter “1990.05.15 22:23:15.000000000” into a cell (in the sheet), it gives me same value but as string. MS Excel does not detect it as DateTime format either.

The is due to your locale or regional setting of os on your end. When I enter “1990-05-15 20:23:15.00”, I get different format in MS Excel on my end.

Generally, Aspose.Cells works the same way as MS Excel does. We are not entirely sure about your issue, please elaborate with complete details. We would also need your template Excel files and sample snippet to reproduce the issue and need to check if it is different than what MS Excel produces. If you cannot provide your original project and tempalte file, then you may reproduce it in a separate project with some sample files (with dummy data) and provide us.

@Janosh
Hi,please try to set the region like this:

	intrusive_ptr<IWorkbook> wb = Factory::CreateIWorkbook();
	intrusive_ptr<IWorksheetCollection> wsc = wb->GetIWorksheets();
	intrusive_ptr<IWorksheet> ws = wsc->GetObjectByIndex(0);
	wb->GetISettings()->SetRegion(CountryCode::CountryCode_Germany);
	intrusive_ptr<ICells> cells = ws->GetICells();
	intrusive_ptr<ICell> cell = cells->GetObjectByIndex(0, 0);
	cell->PutValue(new String("1990.05.15 22:23:15.000000000"), true, true);
	StringPtr str = cell->GetStringValue();
	Console::WriteLine(str);

Hope, this helps a bit.