Problem with column.Style.Custom in Cells 4.4.3.0

Hi guys,

I’ve just upgraded from 4.4.0.20 to 4.4.3.0 and the col.Style.Custom doesn’t appear to work anymore.

Here’s the code I’ve been using. In this case, a DateTime column comes out in Excel as the numeric value instead of the formatted date time.

// Add date formatting for each DateTime column
for (int i = 0; i < dt.Columns.Count; i++)
{
DataColumn dc = dt.Columns[i];
if (dc.DataType.ToString() == “System.DateTime”)
{
Aspose.Cells.Column col = worksheet.Cells.Columns[i];
// col.Style.Number = 22; //22 = Time m/d/yy h:mm
col.Style.Custom = “mm/dd/yyyy hh:mm AM/PM”;
}
}

Thanks for looking into this.

this is how i custom format my date column

worksheet.Cells.Columns[idx].Style.Custom = “m/dd/yyyy”;

Hi,

Please use Cells.ApplyColumnStyle to apply style to column.

Please change your codes:

StyleFlag flag = new StyleFlag();
flag.NumberFormat = true;
int index = workbook.Styles.Add();
Style style = workbook.Styles[index];
style.Custom = "m/dd/yyyy";

for (int i = 0; i < dt.Columns.Count; i++)
{
DataColumn dc = dt.Columns[i];
if (dc.DataType.ToString() == "System.DateTime")
{
worksheet.Cells.ApplyColumnStyle(i, style, flag);

}
}

Thanks Warren. Works great.

Mike