When the run the below code:
Workbook book = new Workbook(FileFormatType.Xlsx);
Worksheet sheet = book.Worksheets[0];
Style style1 = book.CreateStyle();
StyleFlag flag = new StyleFlag();
style1.Custom = “m/d/yyyy h:mm”;
flag.NumberFormat = true;
sheet.Cells.ApplyColumnStyle(0, style1, flag);
sheet.Cells[“A1”].PutValue(“November 07, 2011”);
Style style = sheet.Cells[“A1”].GetStyle();
style.Number = 15;//d-mmm-yy
sheet.Cells[“A1”].SetStyle(style);
sheet.Cells[“A2”].PutValue(DateTime.Now);
book.Save(“sample.xlsx”);
I can find A2 getting updated with appropriate formats but A1 is not. When you manually select the column values, it gets reset & then formatting is applied.
Steps:
1) Open the attachment sample.xslx
2) Manually select values in A1
3) Now randomly click on any cell
4) Now you can find the values in A1 formatted
Let me know for further reference