Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Thu Jan 05, 2023 11:39 am

Hello,

I'm having some issues while trying to set a cell to a custom format ( "yyyy/mm/dd hh:mm:ss" )

This is what I tried so far but to no avail:

Code: Select all
sheetOne["A2"].NumberFormat = "yyyy/mm/dd hh:mm:ss"
sheetOne.Range[2,1].NumberFormat = "yyyy/mm/dd hh:mm:ss"
sheetOne["A2"].NumberFormat = "yyyy.mm.dd hh:mm:ss"


I'll keep trying, but in the meantime maybe you guys can help me with the solution!

Thank you!

IceVanis
 
Posts: 1
Joined: Thu Jan 05, 2023 11:33 am

Fri Jan 06, 2023 8:18 am

Hi,

Thanks for your inquiry.
You can use the following code to meet your requirement.
Code: Select all
            Workbook wb = new Workbook();
            Worksheet ws = wb.Worksheets[0];
            ws.Range["C10"].DateTimeValue = new DateTime(2023, 1, 6);
            ws.Range["C10"].NumberFormat = "yyyy/MM/dd HH:mm:ss";
            wb.SaveToFile("output.xlsx", ExcelVersion.Version2013);

In addition, yyyy: year, MM: month, dd: day, HH: hour, mm: minute, ss: second.
If you have any further questions, just feel free to contact us.

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.XLS

cron