Excel And C#

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.
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
M

Mansi Shah

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.
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top