In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to bind C#.NET Office in the early days, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!
Early C#.NET binding Office
With early binding, Visual C # uses available type information about the C#.NET binding Office application involved to bind directly to the methods or properties it needs to use. The compiler can perform type and syntax checks to ensure that the number and type of parameters passed to the method or property are correct and that the value returned is the expected type. Early binding is sometimes faster because it requires less work to call a property or method at run time. However, while early binding may be faster, the performance difference between early binding and late binding is usually small.
Early binding does have a small drawback: it may cause version compatibility issues. For example, suppose an automated server such as Microsoft Excel 2002 introduces new methods or properties that are not available in Excel 2000, or changes existing properties or methods. These changes may change the binary layout of objects and cause problems with Excel C # applications that automate Excel 2000 with Excel 2002 type information. To avoid this problem with early bindings, it is generally recommended that you use the type information of the minimum version of the Office application that you want to support when developing and testing automation clients.
The following steps explain how to create an automated client that uses early binding. Note that, as these steps illustrate, early binding requires you to reference the type library of the automation client.
Create an automated client that uses early binding
Start Microsoft Visual Studio .NET. On the File menu, click New, and then click Project. Select the Windows application from the Visual C# project type. A Form1 is created by default.
Add a reference to the Microsoft Excel object library. To do this, follow these steps:
◆ on the project menu, click add reference.
◆ on the COM tab, locate the Microsoft Excel object library and click Select.
Note: Office 2003 contains the main Interop assembly (PIA). Office XP does not contain PIA, but you can download PIA. For additional information about C#.NET binding Office, click the article number below to view the appropriate article in the Microsoft knowledge base:
328912 INFO:Microsoft Office XP PIA available for download
◆ clicks OK in the add reference dialog box to accept your choice. If you are prompted to generate wrappers for the selected library, click Yes.
◆ on the view menu, select the toolbox to display it, and then add a button to Form1.
◆ double-click Button1. The code window for the form appears.
◆ in the code window, put the following code
Replace privatevoidbutton1_Click (objectsender,System.EventArgse) {} with: privatevoidbutton1_Click (objectsender,System.EventArgse) {Excel.ApplicationobjApp; Excel._WorkbookobjBook; Excel.WorkbooksobjBooks; Excel.SheetsobjSheets; Excel._WorksheetobjSheet; Excel.Rangerange; try {/ / InstantiateExcelandstartanewworkbook. ObjApp=newExcel.Application (); objBooks=objApp.Workbooks; objBook=objBooks.Add (Missing.Value); objSheets=objBook.Worksheets; objSheet= (Excel._Worksheet) objSheets.get_Item (1); range=objSheet.get_Range ("A1", Missing.Value); range.set_Value (Missing.Value, "Hello,World!"); / / ReturncontrolofExceltotheuser. ObjApp.Visible=true; objApp.UserControl=true;} catch (ExceptiontheException) {StringerrorMessage; errorMessage= "Error:"; errorMessage=String.Concat (errorMessage,theException.Message); errorMessage=String.Concat (errorMessage, "Line:"); errorMessage=String.Concat (errorMessage,theException.Source); MessageBox.Show (errorMessage, "Error");}} this is all of the article "how early C#.NET binds Office". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.