开发者

How do I obtain the url of an application in VSTO application

开发者 https://www.devze.com 2023-02-01 14:50 出处:网络
I have an webapplication in C#, where I will call the VSTO 2003. It works fine. I want the url of the application, so that I can connect to a webservice. For the time being I have hardcoded the webser

I have an webapplication in C#, where I will call the VSTO 2003. It works fine. I want the url of the application, so that I can connect to a webservice. For the time being I have hardcoded the webservice url, in the Sheet1_Startup method. But the url will be changed, so I need a way obtain the url dynamically. That is when I call the VSTO, i want the url to be placed in one of the cells in the Excel OR Is there any method where I can pass a query string to the VSTO 2003 application from my web application.

Kindly help please.

@RobertG5

I wrote the code in my web application as below

 System.Data.OleDb.OleDbConnection objConn = new System.Data.OleDb.OleDbConnection(
    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + @"C:\Examples\VSTO2007\VSTO2007\VSTO2007.xlsx" +
    ";Extended Properties=Excel 8.0;");
            objConn.Open();


            System.Data.OleDb.OleDbCommand objCmd = new System.Data.OleDb.OleDbCommand();
            objCmd.Connection = objConn;
            objCmd.CommandText = "Insert into [Sheet1$]" +
                " values ('Test')";
            objCmd.ExecuteNonQuery();


            // Close the connection.
            objConn.Close();
开发者_高级运维

And the values did get inserted into the vsto excel sheet. Now how do I download this excel.

Regards, cmrhema


Forewarning, you shouldn't ever access Excel through VSTO in a webserver environment. You are going to run into all kinds of threading issues, mainly because Excel is a single threaded application and you are accessing it in a multi-threaded environment.

But I can still answer your question. If you are shelling out to Excel you can pass in your own custom command line argument to it. Just make sure it doesn't conflict with any of Excel's command line arguments (e.g. /x:myargument). You'll want to encode it so that it doesn't contain any special characters that would otherwise conflict with the argument protocol (e.g. base64). On load of your add-in you can check for the argument and do what you like with it ( Environment.GetCommandLineArgs()). Or you can simply instantiate Excel via COM and poke the value into a cell: http://support.microsoft.com/kb/302096

0

精彩评论

暂无评论...
验证码 换一张
取 消