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

Free Support Forum - aspose.com

Setting date format to cells

Hi Team,

I need to customize the cells to Date Format as “dd/MM/yyyy”. I have found below code in Java… Can you please suggest the code in .Net / c#

JAVA Source Code:

Workbook wb = new Workbook();
wb.open(“C:\temp\testDateFormatsWorksheet.xls”);
WorkbookSettings setting = wb.getWorkbookSettings();
setting.setLocale(java.util.Locale.UK);
wb.save(“C:\temp\out.csv”,FileFormatType.CSV);

We know code which sets format of “dd/MM/yyyy” applying it cell wise in c# / . Net … But applying such way is taking too long time (which uses column and row for loop…)…So Please help us to set the same Style for entire worksheet and which reduces the performance issue…

And also code should be in such a way that it should always show in “dd/MM/yyyy” irrespective of the User Regional Settings…

Please help us on this ASAP… Thank you very much in advance…


Hi,


Well, I think you may use Style.Custom attribute to set your desired datetime style for your desired range of cells or columns/rows etc. See a code segment below, same technique will be used to set the style for the entire range e.g you may create a Range object (e.g A1:__) and then use Range.ApplyStyle() method in the same way.

Workbook wb = new Workbook(“e:\test2\Book1.xls”);
Worksheet sheet = wb.Worksheets[0];
Style style;
StyleFlag flag;
style = wb.Styles[wb.Styles.Add()];
style.Custom = “dd/MM/yyyy”;
flag = new StyleFlag();
flag.NumberFormat = true;
//Apply the style to entire first columns (A)
sheet.Cells.ApplyColumnStyle(0,style, flag);

wb.Save(“d:\test\customcolumnstyle.xls”);

Thank you.