I have an excel template(attached) with C6:N6 as Custom Date Format set to mmm-yy.
Using Aspose.cells, populating the value in those cells as below.
for (Int32 inc = 0; inc < 12; inc++) {
Range range0 = cells.CreateRange(collbl2[inc] + (initoff - 1));
range0.Value = (inc + 1) + “/1/” + DateTime.Now.Year;
}
After generating the excel, if i open and see the columns, they are showing as 01/01/2022, 02/01/2022…Formatting didnt apply. If i just double click the column, then the formatting applies automatically.
DateTime values are stored/inserted as numeric notation in MS Excel. I checked those values in the range of cells (C6:N6) and these are inserted as string/text instead of numeric values. So, you cannot apply formatting to the cells. You need to convert those values as numeric notations instead of string. When you double click in the cell, MS Excel just converts to numeric values. For your needs, you may convert to values to numeric values while inserting your DateTime data. See the updated sample code that you may try:
e.g. Sample code:
Good to know that your issue is sorted out now. Feel free to contact us any time if you have further queries or issue, we will be happy to assist you soon.