Free Support Forum -

ImportDataTable- Designer and Column.Style.Custom Bug


I am using Cells.ImportDataTable() to import data from a database, which works fine. For columns containing date/time values, I would like to set an appropriate cell format, using Cells.Columns[3].Style.Custom="MM/dd/yyyy". Again, doing so is not a problem, as long as the worksheet was added to the workbook using Worksheets.Add(). However, when using a designer template file (Worksheets.Open("template.xls")), the formatting of the date/time columns shows absolutely no effect: instead of date/time values, Excel displays the corresponding numeric values, e.g. 38685 instead of 11/29/2005.

Here is some sample code to verify the problem; see the attachment for the designer file being used.

//generate some sample data
DataTable dt = new DataTable();
dt.Columns.Add("DateValue", typeof(DateTime));
dt.Rows.Add(new object[] {DateTime.Now});
dt.Rows.Add(new object[] {DateTime.Now.AddDays(1)});
dt.Rows.Add(new object[] {DateTime.Now.AddDays(2)});

Excel xls = new Excel();
xls.Open("template.xls"); //open designer file; if you comment this out, everything will work perfectly.

xls.Worksheets[0].Cells.ImportDataTable(dt, true, 0, 0); //import data
xls.Worksheets[0].Cells.Columns[0].Style.Custom = "MM/dd/yyyy"; //set date/time format; this will not show any effect

xls.Worksheets[0].Cells[0,10].PutValue(DateTime.Now); //import data
xls.Worksheets[0].Cells.Columns[10].Style.Custom = "MM/dd/yyyy"; //set date/time format; this is going to work, because PutValue was used instead of ImportDataTable

Thank you in advance!

Stefan Raffeiner

Hi Stefan,

Please try this attached fix.

Hi Laurence,

thank you for the fast reply; first tests with the new version were promising!

Is it normal that v3.5.3.4 is only about 770KB, whereas v3.5.3.0 was 916KB in size?



We use obfuscator to protect our product and changed one option of while obfuscating. That decreased the dll size.