calling excel macro from C#

G

Guest

Hello Everyone,

I exported a gridview to excel spreadsheet. I want to adjust the column
width of the excel spreadsheet.
Is it possible to create Excel macro from C# to adjust the column width of
the spreadsheet. Below is my code for exporting to excel

string attachment = "attachment; filename=Contacts.xls";
Response.ClearContent();

Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
HtmlForm frm = new HtmlForm();

dgAgentActivity.Parent.Controls.Add(frm);
frm.Attributes["runat"] = "server";
frm.Controls.Add(dgAgentActivity);
frm.RenderControl(htw);

Any help will be greatly appreciated.

Thanks.
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top