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

Free Support Forum - aspose.com

Apply date format to whole column

Hi,

I am using Aspose Cells for JAVA.
I am trying to set custom format : yyyy-mm-dd to a column.

Here is my code:
Style columnStyle = ws.getCells().getColumns().get(1).getStyle();
String customFormat = “yyyy-mm-dd”;
columnStyle.setCustom(customFormat);
StyleFlag columnStyleFlag = new StyleFlag();
ws.getCells().getColumns().get(1).applyStyle(columnStyle, columnStyleFlag);

But after exporting the file, the date custom format is not set.

@sandipanghosh111,

Please try the following sample code (see the line in bold especially), it should work fine:
e.g
Sample code:


Style columnStyle = ws.getCells().getColumns().get(1).getStyle();
String customFormat = “yyyy-mm-dd”;
columnStyle.setCustom(customFormat);
StyleFlag columnStyleFlag = new StyleFlag();
columnStyleFlag.setNumberFormat(true);
ws.getCells().getColumns().get(1).applyStyle(columnStyle, columnStyleFlag);

Hope, this helps a bit.