We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

I want to change cell style to Date style


Hi

My name is dongsoon park

I programed like below.
I want to change cell style to Date style.
But I can't get Date style, but I got custom style like picture.

What is problem?
I want to get Date style.
Please help me.

...
Cell cell = cells.get("A1");
cell.setValue(Calendar.getInstance());

Style style = cell.getStyle();
style.setNumber(15);
cell.setStyle(style);

...

Hi,


I have evaluated your scenario/ case a bit using the following sample code, it works fine and think this is expected behavior. Well, you will see your cell’s date formatting in Custom category as not all the Date styles can be shown in Date category.
e.g
Sample code:

Workbook workbook = new Workbook();

//Accessing the added worksheet in the Excel file
int sheetIndex = workbook.getWorksheets().add();
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex);
Cells cells = worksheet.getCells();

//Adding the current system date to “A1” cell
Cell cell = cells.get(“A1”);
cell.setValue(Calendar.getInstance());

//Setting the display format of the date to number 15 to show date as "d-mmm-yy"
Style style = cell.getStyle();
style.setNumber(15);
cell.setStyle(style);

//Saving the modified Excel file in default format
workbook.save(“output_1.xlsx”);

I have also attached the output Excel file for your reference.

Thank you.