SUMMARY Developers can refer to this article when using Microsoft Visual Studio .NET to generate solutions using Microsoft Office products. This article is a supplemental material for the content developed using Visual Studio 6.0 in Microsoft Developer Network (MSDN), while the MSDN has a broader development choice for the use of Visual Studio 6.0 for office development. You can get into the following MSDN Web site:
Microsoft Office Development with Visual Studio (Microsoft Office with Visual Studio development) http://msdn.microsoft.com/library/en-us/dnoffdev/html/vsofficedev.asp to help are already familiar with Office development in Visual Studio 6.0 in Developers quickly understand how to use Visual Studio .NET to perform the same task, this article provides a preliminary guidance. Some examples are provided in the article and point out all known issues that may encounter when using Microsoft .NET.
content
Introduction
Use Visual Studio .NET for Office Development. NET Framework's Important Functions Changes from Visual Studio .NET Automatically runs Office
Automation is implemented using a non-hosting code (Microsoft Basics (MFC) and Active Template Library (ATL))
Creating a class package in the MFC Using the MFC's automation example Using managed code (Visual Basic or Visual C #) Automation
COM Interop in .NET From Runturser Call Packaging (RCW) Bind to Office Application From the RCW Processing Event Using Managed Code (Visual Basic or Visual C #) Automated Examples of Automation from Managed Codes Develop office web solutions using ASP.NET
Use the Office web components in ASP.NET to use the document stream from ASP.NET to use Visual Studio .NET extension Office
COM Add Ident Smart Mark Office Security and Managed Code OLE Documentation and Storage
More information
Introduce the Microsoft Office series (including Access, Excel, MAPPOINT, OUTLOOK, POWERPOINT, PROJECT, VITLOOK, POWERPOINT, PROJECT, VISIO, and WORD) include multiple software designed for groups and small business users to increase production efficiency. As a set of end-user tools, Office can help you create, share, and manage business information effectively. Office also helps you customize your product based on your organization's actual situation, using Office technology to solve specific problems.
Back to top
Using Visual Studio .NET for Office Development You can programmatically extend, automate, integrate or use Office in your development solution in your development solution. If you are more strange to use Office development solutions, visit the MSDN Web site provided by this Summary section, which introduces many different forms of Office development and lists some articles for each topic.
After determining the type of Office development that will be performed, the next step is to determine what kind of development tool used. This article is intended to discuss how to generate a Office solution in Visual Studio .NET. The contents of this article include both unmanaged languages (such as Microsoft Basics (MFC) and Active Template Library (ATL), including managed languages, such as Visual Basic .NET, and Visual C #). Which language to choose depends on your project, resources, and familiarity to a particular language. Microsoft has written a number of knowledge base articles to describe how to perform common Office tasks in Visual Studio .NET. Since there are already many other articles, this paper is just to help you organize these content and provide you with important information that you must understand so that you can solve the problem you have in use. NET and increase programming efficiency.
Back to top
Important Functions of .NET Framework Change Most developers using Visual Studio .NET want to use language to communicate with Microsoft .NET Framework. Pay attention to some important changes when using the .NET Framework for office development. If you write code using Visual Basic, Visual C # or third parties, you must be familiar with these changes, so you will know how to design the Office solution.
Note: This section applies only to hosted languages. If you are using MFC or ATL unless you are ready to use Visual C hosted extensions in some place in the project, you can safely skip this section. If you are not familiar with the difference between the managed language and the non-hosting language, please read the following section.
.NET Framework is about managed code. The hosted code is an object-oriented, type safe, a secure code for memory hosting, and most of them are portable code. These codes are compiled into machine codes that can actually run on the processor (called Intermediate Language (IL)) as needed (or in the installation process). In addition, Microsoft also defines a set of classes (including namespaces), which make up the runtime environment of managed code, called public language runs. The public language runtime is the programmed body of all hosts in .NET, which enables you to control all the elements that must be available when writing programs.
Since the program written in .NET Framework is more stable, safer than the early program, so they are naturally safer. However, it is to pay for this feature and flexibility. This price is a structural difference between the public language runtime management code and the early program. For developers who are familiar with Office development in Visual Studio 6.0, consider the following five important function changes, and these function changes to the project:
COM Interoperability: From some aspects, .NET Framework is evolved by Microsoft's previously designed component object model (COM) evolution, which is transforming for the Internet. .NET Framework has a great difference in COM, which is fundamentally different from the type of components familiar with COM developers. Since Office is generated around COM and OLE, you must still use the COM interface when using Office. Microsoft realized this problem, so support for early COM communication (called COM Interop) in the .NET Framework. The action of the interoperability layer is to add a "fill program" between the .NET code and the COM object you intend to use, this way, do not know that it is communicating with his own heterogeneous communication. In other words, the performance of the COM object is similar to any .NET object in the public language runtime, and the .NET client's performance is similar to the COM client's COM client. If you intend to develop Office in Visual Studio .NET, you must be familiar with COM Interop. Do not use variables: .NET hosted language uses public data type systems in the public language runtime system. This type of system has an important feature: All data types are inherited to a single "object" type, which allows data to process data in polymorphism without having other external types (eg, COM or OLE variables). Therefore, .NET Framework does not use variables. If you transplant the Office code from Microsoft Visual Basic for Applications (VBA) or Visual Basic 6.0, you must retrounce the variable as an object. The new object type can not only contain the "IdisPatch *) object, but also other data types. Carefully observe how your code uses these types and add type checks as needed. Garbage Recycling: Managed Language Manage Memory using garbage collector. Using this memory model compared to the reference model, use the memory model to help the .NET project better executes and telescopically. It also helps reduce accidental memory leakage caused by cyclic references. Although it has these advantages, there is also a side effect, which is the uncertainty of the garbage collector, which may make the developers who are familiar with Visual Basic 6.0 or VBA are confused. When you release an object reference in VBA or Visual Basic 6.0, you will release the referenced objects and allow it to close, but it is no longer in .NET. Since the garbage collector is used, the release object does not represent an object has been cleared, so that the retention time of the determinant program (such as Office COM server) can be longer than expected. Real-time (JIT) Compile: In order to be universal between platforms, the hosted code is in the form of IL. This means that the code must be compiled in real time when the code is executed. Microsoft has developed a fast and efficient JIT process for hosted languages, but this requirements for compilation of on-demand mean: the client or component's loading speed may slowly slow down the speed of the non-hosting code. In addition, the public language runtime is handling JIT, and it is necessary to perform a security check and type check, which may not run your code in some execution environments. OLE limit: General OLE is not part of the public language runtime, in terms of "object" representation, it is gradually replaced by XML and HTML, in terms of link remote data sources, it is gradually replaced by Microsoft SOAP.
There is currently no complete (in all aspects) to replace the OLE function, and .NET does not provide built-in support for traditional OLE inclusive features or services in the managed code. Therefore, there is no OLE container control in the new WinForms package (used by Visual Basic and Visual C #. If your solution requires Office OLE tolerance, develop unmanaged hosts or use the WebBrowser control (or custom OLE host control) to process OLE. Remember these issues, you can better handle different from Visual Studio 6.0 when making Office development in Visual Studio .NET.
Back to top
Automatically run Office from Visual Studio .NET enables Microsoft Office to automatically run a convenient and flexible way of incorporating Office features into custom solutions. Although Office's future versions will be integrated with .NET Framework, the current version of Office and earlier have not been done. Most of the operations that must be done automatically in the Visual Studio 6.0 are the same as those processed in Visual Studio 6.0. Office must use COM to programmatically change Office using COM. Some details have changed, but the overall method has not changed.
To automatically run the Microsoft Office application from Visual Studio .NET, you need to download and install the main Interop Access (PIA) for Microsoft Office XP. For additional information about Office XP PIA, click the article number below to see the article in the Microsoft Knowledge Base:
328912 Info: Microsoft Office XP PIA available for download
Developers using Office XP PIA must know that these assemblies are slightly different from Office object models. Therefore, if you want to transplant existing applications, you may have to change the code. In addition, the behavior of PIA is consistent with .NET, as shown below:
The release time is not sure to lack the method used by the project to support the project in the default method or attribute. Different information about the known issues of Office XP PIA, please visit the following Microsoft Web site:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnoxpta/html/odc_piaissues.asp
When developing Office solutions, you must first know what version must be used in this item. Compatibility is an important issue. If you need code to use some specific versions, you must use the lowest version of the code that is compatible with compatible Office to make most development and initial testing. For example, if you need a project to use Office 2000 and later, you use Office 2000 (and Office 2000 Type Library) in the development. This ensures that you can use Office 2000 and later to run items (but don't necessarily use Office 97). For additional information, click the article number below to see the article in the Microsoft Knowledge Base:
244167 Info: Writing Automation Clients for Multiple Office Versions When you have an Office version you must use, you must consider how you need to perform automation in Visual Studio .NET: Use unmanaged code in Visual C in Visual C in Visual C . . - Or - Use managed code in Visual Basic, Visual C # or with managed extended Visual C , and use the COM Interop service of the public language runtime to process COM calls.
Back to top
Automated automation using a non-hosting code (Microsoft Basics (MFC) and Active Template (ATL)) You can use Visual C .NET to generate unmanaged COM clients and servers, just as in the earlier versions of Visual C . The MFC and ATL frames have no big changes in COM or OLE, so existing code that uses Office automation can be ported to Visual C .NET and something is basically no problem. Moreover, performing an automated way (using MFC Package or #import) is similar to what you are familiar with, so don't learn any new technologies.
Back to top
Create class packages in MFC
For developers who are used to using MFC, the only true change is to delete the class wizard of Visual Studio IDE. This change will affect how you create an MFC class package for Office applications when you start a new project. For additional information about how to create a set of MFC packages from Visual C .NET, click the article number below to see the article in the Microsoft Knowledge Base:
307473 HOWTO: From Visual C .NET Using Type Libraries Office Automation Generated Packaging Class Usage and Usage of Packages Created using Visual Studio 6.0 is substantially the same. You can create a separate file for each import class for Visual Studio .NET. In addition, when you use the Office type library, there are some problems with new class generators. For additional information about these issues and methods for avoiding these issues, click the article number below to see the article in the Microsoft Knowledge Base:
311407 BUG: MFC Class Wizard Does Not Resolve Naming Conflicts Between Windows Apis and COM Interface Methods
311408 BUG: 'Read-Only' Warning When Adding An MFC Class from A Type Library
Back to top
Automation example using MFC
For additional information about how to automatically run Office from Visual Studio .NET, click the article number below to see the article in the Microsoft Knowledge Base:
Microsoft Excel
308292 HOWTO: Automate Excel To Create and Format A New Workbook Using C .Net and MFC
308407 How to: Implement Excel automation from C .NET and MFC to use array to populate or get a range of data
309301 How To: Handle Events for Excel by Using Visual C .NetMICROFT WORD
308338 HOWTO: Automate Microsoft Word To Perform A Mail Merge from Visual C .NET
309294 How to: Handle Word Events by Using Visual C .Net and MFC
Microsoft PowerPoint
308336 HOWTO: USE Automation To Create and show a PowerPoint Presentation with Visual C .Net and MFC
309309 How to: Handle PowerPoint Events by Using Visual C .Net and MFC
Sharing Office feature
306686 HOWTO: Automation from Visual C .NET Office Macro
312626 How to: Use Automation To Create Office Command Bars And Controls by Using Visual C .NET
310744 How to: Use Visual C .NET and MFC to turn off the Office application displayed dialog box
Back to top
Automation Using Managed Code (Visual Basic or Visual C #) Automated From Managed Code Automatically runs Offic with early Visual Basic programming slightly different. When performing automation using the hosted language, it is not directly bound to the object. Your communication is transmitted through a middle "package", which converts this .NET data type and call to COM type and call (you can also convert the latter to the former).
Back to top
COM Interop in .NET
The COM Interop service of the public language runtime allows managed code running in .NET to communicate early COM servers (such as Office), the method is to use packaging between managed code and COM servers. This packaging is called an Interop assembly. When you add a reference to the COM server (for example, its type library) in the .NET project, Visual Studio .NET uses the type information to generate the run library to call the package (RCW) code, which is immediately imported into the project. These managed code will be compiled into a separate assembly (ie the Interop assembly) and is accessed by .NET Framework, as if it is any other .NET managed library. The RCW acts as a host between the hosting code and the COM server.
If the written COM server can support .NET, it can provide a mandatory and registered to the main Interop assembly (PIA) in the global program cache. These assemblies are shared assemblies that are considered to reference the best way to reference early COM servers in the .NET project. Currently, Microsoft only provides Office XP (and higher) PIA. You can now download these PIAs and you can re-distribute them with your project. For additional information about Office XP PIA, click the article number below to see the article in the Microsoft Knowledge Base:
328912 Info: Microsoft Office XP PIA is available for download If your item needs to automatically run Office 2000, you must create your own Interop assembly (IA) for Office / MSO, VBA scalability, and Office applications to be automatically run. These custom IAs should be considered part of the application and should be deployed from the rest of the project to the application folder. Although Visual Studio .NET can automatically create these assemblies using the TLBIMP.EXE utility, they are custom assemblies and should not be registered as global objects. For additional information about COM Intero in .NET, see the COM Interop section of the Microsoft Developer Network (MSDN) library in the following MSDN Web site:
Advanced Com Interop Documentation (MSDN Online Library) (MSDN Library) http://msdn.microsoft.com/library/en-us/cpguide/html/cpconadvancedcominterop.asp
Back to top
Bind to Office applications from RCW
The Interop assembly created from the type library uses an early binding to communicate with the COM project. However, if you have to keep the binding detail (for example, if you need code to run multiple Office application types, you don't have to know the specific type), you can still make late bindings in Visual Studio .NET. For additional information about the binding options in .NET, click the article number below to see the article in the Microsoft Knowledge Base:
304661 HOWTO: USE Visual Basic .NET for Binding for Office Automation Servers
302902 HOWTO: The advantage of using Visual C # .NET for Office Automation Server is the advantage of do not have to use RCW (or generate / transmit custom interop assemblies) and more common among each version. Its disadvantage is that it implements it more difficult in Visual Basic .NET than it is more difficult than in Visual Basic 6.0, and because it must find DISPID at runtime, it also affects performance.
In addition to the binding, another important issue is an object instantiation. If you use an Interop assembly, the RCW of a specific Office application will be in use.
The control object is instantiated when the New operator is controlled. RCW secretly calls the corresponding COM routine (for example
CocreateInstance) Create a new instance of the application for your code. If you want to explicitly control the object instance or bind to a running application instance, you can use in Visual Basic .NET.
GetObject, or use in Visual C #
GetActiveObject. However, if the Office application has gone and lost a focus, they only register them in the Run Object Table (ROT). If this is achieved by code, the timing and focus are critical to the code. For additional information, click the article number below to see the article in the Microsoft Knowledge Base:
316126 How to: Use Visual C # .NET TO Automate A Running Instance of an Office Program316125 PRB: Visual C # .NET ERROR Attaching To Running Instance of Office Application
308409 PRB: Visual Basic .NET error occurs when GetObject or getActiveObject is used for the Office application instance that is running.
Back to top
Procedure from RCW
.NET Framework supports type secure callback function pointer to call the notification message to a single client (such as a typical COM event) or multiple clients (such as asynchronous broadcast). Handling this callback mechanism .NET object is called
Delegation, for familiar COM, although "delegate" has other uses, but consider it as a way to handle COM events.
When you create an RCW from the type library, all event methods described in this library will be packaged to form a "delegate" class, which can be used to handle events. To receive events, you can implement a function of handling events, create an instance to bind to the delegation of the function, and attach the delegation to the source object to receive the event. Here is an example:
// in Visual C # WHERE Cellschange b> is a function That You have implemented:
Eventdel_cellschange = new excel.docevents_changeeenthandler (Cellschange);
Xlsheet1.change = Eventdel_cellschange;
'In Visual Basic .NET:
Eventdel_cellschange = new excel.docevents_changeeeventhandler (Addressof Cellschange)
AddHandler Xlsheet1.change, EventDel_cellschangevisual Basic developers can also use
Withevents and
Handles keywords to simplify this process, making your code easier to read. If used
WitHevents declares that the Handles keyword can be added to the callback function so that Visual Basic .NET will automatically bind you "delegate". Here is an example:
// in Visual Basic .NET:
Private Withevents Xlsheet1 as Excel.Worksheet
Private sub xlsheet1_change (byval target as excel.range) Handles Xlsheet1.change
Debug.writeline ("You Changed Cells" Target.address "On Sheet1")
End Sub With additional information about the two methods described above in Visual Basic .NET, click the article number below to see the article in the Microsoft Knowledge Base:
302814 HOW TO: HANDLE Events for Excel by Using Visual Basic .NET If the RCW does not have the delegation of the event method, if you must dynamically provide delegation for the callback, or if you must change the callback, you must use COM.
IconnectionPoint and IconnectionPointContainer interfaces to set their own receivers. This is more troublesome, but may be a unique way to reliably receive events for some servers. For additional information, click the article number below to see the article in the Microsoft Knowledge Base:
308330 HOWTO: Testing PowerPoint events with Visual Basic .NET
Back to top
Automation example using managed code (Visual Basic or Visual C #)
For additional information about the .NET, click the article number below to see the article in the Microsoft Knowledge Base:
Microsoft Excel
301982 HOWTO: From Visual Basic .NET Automation Microsoft Excel
302084 HOWTO: From Visual C # .NET Automation Microsoft Excel
302814 How to: Handle Events for Excel by Using Visual Basic .NET
302815 HOW TO: HANDLE Events for Excel by Using Visual C # .NET
302094 HOWTO: From Visual Basic .NET Automation Excel to use array to populate or get data in a range of values
302096 HOWTO: Using Visual C # .NET Automation Excel to use array to populate or get data in a range
306022 How To: Transfer Data To An Excel Workbook by Using Visual Basic .NET
306023 How To: Transfer Data To An Excel Workbook by Using Visual C # .NET
307021 HOW TO: Transfer XML Data To Microsoft Excel 2002 by Using Visual Basic .NET
307029 HOW TO: Use Visual C # .NET to transmit XML data to Microsoft Excel 2002
Microsoft Word
316383 How to: Automate Word from visual Basic .NET TO CREATE A New Document
316384 How to: Use Visual C # .NET to make Word automatic new documentation
301656 HOWTO: Automate Microsoft Word to Perform A Mail Merge from Visual Basic .NET
301659 HOWTO: Use Visual C # .NET to make Microsoft Word automatically perform mail merge
302816 HOWTO: HANDLE Events for Microsoft Word Using Microsoft Visual Basic .NET
302817 HOWTO: HANDLE Events for Word Using Visual C # .NET
Microsoft PowerPoint
303717 HOWTO: Use Automation To Create and show a PowerPoint Presentation with Visual Basic .NET
303718 HOWTO: Using Automation in Visual C # .NET to create and display PowerPoint presentation
308330 HOWTO: Handpoint events with Visual Basic .NET 308825 HOWTO: HANDLE POWERPOINT Events with Visual C # .NET
Microsoft Access
317113 HOW TO: From Visual Basic .NET Automation Microsoft Access
317114 How to: Automate Microsoft Access from Visual C # .NET
Microsoft Visio
305199 HOWTO: Automate Visio with Visual Basic .NET
Microsoft MAppoint
305200 how to: automate mappoint by using visual basic.net
302897 How to: Automate The MapPoint 2002 Control and Save The Map As HTML in Visual Basic .NET
Sharing Office feature
303017 HOWTO: USE Automation To create Office Command Bars and Controls with Visual Basic .NET
303018 HOWTO: Use Automation To Create Office Command Bars and Controls with Visual C # .NET
302281 HOWTO: Using Visual Basic .NET to get the window handle of Office Automation Server
302295 HOWTO: Using Visual C # .net to get the window handle of Office Automation Server
306682 HOWTO: Automation from Visual Basic .NET runs Office Macro
306683 HOW TO: Automation from Visual C # .NET running Office Macro
303294 HOWTO: USE Automation To Get and Set Office Document Properties with Visual Basic .NET
303296 HOWTO: Using Automation Get and Sets Office Document Properties in Visual C # .NET
307292 HOWTO: Use Visual Basic .NET to close the Office application display dialog
Back to top
Known issues related to automation from managed code
Since the public language runtime is used to manage memory, and the RCW itself is a managed object, it cannot be guaranteed that after the release of the automated object is released, the living life of the object will end immediately. The RCW is labeled as the rubbish to be recovered, and the RCW will be released when the garbage collector is ready to release more memory. This means that although you no longer make the Office application automatically run, because the garbage collector has not released RCW, the application remains loaded. For additional information, click the article number below to see the article in the Microsoft Knowledge Base:
317109 PRB: Use the Visual Studio .NET client to perform the automation function without exiting the Office application for additional information about the problem that may encounter when using Office objects in the managed code, click the article number below to view the Microsoft Knowledge Base Corresponding article:
315981 Visual Basic .NET '[Method] is ambiguous across the inherited interfaces' Error Message When Using Office Automation316653 PRB: Error Using WithEvents or Delegates to Handle Excel Events from Visual Basic .NET or Visual C # .NET
320369 BUG: Old Format Or Invalid Type Library Error When Automating Excel 2002
317157 PRB: Errors When You Reference The Access 10.0 Type Library with Visual Studio .NET
Back to top
Developing Office Web Solutions using ASP.NET ASP.NET is a new development platform in Visual Studio .NET that enables developers to create an enterprise application. With ASP.NET, you can develop web applications with any language that supports .NET, and makes full use of the rich features of .NET Framework. The ASP.NET Web Form enables you to generate a user interface for a web application. Although web forms provide user interfaces for web applications, the page hidden code (code runs to generate page output) is still running on the server computer. Microsoft recommends not automatically running Office products from a web form or from other non-interactive accounts. For additional information, click the article number below to see the article in the Microsoft Knowledge Base:
257757 Info: CONSIDERATIONS for Server-Side Automation Of Office Server Automated, including client automation, streaming multi-purpose Internet Mail Extension Protocol (MIME) content, and Office Web Components. These methods will be introduced one by one below.
Back to top
Using Office Web Component Office Web Components (OWC) in ASP.NET provides the best way to make Web projects. These components can be used as client controls in ASP.NET, just like in any HTML page. In addition, OWC 10 (Office XP) also provides an appropriate function that makes it a good server-side component suitable for a limited Web site. Additional information about how to use OWC 10 when developing a server-side solution in ASP.NET, click the article number below to see the article in the Microsoft Knowledge Base:
303016 How to: Use the Office XP Chart Components and ASP.NET to use the data set
315695 How to: use the office xp web components with xml data generated by an Xml Web Service CREATED Using ASP.NET
Back to top
Use the Document Stream from ASP.NET If the Office Web component does not have the features you need, you can configure the HTML page to launch the Office application on the client and load data from the web server. In this way, the user can modify, edit, or save the returned data using OFFICE.
You can use multiple methods to return data to the client, including XML web services and MIME content. The integration of XML Web services is a new feature in Visual Studio .NET. Visual Studio .NET enables developers to easily create and use XML Web services. XML Web services provide services to users through standard Web protocols. Users can use the Visual Studio .NET application, you can also use the Microsoft SOAP toolkit to connect to the XML Web service. For additional information about the SOAP toolkit, visit the following Microsoft Developer Network (MSDN) Web site: http://msdn.microsoft.com/library/default.asp? URL = / Downloads / List / Websrv.asp In addition, use Office XP Web Services Kit, developers can also directly reference the XML web service from VBA without having to use .NET Framework. For additional information about the Office XP Web Services Kit, visit the following Microsoft Developer Network (MSDN) Web site:
Another way to send data to the client in Microsoft Office XP Web Services Toolkit (Microsoft Office XP Web Services Toolbox "is to stream content by using the MIME type. After changing the MIME type of the web page to a specific value, the browser will start the associated application to display the data. If this method is used, after setting the content type, any type of data (e.g., RTF, HTML, and binary data) that can be opened in the Office application can be sent to the client. Since the ASP.NET web control generates HTML sent to the client, you can set the content type of the web page to display the contents of the control in the Office application. For additional information, click the article number below to see the article in the Microsoft Knowledge Base:
318425 How to: send and receive binary documents by using an asp.net Web service and visual c # .NET
318756 PRB: Excel and Word Content Do Not Stream As Expected from ASP.NET
311461 HOW: Use asp.net or visual basic.net to transform xml to rich text format (RTF) for Microsoft Word 2002
319180 how to: convert the data set to Excel's spreadsheet XML by using Visual Basic .NET and ASP.NET
317719 How to: Export Data In a DataGrid on an ASP.NET Webform to Microsoft Excel
316934 How to: Use ADO.NET in Visual Basic .NET to retrieve and modify records in the Excel workbook
307033 HOWTO: USE An XML Web Service by Using ASP.NET from AN Office VBA Macro in Word or Excel
Back to top
Extending the extensible components running in Office using Visual Studio .NET extending Officed scalable components have always been an important part of Office development. All Office 2000 and Office XPs allow for programming of the host application using the COM load item. Some features are introduced in Office XP to allow the use of intelligent tag identifiers and operational components to extend the documentation. Since both solutions are largely dependent on COM, I decide that Before I generate COM components in Visual Studio .NET, consider the benefits of using fully compiled COM components. However, if your design needs to use .NET feature, or it can benefit from the .NET, you can create these two types of add-in in Visual Studio .NET. Developers who are familiar with COM Add or Smart Markers in Visual Studio 6.0 must remember the following points:
You must register your COM add-on. By default, managed DLLs created in Visual Basic or Visual C # cannot be used as COM components. To register them, you must set the registration COM Interop value to true under the "Generation" option of the project properties. In order to make the Office correctly load the components, you should specify a strong name for the component and then register it in the Global Assembly Cache (GAC). By default, the typical .NET DLL project does not perform this. Since the hosted code is not a native code, the COM registry key created for the component points to the .NET runtime engine (Mscoree.dll), and does not point to your assembly. Because Mscoree.dll has no digital signature, the Office is based on the digital signature, so that even if you have a digital signature for the assembly, the system will prompt the user to enable or disable the add-on. For additional information, see the Office Security and Managed Code section below this article. Keep in mind that the current version of Office is designed around COM (instead .NET). If performance is a key factor in the success of the project, consider using a non-hosting language (such as MFC, ATL or Visual Basic 6.0).
Back to top
The COM Add-item COM loading is the most commonly used scalability solution for developers. In order to completely integrate the add-in and the host application, the developer must automatically run the load item from the application. Therefore, developers need to be familiar with the above
Automatically run Office section from Visual Studio .NET.
For additional information on how to create a COM add-in to create a COM loading in Visual Studio .NET, click the article number below to see the article in the Microsoft Knowledge Base:
302896 HOW TO: Generate Office COM Outline using Visual Basic .NET
302901 How to: Use Visual C # .NET to generate Office COM add-in
316723 PRB: Visual Studio .NET Shared Add-in Not Displayed In Office COM Add-ins Dialog Box
Back to top
Smart Mark Intelligent Markers is a new technology introduced in Office XP. The smart tag provides a new document interaction. Currently, smart tags can only be used for Microsoft Word 2002 and Microsoft Excel 2002. For additional information about smart tags, see the Smart Tag Software Development Kit (SDK) on the Microsoft Developer Network (MSDN) Web site below:
Microsoft Smart Tag SDK (Microsoft Smart Tag SDK) For additional information about how to develop smart tags using Visual Studio .NET, click the article number below to see the article in Microsoft Knowledge Base: 306058 How to: Use Visual Basic .NET creates Office XP Smart Tag DLL
306422 How to: Create An Office XP Smart Tag DLL by Using Visual C # .NET
Back to top
Office security and managed code Since the managed code is not a native code, the COM registry key created for Office components (using .NET generation) points to the .NET runtime engine (Mscoree.dll), not to your assembly . Because Mscoree.dll has not passed a digital signature, and Office is determined in accordance with the digital signature, the user will receive a macro warner even if you have a digital signature for the assembly, the user will also receive or disable the add-in.
316724 PRB: 'MSCOREE.DLL Contains Macros' Prompt When Starting Office Application To avoid this macro warning, you can use a "fill program" to the component. For additional information about developing and deploying fill program solutions, see the following article on the Microsoft Developer Network (MSDN) Web site:
Deployment of Managed COM Add-ins in Office XP (Departs in Office XP) http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnoxpta/html/ ODC_SHIM.ASPUSING The Smart Tag Shim Solution To Deploy Managed Smart Tags In Office XP (Using Smart Tag Fill Programs Solution in Office XP) http://msdn.microsoft.com/library/default.asp?url = / library / en-us / dnsmarttag / html / odc_stshim.aspusing the COM Add-in Shim Solution to Deploy Managed COM Add-ins in Office XP (Using COM Add Item Pack Program Solution to Deploying COM Add "in Office XP Http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnoxpta/html/odc_comshim.asp
Back to top
OLE Documents and Storage For editing or viewing Office documents in a Windows application, Visual Studio .NET does not provide any new features. In fact, for some developers who are familiar with Visual Basic, it seems to have some steps because it no longer provides OLE container controls they have already already familiar with. For additional information, click the article number below to see the article in the Microsoft Knowledge Base:
304562 INFO: Visual Studio .NET does not provide OLE container control for WINF, this is caused. OLE Based on COM, and .NET is not based on COM. In order to adapt to the cross-platform design of the public language runtime, the OLE solution cannot be tightly bound to this frame. If your solution requires an OLE function, you can use the WebBrowser control or a custom OLE Document Viewer. For additional information, click the article number below to see the article in the Microsoft Knowledge Base: 304643 HOWTO: USE The WebBrowser Control to Open an Office Document In Visual Basic .NET
304662 HOWTO: Open Office documentation in Visual C # .NET using WebBrowser controls
311765 Sample: Visual C ActiveX Control for Hosting Office Documents IN Visual Basic or HTML For additional information on how to use existing OLE features in an unmanaged MFC or ATL project, click the article number below to view Microsoft The corresponding article in the knowledge base:
316587 How to: Automate Embedded Office ActiveX Documents with C .NET
316207 How to: embedded and automated Word documents by using C .NET and MFC
Back to top
The information in this article applies to:
Microsoft Visual Studio .NET (2002), Academic Edition Microsoft Visual Studio .NET (2002), Enterprise Architect Edition Microsoft Visual Studio .NET (2002), Professional Edition Microsoft Visual Studio .NET (2002), Enterprise Developer Edition Microsoft Visual Basic. NET (2002) Microsoft Visual C .NET (2002) Microsoft Visual C # .NET (2002) Microsoft Office XP Microsoft Office 2000 Developer Microsoft Visual J # .NET Microsoft Visual Studio .NET (2003), Professional Edition Microsoft Visual Studio .NET (2003 ), Academic Edition Microsoft Visual Studio .NET (2003), Enterprise Architect Edition Microsoft Visual Studio .NET (2003), Enterprise Developer Edition Microsoft Visual C # .NET (2003) Microsoft Visual C .NET (2003)
Recent Updated: 2004-2-20 (9.0) Keywords: KbhowTomaster Kbinfo KB311452 KBAUDDEVELOPER