By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,686 Members | 2,770 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,686 IT Pros & Developers. It's quick & easy.

calling Excel Macro from C#

P: n/a
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.
Oct 30 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Vinki" <Vi***@discussions.microsoft.comwrote in message
news:2D**********************************@microsof t.com...
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.
You can use the Microsoft Office Primary Interop Assemblies. These allow
you to add a references which gives you access to COM components and let you
do just about anything with an office application.

Look up http://msdn2.microsoft.com/en-us/lib...57(VS.80).aspx

Here you should find out which reference to add, and information about
classes and methods.
Oct 30 '07 #2

P: n/a
No, it's not possible using your technique. You are better off trying an
Interop approach or using the OWC.
--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless Author Plug
OWC Black Book 2nd Edition
Exclusively on www.lulu.com/owc
$19.99
"Matt Brunell" <ma**@fast-soft.comwrote in message
news:80**********************************@microsof t.com...
"Vinki" <Vi***@discussions.microsoft.comwrote in message
news:2D**********************************@microsof t.com...
>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.

You can use the Microsoft Office Primary Interop Assemblies. These allow
you to add a references which gives you access to COM components and let
you do just about anything with an office application.

Look up http://msdn2.microsoft.com/en-us/lib...57(VS.80).aspx

Here you should find out which reference to add, and information about
classes and methods.


Oct 31 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.