Formatting a cell in excel sheet

In my dataset one DateTime column is there…while iam trying to import this dataset into excel using aspose.cells it is importing datetime column as integer …i want tht column in datetime format

Hi,

You should format your entire column in date format. Please see these documents for further reference:

Setting Display Formats of Numbers & Dates
Applying Style on a Row or Column

Please also try the latest version:
Aspose.Cells for .NET (Latest Version)
and see if it works fine without the need of above articles.

body { margin: 0 0 0 0; padding:0 0 0 0 } td,div { font-family:Tahoma;font-size:8pt;vertical-align:top } body { margin: 0 0 0 0; padding:0 0 0 0; overflow:hidden; } .transcript { background-color:#d2d2d2; } .messageBlock { margin-left:4px; margin-bottom:3px } .message { margin-left:100px; word-wrap:break-word; white-space:-moz-pre-wrap; _white-space:pre;white-space:pre-wrap; } .messageCont { margin-left:100px; word-wrap:break-word; white-space:-moz-pre-wrap; _white-space:pre;white-space:pre-wrap;} .other { overflow:hidden;color:#39577a;vertical-align:top;font-weight:bold;font-style:normal;float:left; width:95px; } .myself { overflow:hidden;color:#da8103;font-style:normal;font-weight:bold;font-style:normal;float:left; width:95px; } .otherCont { font-size:8px;text-align:right; color:#39577a;font-family:Arial,Lucida Grande;font-style:normal;vertical-align:top;font-weight:bold;float:left; width:95px; } .myselfCont { font-size:8px;text-align:right; color:#da8103;font-family:Arial,Lucida Grande;font-style:normal;vertical-align:top;font-weight:bold;float:left; width:95px; } .system { margin-left:4px; word-wrap:break-word;color:#da8103;font-style:normal;font-weight:normal; white-space:-moz-pre-wrap; _white-space:pre;white-space:pre-wrap; } .showTimestamp { padding-left:8px; margin-right:3px; float:right; color:#999999;font-style:normal;font-weight:normal; } .other1 { color:#ac2000;vertical-align:top;font-weight:bold;font-style:normal;float:left; width:95px; } .otherCont1 { font-size:8px;text-align:right; color:#ac2000;font-family:Arial,Lucida Grande;font-style:normal;vertical-align:top;font-weight:bold;float:left; width:95px; } .other2 { color:#3c9fa8;vertical-align:top;font-weight:bold;font-style:normal;float:left; width:95px; } .otherCont2 { font-size:8px;text-align:right; color:#3c9fa8;font-family:Arial,Lucida Grande;font-style:normal;vertical-align:top;font-weight:bold;float:left; width:95px; } .other3 { color:#e25614;vertical-align:top;font-weight:bold;font-style:normal;float:left; width:95px; } .otherCont3 { font-size:8px;text-align:right; color:#e25614;font-family:Arial,Lucida Grande;font-style:normal;vertical-align:top;font-weight:bold;float:left; width:95px; } .other4 { color:#0b6ac8;vertical-align:top;font-weight:bold;font-style:normal;float:left; width:95px; } .otherCont4 { font-size:8px;text-align:right; color:#0b6ac8;font-family:Arial,Lucida Grande;font-style:normal;vertical-align:top;font-weight:bold;float:left; width:95px; } .other5 { color:#b23290;vertical-align:top;font-weight:bold;font-style:normal;float:left; width:95px; } .otherCont5 { font-size:8px;text-align:right; color:#b23290;font-family:Arial,Lucida Grande;font-style:normal;vertical-align:top;font-weight:bold;float:left; width:95px; } .other6 { color:#02e7c7;vertical-align:top;font-weight:bold;font-style:normal;float:left; width:95px; } .otherCont6 { font-size:8px;text-align:right; color:#02e7c7;font-family:Arial,Lucida Grande;font-style:normal;vertical-align:top;font-weight:bold;float:left; width:95px; } .other7 { color:#5b3284;vertical-align:top;font-weight:bold;font-style:normal;float:left; width:95px; } .otherCont7 { font-size:8px;text-align:right; color:#5b3284;font-family:Arial,Lucida Grande;font-style:normal;vertical-align:top;font-weight:bold;float:left; width:95px; } .highlight { background-color:#bed6f8; } .datestamp { cursor:default; margin-bottom:1px; background-color:#c0c0c0; width:100%; float:left; text-align:right; color:#ffffff; font-weight:bold; font-style:italic; } #chatAlert { float:left; border-bottom:1px solid #E8D091; padding:10px; width:100%; color:#A5754C; } #chatAlertImage { float:left; } #chatAlertText { float:left; margin-left:6px; } #chatAlertClose { float:right; margin-right:10px; padding-right:6px; margin-top:0px; } #chatAlertText a { color:#A5754C; } #chatAlertText a:hover { color:#A5754C; text-decoration:none; } .tsDisplay { display:block }.dsDisplay { display:none } i wrote given below code but still it doesnt works for me

Aspose.Cells.Style style = new Aspose.Cells.Style();

style.Custom = "MM/DD/YYYY HH:MM:SS";
Aspose.Cells.StyleFlag obj = new Aspose.Cells.StyleFlag();

Workbook.Worksheets[sheetIndex].Cells.ApplyColumnStyle(10, style, obj);

Hi,

Please also set the StyleFlag.All property true.

i.e

obj.All = true

still not working…pls helpme out

Hi,

Please see the code below and the output xlsx file attached by me, as you can see it is working fine.

I have used the latest version.

C#


DataTable dt = new DataTable(“OrderDates”);

dt.Columns.Add(new DataColumn(“MyDate”, typeof(DateTime)));


DateTime today = DateTime.Now;


DataRow dr;


for (int i = 0; i < 5; i++)

{

dr = dt.NewRow();

dr[“MyDate”] = today;


today.AddDays(2);

dt.Rows.Add(dr);

}


Workbook workbook = new Workbook();

Worksheet worksheet = workbook.Worksheets[0];


worksheet.Cells.ImportDataTable(dt, true, “A1”);


Column col = worksheet.Cells.Columns[0];


Style st = workbook.CreateStyle();

st.Custom = “MM/DD/YYYY HH:MM:SS”;


StyleFlag obj = new StyleFlag();

obj.All = true;


workbook.Worksheets[0].Cells.ApplyColumnStyle(0, st, obj);


workbook.Save(“Output.xlsx”);