473,387 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

calling Excel Macro from C#

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
2 4458
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mrs Howl | last post by:
I don't know if there's even a way to do what I want. I click on a button in an Access form, and it opens an instance of Excel, and opens a workbook and runs a macro that's in it. So far, fine,...
0
by: Alex | last post by:
i have a module in Access which opens an existing Excel file and envokes a macro within the Excel file to draw graphs. now i am trying to convert the Excel macro to an Access one so that the...
6
by: geronimo_me | last post by:
Hi, I am trying to run an Excel macro from an Access module, however when I run the code the macro runs but then I get an error in Access. The error is: Run-time error "440", Automation error. ...
3
by: TommyBoy | last post by:
i'm trying to call an excel macro from C#, but i have never done it before, and advice? can you pass an argument to a macro.. if so how? Thanks in advance
2
by: cr113 | last post by:
I just upgraded from Office 2000 to Office 2003. My VB.NET Excel macro calls don't work any longer. Here is how I make my Excel macro call from VB.NET: Dim objExcel as Excel.Application ...
1
by: cr113 | last post by:
We've upgraded from Office 2000 to Office 2003 and now my excel macro calls are messed up. There's about a 15 second delay from the time I make the call in VB.NET to the time the excel macro is...
1
by: =?Utf-8?B?Vmlua2k=?= | last post by:
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...
3
by: redbenn | last post by:
Hello, I am trying to create an excel macro, that when clicked... a specific cell will match a record in my database, and update certain fields in this record. The Excel file will have a cell...
1
MitchR
by: MitchR | last post by:
Good Morning Folks; I have a question that is pretty far fetched but here goes nothing... I am looking to find a way to insert a macro into an Excel command button located in an Access VBA...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.