Wednesday, April 2, 2008

Creating Excel Menu from Dot net 2003



using System;
using Microsoft.Office.Interop.Excel;
using Microsoft.Office.Core;

namespace ConsoleApplication3
{

class Class1
{
///
/// Summary description for Class1.
///

private Application excel= new ApplicationClass();
private Workbook book= null;
private Worksheet sheet = null;
private CommandBar MainMenuBar = null;
private CommandBarControl MenuBarItem = null;
//private CommandBarButton MenuItem = null;
public Class1()
{
book = excel.Workbooks.Open("C:\\log.xls",0, true, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "",true, false, 0, true, false, false);
InitMenuBarItems("My Main Menu");
excel.Visible=true;
sheet = (Worksheet)book.Sheets.get_Item(1);
Console.WriteLine("The file name is {0}",sheet.Name);
Console.ReadLine();
}

private void InitMenuBarItems(string Caption)
{
try
{
MainMenuBar =
excel.CommandBars["Worksheet Menu Bar"];
MenuBarItem = MainMenuBar.Controls.Add(
MsoControlType.msoControlPopup,
Type.Missing, Type.Missing, Type.Missing, true);
MenuBarItem.Caption = Caption;

}
catch
{

}
}

[STAThread]
static void Main(string[] args)
{
Class1 cls = new Class1();

}
}
}

7 comments:

SEO Flies said...

Hi Vikas!
I liked your blog, I need a help from you, I am developing a project using c#.net 2003. "When I run my project on IE then it works fine but when I run this on Firefox then output is not as aligned as in IE.
Is there any code or setting which is required to run my C#.net 2003 application on any browser in same manner as it shows in IE.

Please mail me at wingaurav@gmail.com as my work is on hold for this.

Thanks!

Office Coder said...

hey Gaurav,

Couldn't see your comment earlier. I am not a web developer. I am actually an office developer :(

Best,
Vikas

Anonymous said...

Easily I acquiesce in but I think the list inform should secure more info then it has.

Anonymous said...

Genial fill someone in on and this fill someone in on helped me alot in my college assignement. Say thank you you for your information.

Anonymous said...

Again a gentle post. Because of your crony

Anonymous said...

Hi Vikas,

I like your blog. I am also a office developer and new to this field.Need your help regarding Excel.Can you show me an example to create a split button in Excel CommandBar.

Thanks in Advance

Archana

Office Coder said...

Hi Archana,

Sorry for the delay. I was out on a vacation. Hey, I don't work on Office 2003 anymore. I work in 2007 now. The splitbutton can be easily created in 2007 in Ribbon. Let me know if you are looking for an option in 2007.

Thanks,
Vikas