BoldSignA modern eSignature application with affordable pricing. Sign up today for unlimited document usage!
Hello Syncfusion support,
I am attempting to convert a .NET 7.0 C# Datetime with hours to an Excel DateTime with
========================================
========================================
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
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.
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();
...
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.