Set Custom datetime format for cell using Aspose.Cells for .NET in C#

Hi all,
I’m using Aspose Cell 19.2 and I try to set Custom format for cell but it not work.

Here is my code:

var workbook = new Workbook();
            Worksheet worksheet = workbook.Worksheets[0];
            Style style = workbook.CreateStyle();
            style.Custom = "dd/mm/yy";
            StyleFlag flag = new StyleFlag();
            flag.NumberFormat = true;
            Cell cell = worksheet.Cells["A1"];
            workbook.Worksheets[0].Cells.Columns[0].ApplyStyle(style, flag);
            cell.PutValue(DateTime.Today);

            worksheet.AutoFitColumns();
            workbook.Save("output.xlsx");

Thank and regard.

@DungLT,

Thanks for the sample code with details.

I tested your sample code to apply the custom formatting to A1 cell using our latest version/fix: Aspose.Cells for .NET v19.2, it works fine, see the attached output file for your reference.
files1.zip (6.3 KB)

Thanks for your reply,
But I used .Net and I has set ShortDate in my machine same image.
Pls check help me. Tks
Capture.PNG (3.6 KB)

@DungLT,

Sorry, I mistakenly wrote Aspose.Cells for Java v19.2.x, I actually used Aspose.Cells for .NET v19.2 which works fine. Did you open my file into MS Excel manually and see what date you are getting. Give us some screenshots of MS Excel when opening the file into it. Also what is your environment and regional settings, etc. Also give us a screenshot which should give your expected DateTime. Your issue might be due to your regional settings or locales. I use us-english locale and MS Excel English version to test your scenario/case.

Hi Amjad_Sahi,
My output and my setting date format here. It not work when I change ShortDate from setting
1.PNG (3.0 KB)
2.PNG (5.8 KB)
3.PNG (10.6 KB)

@DungLT,

In image 1.PNG, I can see the same output in Excel file as mine here. Could you please explain is image 1.PNG showing the expected output or the output obtained from the program in the first thread of this post? As per our understanding this is the output which is expected from the program and same is produced by the program. Please provide us more detail about the issue and comparison of the expected output and actual output for our reference.

@ahsaniqbalsidiqui
My format is dd/mm/yy, but after export date is dd-mm-yy :frowning:

@DungLT,
Thank you for contacting us again. We are working on this issue and will write back soon.

@DungLT,

I have tried this scenario using different customize format and got the same result as expected by you. It seems to be based on system configuration. Please try the settings as shown in the attached image and provide your feedback.

Customize Format.png (23.3 KB)