Set display format as date in the exported excel

Hi,

I have changed the display format to date in the excel and its working fine. In the exported sheet I could find the date field is dissplaying as dd-MMM-yyyy. But while doing the right click and go to format cell option, I can see see category displaying as General inspite of displaying as date which I already set in code. Because of which cannot be used directly for date related calculations in the extracts.

Style formatDate = new Style();
formatDate.Custom = “DD-MMM-YYYY”;
formatDate = StandardFormat(formatDate, false, string.Empty);

Range rangeD = worksheet.Cells.CreateRange(2, col, dtTrackerReport.Rows.Count, 1);
rangeD.ApplyStyle(formatDate, styleFlag1);

Thanks in advance.

Hi,

Thanks for providing us some details.

It looks like your so called datetime values are of string type, so you are seeing General category set when you right click on the cell to check the formatting in the dialog box. Please make sure that the value is DateTime in your datatable/data source, so when you import it to worksheet cells via Aspose.Cells APIs, they could be formatted fine.

Also, while creating Style object, please do use the following line of code to instantiate it:
e.g
Sample code:

..............
Style style = workbook.CreateStyle();

If you still could not evaluate or find the issue. Please create either a runnable sample code (complete) or provide a simple console demo application (runnable), zip it and provide us here with template files. Please use dynamic dataset/datatable in your code to remove any inter dependencies for external data source or database, so we could evaluate and run your test project fine.

Thank you.

Thanks Amjad for the response. It worked.

Hi,


Good to know that your issue is sorted out now. Feel free to write us back with details/sample project if you have other issue or queries, we will help you soon.

Thank you.