Infopath automation and Expansion

Source: Internet
Author: User
From: Microsoft

Operation Method: Create a COM add-on to add the custom function to infopath.

Microsoft Office infopath 2007 supports COM add-ons used to extend the form editing user experience. Although this is a new feature of office infopath 2007, other office applicationsProgram(Such as Microsoft Office Word and Microsoft Office Excel) COM add-on is supported from Office 2000.

The COM add-on in office infopath 2007 can be used in the Form editing environment. You cannot extend the form design environment by using the COM add-on.

Idtextensibility2 Interface

The infopath editing environment providesIdtextensibility2Interface support. This interface is required by COM add-on developers.Idtextensibility2It is a double interface object that provides five methods to act as events in the editing environment. These methods allow the COM add-on to respond to the startup and shutdown conditions listed in the following table.

Interface Description
Onaddinsupdate (byval custom () as variant) It occurs when the add-on is loaded or detached in the environment.
Onbeginshutdown (byval custom () as variant) This occurs when the environment is being disabled.
Onconnection (byval application as object, byval connectmode as ext_connectmode, byval addininst as object, byval custom () as variant) An error occurred while loading the add-on in the environment.
Ondisconnection (byval removemode as ext_disconnectmode, byval custom () as variant) An error occurred while detaching the add-on from the environment.
Onstartupcomplete (byval custom () as variant) This occurs when the environment has been started.
Register COM add-on

All office applications, including infopath, use the registry to list the add-ons in the COM add-on set, store the connection status, and store boot or load information as needed. For the infopath COM add-on, the name of each add-on appears under the following registry key:

HKEY_CURRENT_USER \ Software \ Microsoft \ Office \ infopath \ addins \

This registry entry is located in the HKLM registry Configuration unit for the COM add-on that can be installed for each user on the client computer:

HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Office \ infopath \ addins \

The registry key name corresponds toProgidattributeAnd contains the following values.

Name Type Description
Friendlyname String The name will appear in the "COM add-on" dialog box and in the "add-on" page of the trust center.
Description String The string that will appear when you select an add-on in the trust center.
Loadbehavior DWORD Specifies the Loading Method of the COM add-on. The value can be a combination of 0, 1, 2, 8, and 16. For more information, see the following table.

LoadbehaviorThe DWORD Value of should contain a value that describes how the COM add-on loads in the editing environment. This value can be a value in the following table or a combination of values in the following table. For example, the loadbehavior value of a COM add-on created in Visual Studio 2005 is "3": loaded at application startup and connected.

Value Description
0 The connection is closed. The add-on is displayed as "inactive" in the "COM add-on" dialog box ".
1 Connected. The add-on is displayed as "active" in the "COM add-on" dialog box ".
2 Load at startup. Load and connect the add-on when the host application starts.
8 Load as needed. When the host application requires an add-on, for example, when you click the button to use the functions in the add-on, the add-on is loaded and connected.
16 Connection during the first running. When you run the Host application for the first time after registering the add-on, the user loads and connects the add-on.

 

Use Visual Studio 2005 to create a hosted COM add-on

To use Microsoft Visual Studio 2005 to create a hosted COM add-on, create a visual Studio shared add-on project as follows:

  1. Click"Start", Pointing"All Programs", Pointing"Microsoft Visual Studio 2005"And then click"Microsoft Visual Studio 2005".
  2. In"File"Click"Create a Project".
  3. In"Create a Project"Dialog Box"Project type"In the pane, click"Other project type"Folder, and then click"Scalability".
  4. In"Template"In the pane, click"Shared external program".
  5. In"Name"Enter a name for the shared external project.
  6. In"Location"Box, enter the folder path, or click"Browse"Select the folder path, and then click"OK". Will appear"Shared external program wizard".
  7. In"Shared external program wizard"Click"Next". Will appear"SelectProgramming Language"Page.
  8. Click"Using Visual Basic to create an external program"And then click"Next". Will appear"Select Application host"Page.
  9. Deselect"Microsoft infopath"And click"Next". Will appear"Enter the name and description"Page.
  10. In"External program name"Enter the name of the COM add-on.
  11. In"External program description"Box, enter the description of the COM add-on, and then click"Next". Will appear"Select External Program Options"Page.
  12. Selected"I want to load my external while loading the Host application"And"My external program should be available to all users of computers with an external program installed, not just those who install the external program"Box.
  13. Click"Next"To view"Abstract"Page, and then click"Done".

 

After you create a project in Visual Studio, you will see two projects in the Solution Explorer window. The first project is the COM add-on Project, and the second project is the installation project used to deploy the COM add-on."Shared external program wizard"Only insertMicrosoft Office 12.0 Object LibraryTherefore, you must use the following steps to insert a reference to the infopath Object Library:

    1. Double-click"My Projects"To display the properties of the add-on project. Click"Reference"Tab to display the reference automatically added to the project.
    2. Click"Add"Button to display"Add reference"Dialog box.
    3. In". Net"Tab, double-click"Microsoft. Office. InterOP. infopath"And then click"OK".
Note
To create an unmanaged COM add-on, see create a Microsoft Office 2000 COM add-on in the msdn library.

 

View Registry Settings

To view the registry settings that will be created when the COM add-on is installed, follow these steps:

    1. InSolution Resource Manager"Right-click the root node of the installation project, and click"View"And then click"Editor"And then click"Registry".
    2. In the left-side pane, click the plus sign to expandHKEY_LOCAL_MACHINE,Software,Microsoft,Infopath, And then expandAddins.
    3. ClickProgidCorresponding name.

 

To change any of these attributes, right-click Properties and click"Property Window"And then"Property Window"Change"Value"Box.

Compile and distribute shared add-ons

To compile a hosted COM add-on for testing on the computer where the shared add-on project is developed, goSolution Resource Manager"Right-click the root node of the shared add-on project, and then click"Generate". If there is no error in the project generation process, you can start the infopath editing environment and start using the hosted COM add-on. If an infopath instance is running, disable it before generating the project. It may also have to be enabled."COM add-on"Dialog Box to verify that the COM add-on is registered. To open the "COM add-on" dialog box, follow these steps:

    1. Open the infopath editing environment. The simplest way to do this is to open an existing form template, which will create a new form based on the form template.
    2. In"Tools"Click"Trust Center".
    3. Click"Add-on"Category.
    4. In Proximity"Trust Center"At the bottom of the dialog box"Manage"Section, select from the list"COM add-on"And then click"Search"Button.
    5. In"COM add-on"In the dialog box, you will see the name of the recently generated add-on, and there should be a check box next to it. If there is no check box next to it, the COM add-on fails to be loaded due to an error. This error will be listed in"Loading behavior".

 

To compile a hosted COM add-on for use on another computer that is not developing a shared add-on project, you must perform additional steps to ensure thatCodeSecurity. For information on protecting shared add-on projects for use on other computers, see the following threeArticle:

    • Deploy a hosted COM add-on in Office XP
    • Use the COM add-on Shim solution to deploy a hosted COM add-on in Office XP
    • Isolate office extensions using the com Shim wizard

      Key PointsIf the COM add-on is not isolated, memory leakage and unstable applications may occur.

Note
If you have not installed. NET Framework on the target computer or other required assembly in the installation project, the. MSI file may not be properly installed. In addition, you cannot distribute the. MSI file and then try to install the. MSI file. You must also distribute other support files in the same folder as the original. MSI file generated by Visual Studio.

 

Encoding in COM add-on

The COM add-on can capture application events that occur in the infopath form editing environment. COM add-on can be usedApplicationeventsObject To respond to user operations:

Event Description
Newxdocument This occurs when a new form is created.
Quit This occurs when the user exits infopath.
Windowactivate This occurs when any document window is activated.
Windowdeactivate This occurs when any document window becomes an inactive window.
Windowsize This occurs when any document window is resized or moved.
Xdocumentbeforeclose This occurs before any opened document is about to be closed.
Xdocumentbeforeprint This occurs before any open document is printed.
Xdocumentbeforesave This occurs before any open document is saved.
Xdocumentchange It occurs when a new form is created, an existing form is opened, or other forms are activated.
Xforwarentopen Occurs when the document is opened.

 

To capture these events in the COM add-on, you mustConnectClass declares the following class-level variables:

Private infopathapplication as Microsoft. Office. InterOP. infopath. _ application3 private withevents infopathapplicationevents as Microsoft. Office. InterOP. infopath. applicationevents

In the first line,_ Application3YesApplicationThe latest version of the object, which must be explicitly declared becauseApplicationObjects not includedEventsAttribute. The second line is inInfopathapplicationeventsVariables includeWitheventsKeyword, andInfopathapplicationeventsThe object ("subscriber") must have a row to receive events from the infopath application ("publisher.

 

InOnconnectionDuring the process, you will need the following two lines:

Infopathapplication = directcast (application, Microsoft. Office. InterOP. infopath. _ application3) infopathapplicationevents = directcast (infopathapplication. Events, Microsoft. Office. InterOP. infopath. applicationevents)

The common application received by the add-on in the first lineObjectConvert_ Application3Object. The second line_ Application3ObjectInfopathapplicationVariable)EventsConvert attributeApplicationeventsObject.

 

To create an event handler, go to"Class Name"SelectInfopathapplicationeventsAt the top of the Visual Studio window"Method name"Select the event to be processed from the drop-down list. For example, if you want to control when to save the formXdocumentbeforesaveEvent. Slave"Method name"SelectXdocumentbeforesaveThe following process is automatically inserted:

Private sub infopathapplicationevents_xdocumentbeforesave (byval pdocument as Microsoft. Office. InterOP. infopath. _ xdocument, byref pfcancel as Boolean) handles infopathapplicationevents. xdocumentbeforesave end sub

 

COM add-ons can be processed in the same wayApplicationeventsAny event of the object.

Other resources used to develop COM add-ons

The following lists links to learn more about COM add-ons and step-by-step examples of creating COM add-ons for office applications.

    • Create a Microsoft Office 2000 COM add-on
    • Use Visual Studio. NET to create an office-hosted COM add-on
    • Idtextensibility2 event Process
    • Operation Method: Use Visual Basic. Net to generate an office COM add-on
    • Operation Method: Use Visual C #. Net to generate an office COM add-on

 

2006 Microsoft Corporation. All rights reserved.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.