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 Sep 23, 2021 7:29 am

Hello there !

As the title says, I'd like to set a specific datetime format for a specific range of cells.
I've found 1 topic talking about it, but it doesn't work completely.

Here is what I have in my column cells : 01/01/2000 00:00
Here is what I want : 2000-01-01 00:00:00

And here is what I've tried so far :

Code: Select all
               
                Workbook workbook = new Workbook();
                workbook.LoadFromFile(Inputfile);
                Worksheet sheet = workbook.Worksheets[0];


                Inputfile = Path.ChangeExtension(Inputfile, ".csv");

                sheet.Columns[2].NumberFormat = "yyyy-mm-dd hh:mm:ss";
                sheet.SaveToFile(Inputfile, ";", Encoding.UTF8);

                sheet.SaveToFile(Inputfile, ";", Encoding.UTF8);


The problem is always near "-" in the datetime format that doesn't seem to be applied. So I've tried multiple things but it never worked.
I also tried to use :
sheet.Columns[2].TextPartReplace(".", "-");

But I always have dots instead of what I want and the seconds are not always here.


Thanks

styattia
 
Posts: 1
Joined: Wed Sep 22, 2021 12:54 pm

Thu Sep 23, 2021 8:52 am

Hello,

Thanks for your inquiry.
The number format of data in the excel file will be related to the region settings of your system. Please provide your input file and your region setting to help us do further investigation. You can send them to us (support@e-iceblue.com) via email. Thanks in advance for your assistance.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Return to Spire.XLS