|
I am trying to start Excel through code. My objective is to start excel and load a Addin called TM1. If i go in through explorer and click on this Addin(.xla) it connects to a datawarehouse and adds a menu item in excel called Tm1.
Well here is the code that I am using to accomplish the above tasks:
try
{
//create a new excel app.
_newApp = new Excel.Application();
_newApp.Visible = true;
_newApp.AddIns.Add("C:\\Applix\\Integra\\bin\\tm1p.xla","C:\\Applix\\Integra\\bin\\tm1.xla");
_userBook = (Excel._Workbook)_newApp.Workbooks.Add("C:\\Inetpub\\wwwroot\\ExcelAddinExample\\ExcelTemplates\\01_fsTemplate_orig.xls");
_tm1Book = _newApp.Workbooks.Open("C:\\Applix\\Integra\\bin\\tm1.xla",0,false,5,"","",true,
Excel.XlPlatform.xlWindows,"\t",false,false,0,false,null,null);
//try to call the copnnect routine;
_newApp.Run("N_Connect","toad","bisu","GBA03",null,null,null,null,null,null
,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null);
}
Well my code is failing at the Addins.Add() line. What am i doing wrong.
Thanks for any help.
|
|
|
|
|
sameerhanda wrote:
Well my code is failing at the Addins.Add() line. What am i doing wrong.
That's not very helpful. What exception is thrown? What does the exception message state? What's the stack trace of the exception? Specific information like this is necessary to diagnose the great majority of problems. Always give as much information as possible regarding the problem.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
The exception thrown by this piece of code is excatly what I said in my previous post:
{"Add method of AddIns class failed" }
and unfortualty the stack trace is not very descriptive either. But here it is:
" at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)\r\n at Excel.AddIns.Add(String Filename, Object CopyFile)\r\n at ExcelModel.ExcelHandler.CreateExcel() in c:\\sameer work area\\excelmodel\\excelhandler.cs:line 32"
I copied this directly from the debugger.
Anyway hope this gives you a better idea.
|
|
|
|
|
sameerhanda wrote:
{"Add method of AddIns class failed" }
That's not an exception. That's the exception text. What was the exact exception type thrown (ex: TargetInvocationException ).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Heath Stewart wrote:
What was the exact exception type thrown (ex: TargetInvocationException).
Sorry about that..
The excat exception type is ..
{"System.Runtime.InteropServices.COMException"}
Sameer
|
|
|
|
|
Since it's a COMException , the the first thing you should do is suspect the COM server you're calling and look at the documentation.
Having done that, I see two flaws:- The second parameter is ignored if the
Filename refers to a local file (on the hard disk), and CopyFile is a variant of type VT_BOOL (bool ), so even if you had to specify it (i.e., Filename refers to a file on a network share, for example) you need to cast it to an object which gets marshaled as a VARIANT (native type):
object copyFile = true;
excelApp.AddIns.Add("filename", copyFile); You don't need to specify the second parameter, however, if you always know the file will be on hard disk. If you know this assumption is safe, then use object copyFile = Missing.Value; instead of assigning a bool .
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Just wanted to give you a FYI as to how I had fixed this problem..or gotten around it.
int _count = _newApp.AddIns.Count;
for( int i = 1;i < _count ; i ++ )
{
//test to see what is the name of the AddIn.
if( _newApp.AddIns[i].Name.StartsWith("tm1p"))
{
//test to see if it is installed
if ( !_newApp.AddIns[i].Installed )
{
_newApp.AddIns[i].Installed = true;
this._addinIndex = i;
}
}
}
However I will try your method to Heath. Thank's for your responses.
|
|
|
|
|
i'm developing a chat application which allows the user to put smilies in the text box. how can i do this? are there any sample codes? thank you for helping me.
|
|
|
|
|
If you want to display anything more than text, the TextBox is a bad class to extend since it encapsulates the Edit Windows common control and is pretty inflexible. In these cases, most use the RichTextBox , for which you can find many articles about using with chat applications if you search this site or google[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Tell me any five real time web application developed in C# & Asp.Net or Vb.Net & Asp.Net combinations and which have more than 20000 thousands of hits per hour. .
Sreejith Nair
|
|
|
|
|
Sure. www.microsoft.com, www.yahoo.com, www.google.com, www.cnn.com, www.espn.com, ...
All have content that is updated and served real-time.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hoooo, You mean to say these are developed using dotnet
Sreejith Nair
|
|
|
|
|
Not in their entirety. Even Microsoft.com isn't done completely in ASP.NET and C#/VB.NET. There are many different technologies that go into these and most other commercial sites, like Java, PHP, plain old HTML, CSS, XML, CGI, C/C++, ... C#/VB.NET and ASP.NET are just a smallish part of the greater whole.
Besides, 20,000 hits per hour is only 5 hits per second. You could handle that with a single processor box @ 1GHz...
Microsoft.com averaged about 1,600,000 hits in an hour, or 1,121 hits per second, for the month of May 2004. Check out Inside Microsoft.com[^] for hint at what it takes to support one of the worlds busiest web sites.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
And soon that'll double with all the hits on my new blog at http://blogs.msdn.com/heaths[^]!
Much of it is actually ASP.NET now, but not the stock "stuff". Much of it is custom page handlers. We also use SharePoint a lot, which is built on ASP.NET (well, at least SharePoint Service 2.0). There's still some ASP running around, but slowly things are being upgraded to ASP.NET. There have been some MSDN articles and MSDN TV episodes discussing these transitions if you're interested.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Hey all,
I'm trying to adapt our application to work with large fonts- that is when someone goes to display properties, appearances, and changes font size to large or extra large, have my application have larger font sizes. The basic change I've made which works fine is to put in the constructor of the main application the code:
this.Font = new Font(this.Font.FontFamily, SystemInformation.MenuFont.SizeInPoints, this.Font.Style, this.Font.Unit, this.Font.GdiCharSet, this.Font.GdiVerticalFont);
SizeF sf = Form.GetAutoScaleSize (this.Font);
this.AutoScaleBaseSize = sf.ToSize ();
this.AutoScale = true;
I had some trouble just changing the fontsize, that's why I've got that more complicated call (which may not be entirely necessary). Anyway, that works. The problem is that for some reason, in some of my internal controls (but not all! that's the thing) textboxes are getting wider- stretching to the right. This is causing problems like the textboxes covering up buttons that are next to them, etc. I can't figure out for the life of me why they're getting wider- and I can't figure out why only on some controls they are. For example, on one form they're stretching as far as the panel lets them.
I thought it might be the AutoSize property, but even with that off, they still do it (the AutoSize property, as it turns out, only resizes the height based on font size). I coded something that just reverses the change, but there should just be a way to tell the textbox not to resize automatically like it is doing. I checked all over my code and there's nothing I do to change the width. In fact, when I tried to put the code to reverse the automatic change in the Layout event rather than the Resize event, it works, but then when I minimize and maximize, the textboxes stretch again, so it really does see like something built in. Does anyone have any clue as to what might be causing this and how to turn it off?
-David
|
|
|
|
|
|
Sorry, that doesn't fix it. In fact those lines are there so the window resizes appropriately. The AutoScale on the main application assumes the default font size and when that changes, you need to change the AutoScaleBaseSize. I got that from a MS developer.
The reason I'm annoyed at this is because it seems like a built-in behavior in some manner, and there really should be a way to turn it off rather than just hardcoding it in so whenever a control tries to be helpful, I reverse what it does. I'm finding this a common theme with some of these controls.
For example, in a ListView with checkboxes and FullColumnSelect, using shift-select or control-select checks boxes automatically. There's no way to turn this behavior off. I ended up having to test for a shift or control click and set a boolean value to true and then in the onCheck event reverse the check if the boolean value was true.
I think it should be a more common practice when microsoft builds in automatic "features" like this to have the option to turn them off.
-David
|
|
|
|
|
I define some of my variables in asp.net page as a static variable, to keep track of the value when do a postback. For exmaple
<br />
protected void Page_Load(Object Src, EventArgs E) {<br />
static int Counter = 0;<br />
}
The question is, will this static variable become global? mean everyone login to the page from different session see the same value?
or the value only applicable for current session?
Thanks.
regards,
vic
|
|
|
|
|
Your question would be better handled in the ASP.NET Forum. This is a web development/ASP.NET question, regardless of the language that the code-behind is written in.
The static variable idea won't work considering that ASP.NET, as any HTML page, is stateless. You have to save the values to hidden fields on the page, to be read back when the page is posted back to the server, or in the Session object, or somewhere else that can handle state. And, no, it won't become global. There is no such thing in the .NET Framework.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak,
Thanks for the info.
My static variable actually work on the page... just that I am worry it become global. Your answer make me feel better.
p/s: I post it here coz I am using C# in my asp.net. Anyway thanks for reminding me.
|
|
|
|
|
While I normally agree with Dave, I don't see this as specific to ASP.NET so I'll bite.
This won't even compile. You cannot declare fields (a static int Counter looks like a field to the compiler) inside method implementations.
If you need to declare a static variable, do so in the class (your derivative page) like so:
static int Counter = 0;
protected override void OnLoad(EventArgs e)
{
Counter++;
base.OnLoad();
} This will increment for the lifetime of the object, which is alive for as long as the AppDomain is alive in which it was created. For Windows Forms applications, this is typically as long as your application is running (your application could, however, create a new AppDomain). With ASP.NET, this is for as long as the web application doesn't need restarting (like after editing the Web.config file for the site or application; or, again, unless you created a separate AppDomain for some reason).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Heath Stewart,
Thanks for the explaination!
You are right, I actually declare the static variable outside the Page_Load method. My mistake here...
I just want to make sure that, as long as the static variable won't share by other sessions in the same server... it will be fine...
Thanks guy...
|
|
|
|
|
Statics are always within the context of an AppDomain, so if your process consists of two or more AppDomains statics will be different.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Hey Heath!
How's life in the shadow of an actively rumbling volcano?
I thought he was asking if it was possible to persist a session-specific value using a static, like you've suggested. I did't think that's possible, but I could be wrong? Is the AppDomain session-scoped or application-scoped? Seems like a dumb question, I know. But just for clarification purposes...
Also, just to point out for future readers ... yeah, right! ... using a Static such as this, in either Session or Application scope, does not propogate it's value acrossed multiple servers hosting the same web application. So, if you have two or more web servers running the same application, say for load balancing purposes, all servers will have different values for the Static "global" variable.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote:
How's life in the shadow of an actively rumbling volcano?
Exciting! I've been through tornados having been from the midwest, but this is a new experience. I had a lot of interest in volcanoes (and earthquakes) when I was younger (did a fair share more than just "class projects" on them) so this will be fun to see in person. If I get a chance I'll be taking some pics.
It's not expected to be dangerous to the greater Puget Sound area, though, so I'm not worried.
What is exciting is that I've killed two potentially deadly spiders in our new apartment, all within a week of moving in! While they look like brown recluse spiders, 1) those are only supposed to be in the south-east, and 2) they're often mistaken for hobo spiders, which are in this area (and just as potentially deadly).
Back to the topic at hand...
As far as the problem goes, it really all comes down to AppDomains. A process can have more than one AppDomain, and a web application is an AppDomain. As long as the AppDomain is active, the statics are, well, static. Since an AppDomain cannot span multiple machines, what you said about services is true.
To the original poster, if you want a "global" variable across multiple server or applications, you either need to persist it in some storage medium (like a database, although that can be pretty slow depending on load) or use .NET Remoting which allows communication between multiple AppDomains (through indepedent transport and formatting channels). You could, for example, have a singleton running on some machine and the separate servers communicate with the remoting object through a proxy (which you implement a mutex to lock the increment and/or decrement).
There's lots of different ways to solving the problem.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|