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

Free Support Forum - aspose.com

Issue in date time field in EXcel

Hi,

I am using then following line of code to present date time field in mm/dd/yy. but showing in numbers like 80897

workSheet.Cells[cell + row.ToString()].PutValue(

Convert.ToDateTime(dataRow["SURVEY_DATE"].ToString()));

Style style = workSheet.Cells[cell + row.ToString()].GetStyle();

style.Number = 14;

workSheet.Cells[cell + row.ToString()].SetStyle(style);

pls provide me support on the same. thanks in advance.

Hi Vimlesh,


Thank you for contacting Aspose support.

If you wish to format the data according to a format that is not available as predefined formats then please use the Style.Custom property to set the format accordingly. Please check the below provided code snippet & its resultant spreadsheet.

C#

var book = new Workbook();
var workSheet = book.Worksheets[0];
workSheet.Cells[“A1”].PutValue(Convert.ToDateTime(“12-Dec-14”));
Style style = workSheet.Cells[0].GetStyle();
style.Custom = “dd/mm/yy”;
workSheet.Cells[“A1”].SetStyle(style);
book.Save(“D:/output.xlsx”);

Adding more, we have evaluated this case while using the latest version of Aspose.Cells for .NET 8.3.1. In case the problem persists with your current version of the API then please upgrade the API to latest revision.

Hi,


Please change the line of code:
i.e,
workSheet.Cells[cell + row.ToString()].PutValue(Convert.ToDateTime(dataRow[“SURVEY_DATE”].ToString()));

with:
workSheet.Cells[cell + row.ToString()].PutValue(Convert.ToDateTime(dataRow[“SURVEY_DATE”].ToString()), true);

it should work fine now

Let us know if you still find any issue.

Thank you.

Hi ,

I implemented the same code but get 6000 in date time filed. code is below

workSheet.Cells[

"A2"].PutValue(Convert.ToDateTime(dataRow["SURVEY_DATE"].ToString()));

Style style = workSheet.Cells["A2"].GetStyle();

style.Custom =

"dd/mm/yy";

workSheet.Cells[

"A2"].SetStyle(style);

please provide the support on the same.

Thanks

vimlesh Singh

Hi,


Did you try my suggestion in my previous post? please try it if possible.

It looks like an issue with your underlying “SURVEY_DATE” column’s values in your table. Well, we require your sample code (runnable) to evaluate your issue properly. We appreciate if you could provide us a sample code (runnable) same as Babar pasted in his previous post, or preferably a sample console application (runnable), zip it and post us here to reproduce the issue on our end. Please remove any interdependencies regarding data sources or data set, instead please use dynamic DataTable in your codes when creating the sample console application. Also attach the template files, we will check it soon.

Thank you.