Excel And C#

  • Thread starter Thread starter Mansi Shah
  • Start date Start date
M

Mansi Shah

How can we change excel column's data type thru c#??

I have 1 column which contains data like 1:30 , 3:30 etc.

I need this data in this format (1:30) to excel, but when i export it to
excel it shows.. 1:30:00 AM , it converts it to time, that i don't
want..

any ideas??



Regards,
Mansi Shah.
 
Mansi,

You will want to check the Format property of the Range instance you are
dealing with to format the contents of the cell appropriately.
 
DataTable dt = new DataTable();

dt.Columns.Add(new DataColumn("Col1"));
dt.Columns.Add(new DataColumn("Col2"));

DataRow dr = dt.NewRow();
dr[0] = "Employee Time: ";
dr[1] = "13:58"; //total hours:total minutes
dt.Rows.Add(dr);

GridView gv = new GridView();
gv.DataSource = dt;
gv.DataBind();

Then i am exporting this grid to excel.
In excel it shows me "13:58:00 AM" instead of "13:58"

so I need to change the format of excel column, but i don't know how to
do that..


Regards,
Mansi Shah.
 
Mansi,

You have to automate excel to do that.

How are you exporting it to Excel? If you aren't working with an Excel
sheet directly (instead, creating a CSV, for instance), you really have no
control over this.
 
Back
Top