Griddesktop formatting date to mm/dd/yyyy

I have tried the code below (using the forums to get suggestions).

I have a datetime in my datatable and have imported the data to a grid.
Now I am trying to set the format for the datetime to show only the date.

The below custom code doesn't do the job. Is there something I am missing?

Style st = new Style(gridDesktop1);
//st.NumberFormat = 14;
st.Custom = "mm/dd/yyyy";
sheet.Columns[1].SetStyle(st);

Hi,

Well, I tried your scenario and used the following code with the latest version of GridDesktop and it works fine. The date format is applied fine.

Sample code:

DataTable dt = new DataTable(“MyTable”);
dt.Columns.Add(“NAME”);
dt.Columns.Add(“ODATE”, typeof(System.DateTime));
dt.Columns.Add(“COMPOSITION_MAX”, typeof(decimal));
DataRow dr = dt.NewRow();
dr[“NAME”] = “Alpha”;
dr[“ODATE”] = DateTime.Now;
dr[“COMPOSITION_MAX”] = 2.13;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[“NAME”] = “Alpha1”;
dr[“ODATE”] = Convert.ToDateTime(“11-10-09”);
dr[“COMPOSITION_MAX”] = 1.3453;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[“NAME”] = “Alpha2”;
dr[“ODATE”] = Convert.ToDateTime(“10/12/08”);
dr[“COMPOSITION_MAX”] = 2424.44;
dt.Rows.Add(dr);


Worksheet sheet = GridDesktop.Worksheets(0);
sheet.ImportDataTable(dt, false, 0, 0);

Style st = new Style(GridDesktop);
st.Custom = “mm/dd/yyyy”;
sheet.Columns[1].SetStyle(st);



Which version of the product you are using? Kindly try the latest version installing the new Aspose.Cells for .NET msi installer and get/use the control’s dll from the installation folder (Aspose.Cells.GridDesktop): http://www.aspose.com/community/files/51/.net-components/aspose.cells-for-.net/entry231670.aspx


If you still find the issue, kindly create a sample application to show the issue, we will check it soon.

Thank you.

I have figured out the problem but don’t have a solution: I am using this code to make gridlines:

This is interfering with the column style. Is there a way to get both?

CellRange sr = new CellRange();
sr.StartRow = 0;
sr.EndRow = 1000;
sr.StartColumn = 0;
sr.EndColumn = 100;
Style sty1 = new Style(gridDesktop1);

sty1.SetBorderLine(BorderType.Left, BorderLineType.Thin);
sty1.SetBorderColor(BorderType.Left, System.Drawing.Color.Gray);
sty1.SetBorderLine(BorderType.Right, BorderLineType.Thin);
sty1.SetBorderColor(BorderType.Right, System.Drawing.Color.Gray);
sty1.SetBorderLine(BorderType.Top, BorderLineType.Thin);
sty1.SetBorderColor(BorderType.Top, System.Drawing.Color.Gray);
sty1.SetBorderLine(BorderType.Bottom, BorderLineType.Thin);
sty1.SetBorderColor(BorderType.Bottom, System.Drawing.Color.Gray);

Hi,

Well, I think instead of creating a new Style object, you may get an existing style/formatting and change/add additional formatting attributes. See the sample code below, I have tested and it works fine.
Sample code:

DataTable dt = new DataTable(“MyTable”);
dt.Columns.Add(“NAME”);
dt.Columns.Add(“ODATE”, typeof(System.DateTime));
dt.Columns.Add(“COMPOSITION_MAX”, typeof(decimal));
DataRow dr = dt.NewRow();
dr[“NAME”] = “Alpha”;
dr[“ODATE”] = DateTime.Now;
dr[“COMPOSITION_MAX”] = 2.13;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[“NAME”] = “Alpha1”;
dr[“ODATE”] = Convert.ToDateTime(“11-10-09”);
dr[“COMPOSITION_MAX”] = 1.3453;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[“NAME”] = “Alpha2”;
dr[“ODATE”] = Convert.ToDateTime(“10/12/08”);
dr[“COMPOSITION_MAX”] = 2424.44;
dt.Rows.Add(dr);


Worksheet sheet = GridDesktop.Worksheets(0);
sheet.ImportDataTable(dt, false, 0, 0);

Style st = new Style(GridDesktop);
st.Custom = “mm/dd/yyyy”;
sheet.Columns[1].SetStyle(st);


CellRange sr = new CellRange();
sr.StartRow = 0;
sr.EndRow = 10;
sr.StartColumn = 1;
sr.EndColumn = 1;
Style sty1 = sheet.Columns[1].GetStyle();

sty1.SetBorderLine(BorderType.Left, BorderLineType.Thin);
sty1.SetBorderColor(BorderType.Left, System.Drawing.Color.Gray);
sty1.SetBorderLine(BorderType.Right, BorderLineType.Thin);
sty1.SetBorderColor(BorderType.Right, System.Drawing.Color.Gray);
sty1.SetBorderLine(BorderType.Top, BorderLineType.Thin);
sty1.SetBorderColor(BorderType.Top, System.Drawing.Color.Gray);
sty1.SetBorderLine(BorderType.Bottom, BorderLineType.Thin);
sty1.SetBorderColor(BorderType.Bottom, System.Drawing.Color.Gray);

sheet.SetStyle(sr, sty1);




Thank you.