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

Syncfusion.XlsIO Excel DateTime Format Still Displaying as a Number

Hello Syncfusion support,

I am attempting to convert a .NET 7.0 C# Datetime with hours to an Excel DateTime with

========================================

  • NuGet Client Project:
    • Syncfusion.XlsIO.Net.Core
      • 21.1.41
  • Blazor WASM Core Hosted .NET 7.0

 ========================================

C#:

using Syncfusion.XlsIO;

if (jobScan.ScanDate != null)
{
sheet1.Range[1, 1].DateTime = jobScan.ScanDate ?? new DateTime();
}
sheet1.Range[1, 1].NumberFormat = "mm/dd/yyyy hh:mm";


However, it still displays as a numerical format when the Excel file is opened. Additionally, once opened if you set the Number Format on the target column it displays the date as intended.

ScanDate
44847

Please advise!

Thanks, Mike


3 Replies

KK Konduru Keerthi Konduru Ravichandra Raju Syncfusion Team May 2, 2023 01:04 PM UTC

Hi Mike,


From the code snippet that you have shared with us, we found that you are trying to set the number format for the Excel cell "A1". But from the screenshot, we could see that the cell is not "A1". There is a match in the cells.


Kindly share the entire code snippet, input Excel document if any, and output Excel document, to investigate the query further.


Regards,

Keerthi.



MV Mike Vinson May 3, 2023 09:06 AM UTC

My apologies for the image not matching the code.


...
ExcelEngine excelEngine = new ExcelEngine();
//Step 2 : Instantiate the excel application object.
IApplication application = excelEngine.Excel;


#region Generate Excel
Creating new workbook
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet1 = workbook.Worksheets[0];
sheet1.Name = "EventReport";
sheet1.IsGridLinesVisible = false;
sheet1.EnableSheetCalculations();
sheet1.PageSetup.IsSummaryRowBelow = false;



sheet1.Range[4, 4].NumberFormat = "mm/dd/yyyy hh:mm";
if (jobScan.ScanDate != null)
{
sheet1.Range[4, 4].DateTime = DateTime.Now;
}


workbook.Version = ExcelVersion.Excel2016;
DateTime currentTime = DateTime.Now;

string fileName = $"EventReport.xlsx";
MemoryStream ms = new MemoryStream();

workbook.SaveAs(ms);
ms.Position = 0;
return ms.ToArray();
...





KK Konduru Keerthi Konduru Ravichandra Raju Syncfusion Team May 11, 2023 06:44 AM UTC

Mike, we are unable to reproduce the reported issue. The sample tried at our end can be downloaded from the below link.

https://www.syncfusion.com/downloads/support/directtrac/general/ze/EditExcel-565297237.zip


Kindly, modify and share the issue reproducing sample, to investigate the query further. Also, please confirm your system culture.


Loader.
Up arrow icon