[Repost] Let .NET developers easier to develop intelligent documents

zhaozj2021-02-12  143

Let .NET developers easier to develop intelligent documents

Release Date: 2004-06-30

| Update Date: 2004-06-30

Susan Warrenkeith Craigvertigo Software, Inc

Suitable for: Microsoft? Office 2003 version Microsoft Visual Studio? .NET 2003

Summary: Intelligent document is a powerful application model, but it does not utilize the object-oriented event drive feature based on the .NET language. This article describes Vertigo managed smart document packaging (Vertigo Managed Smart Documents Wrapper), which is a hosted package and a group of Microsoft Visual Studio .NET 2003 project templates. It makes it easier to use .NET-based language to make smart documents easier and efficient. Hosting smart document packaging can be downloaded from Vertigo Software, Inc..

Vertigo managed smart document packaging can be obtained from Vertigo Software.

This page

Introduction Intelligent Document Basics Use Visual Studio .NET to create a hosted smart document Quick experience hosting smart document to find the end of the intelligent document debugging smart document bold ideas: control array summary

Introduction

I really like the user experience brought by intelligent documents. They have completed an amazing job that makes the document-centered task becomes more in the form of documentation by using the data, process and helping to properly integrate data, process and help in Microsoft? Office Word 2003 or Microsoft Office Excel 2003. Smooth and efficient. When I first saw the smart document, I was very excited: with build, deployment, supporting another new application and different training users, the method puts the application intelligence directly into the document itself. Ah, how wonderful idea!

But I am also a faithful believer that uses an object-oriented event-driven programming mode to develop corporate productivity applications. The reason is very simple: development, debugging and maintenance of an application-driven consignment code written, the cost of spending is much less. Shortly after I am experiencing, we received a request from the customer's development of intelligent document solutions, so I took the intelligent document development field and to get a chance to use this powerful new application model. I feel excited. However, how long I don't have to realize that implementing a smart document means writing a process code rather than an object-oriented code. Not very fun at all.

After working with the cooperation developer Will Allan and the Classic Keith Craig, I started to create a set of classes and tools in order to make smart document development work easier, more efficient, while keeping we are very obsessed with The low cost advantage of .NET development model. This article describes our solution - Vertigo hosted smart document packaging, and strives to let readers quickly learn to use Microsoft Visual Studio .NET 2003 to develop smart documents.

The hosted smart document package provides some smart document development links that are missing in the .NET environment. The most important component (the foundation of my ASP.NET) is actually a managed package for process ISMARTDocument interface. The package provides "plumbing" to meet the internal operation requirements of this interface, so that it can act as the base class (called ConfigureDsmartDocument) of the code of the document. It reads the layout and event Wire-Up of the element in the document task pane from an XML configuration file. IsmartDocument's programmable hooks are disclosed as an event, and you can process these events in the code hidden class of the document.

Another important part of the hosted intelligent document package is a set of new Visual Studio .NET 2003 project types, use these item types with Microsoft Visual Basic? NET and Microsoft Visual C #? Develop language, you can create Word and Excel smart documents . As you can see, an intelligent document solution consists of multiple separate files. The Visual Studio .NET project creates a preliminary solution to manage these files easier to manage these files and their dependence. The following is a component installed with the Vertigo hosted smart document package.

• IsmartDocument interface Based on .NET's Package Library? Used to create a new Visual Studio .NET 2003 project for hosted smart documents in Visual Basic .NET and C #? Smart Documentation Instruction List File and XML Profile Visual Studio .NET statement completed architecture • The full source code for the package library in the Visual Studio .NET C # project? A sample showing how to use the packaging library? Document

This article will create the process of creating a hosted smart document later, but first let us briefly review the basics of intelligent documents.

Back to top

Intelligent document basic knowledge

The smart document is a workbook in Word 2003 or in Excel 2003, which is associated with an XML architecture, so that data in the document is not only a paragraph or a cell area, but also has a context-related identifier. For example, it does not identify a cell as a similar sheet1! C34, more valuable is that it knows the entertainment expenditure of the unit contains expenditure reports. The context-specific logic and user interaction is another element of a smart document solution. When the user selects an entertainment expenditure cell, the smart document can display the information and operations in the task pane specific to the entertainment expenditure policy.

Intelligent document analysis

Documents and XML architectures are just two files of multiple files of intelligent document solutions; other files support, deploy, and update code behind smart documents. Intelligent document solution consists of the following files:

? Smart documentation. Word document or Excel spreadsheet. ? Architecture file. Define the XML architecture file for the meaningful area of ​​the document. • Operation handler code. Based on .NET's assembly (DLL), it implements the ISMARTDocument interface and handles interactions between users and task panes. • XML extension package instruction list file. An XML file that specifies the identity and location of the component files required for a specific smart document solution fully enabled.

In addition, hosting smart document packaging has also added the following files:

? SmartDocumentWrapper.dll. Based on .NET's assembly, including packaging classes. ? Configure.xml. An XML file that defines the layout and function of the task pane using the declarative XML syntax.

These files are shown in Figure 1.

Figure 1. Extended package file

For more information on intelligent documents, see the following SDK documentation: Office 2003 Smart Document Software Development Kit (SDK).

Back to top

Create a managed smart document using Visual Studio .NET

In its article The Definitive "Hello World" Managed Smart Document Tutorial, John Durant completed a superior job, which describes how to create a managed smart document from the header with the ISMARTDocument interface interactive and provide a large amount of detailed details. For any developers who create smart documents in an .NET-based environment, the information in this article is very useful, so you recommend that you can read this article.

However, in this article, we will create a smart document with the library and project templates that are installed with the hosted smart document package. Back to top

Quick experience hosting intelligent documentation

When you install your hosted smart document package, you will add a new Visual Studio .NET 2003 project template to create a hosted smart document project using the packaging assembly. A template is provided for Visual C # and Visual Basic .NET and Word and Excel documents.

To quickly experience the hosted smart document, do the following five steps:

Open Visual Studio .NET 2003. On the File menu, point to New and click Project. The New Project dialog opens:

Figure 2. "New Project" dialog of intelligent document project

• Select the project type, fill in the project name (change will be more difficult later) and the location, and then click OK. The project will open and the Solution Explorer contains the following files:

Figure 3. Files in the new smart document project

• Press F5 to start the project compile, Word will open and display the smartdoc.doc document:

Figure 4. Word template document before the additional extension package

At this point, the extension has not been attached to the document, so the document is not "smart"! Follow the instructions in the green help text in the file to attach the extension package, will display the Document Actions Task pane (at this point, the smart document begins to run):

Figure 5. Word template document after additional expansion pack

• Click Click ME in the Document Actions Task pane! A simple message box can be displayed:

Figure 6. Click the word template document after the button

It's that simple!

The new project template has completed most of the curtains, they automatically created the following:

• XML instruction list file. Manifest.xml lists the files included in the extension. • XML architecture file. DocumentsChema.xsd files are used to describe the logical structure of the document. These include examples and how to expand it. • XML configuration file. Configuration.xml defines the Document ActionS task pane control and its properties using a simple tag language. It contains an example documentation operation festival and has an example control. ? Code hide code class. The OfficeCodeBehind class is derived from the ISMARTDocument interface class: configuredsmartDocument. This class contains event handlers for loading and initializing intelligent documents, as well as examples of how to handle control event handler for intelligent document control events. ? Smart documentation. This is a Word 2003 document or an Excel 2003 workbook, depending on the selected project template. This document contains help text to add an extension package to a document.

In addition, the project template also confesses the project's debugging and code access security.

• Debug. Press F5 to start the smart document in Word or Excel and configure the work folder to folder with the Manifest.xml file. ? Code access security. When the project is created, a command file will be created and customized, and the file is automatically executed. It will configure the URL-based code access security for the project. This file is also added to the project and has appropriate annotations for future use and modification.

Back to top

Find out

Now let's continue to find out if you have just created how the intelligent document you have just created. Please observe the code, the following sections of the configuration.xml file define the button:

tag is packaged in the tag. The tag defines a set of control sets for give an ActionXMLTYPE, from essentially a logical festival of the document. In this example, the "ActionPERTAINSTOENTIRESCHEMA" means that the controls in this section appear at the top of the Document Actions task pane, regardless of the current selection location in the document.

The tag defines the name, type (button), title, and several event handler of the button. The ONSETCAPTION attribute defines the name of the event handler for setting the title. Related code exists in the OfficeCodeBehind class:

Private sub button1_setcaption (ByVal ControlName As String, Byval E ASSetCaptionEventArgs) E.CAPTION = "Click ME!" End Sub

When the control is about to be rendered, setcaption and prerender events will be initiated in order. You can dynamically set the title by SetCAption. Other control values ​​and properties can be set by prerender:

Private sub button1_prender (Byval E AS prerenderEventArgs) 'set the Button Caption to bold e.displayprops.fontweight = "bold" End Sub

For more complex controls, you can use the prerender event to achieve a better effect. For example, for a radio button group, a list box, a composite box control, you can dynamically set the item you want to display in the respective control in the prerender event.

Finally, the onaction property in the configuration.xml file sets the name of the "Action" event handler when the button event (button event is raised when the user clicks the button):

Private Sub Button1_Action (ByVal controlName As String, ByVal e As ActionEventArgs) 'Show a message box when the button is clicked MessageBox.Show (string.Format ( "You clicked button' {0} '!", ControlName)) End Sub

As you can see, this is very similar to the ASP.NET in mind:

• The control is defined in a declaration (in the .aspx file or configuration.xml file). • Event handler configuration control and respond to user interaction. Their code is in a separate file (hidden files in ASP.NET, which is OfficeCodeBehind class in the smart document). Back to top

Custom intelligence document

We can conduct a logical definition of the structure of the document by first editing the contents of the DocumentStructure.xsd file, to customize our test smart documentation. Then, we can display different controls in the task pane according to the location of the currently selected content in the document. For this example, we use the Documentstructure.xsd file existing content.

First, let's remove existing green help text from the document. ? Next, click Document Actions at the top of the task pane. A drop-down list will be displayed; click XML Structure. The task pane will now be shown in the figure:

Figure 7. XML Structure Task pane for assigning an XML structure to a document

• Click the DocumentSections element in the list box at the bottom of the task pane. A dialog will be displayed, asking you to apply this element throughout the document, or applied to the current selected content. • Select Apply to Entire Document. If the show xml tags in the document in the task pane is not selected, please select it. Now you will see the XML format represented by pink tags in the document. Next, add text "Section 1" and "Section 2" to the inside of the document body. • Select Text "Section 1" and click Section 1 in the list box at the bottom of the task pane. Next, select Text "Section 2" and click Section 2 in the list box. This document should now be shown in the figure:

Figure 8. Assign an XML structure to the document section

Now, we have associated text "section 1" associated with the section1 element of the documentstructure.xsd file, associated with the section "section 2" with the section2 element. • Click XML Structure at the top of the task pane, and then click Document Actions to display the Document Actions task pane again.

Now, in accordance with whether or not the current selected content is in text "section 1" or text "section 2", the control in the task pane will be changed accordingly. Here is the control that is displayed when the content is displayed in "Section 1":

Figure 9. Smart documentation when selecting "Section 1"

Here is the control that is displayed when the content is displayed in "Section 2":

Figure 10. Smart documentation when selecting "Section 2"

Observe the task pane, only "Sample" section containing the section 1 Button control is only displayed when a part of the document text "Section 1" is selected. This is because the Section 1 Button control is defined in the configuration.xml file to reside in the section DocumentAction section:

currently not defined in the corresponding file Configuration.xml DocumentAction section of Section2. This is the reason why the control is displayed in "Entire Schema Section" when the selected content is located in "Entire Schema Section" (see Figure 10).

Back to top

Debugging intelligent documentation

Debugging is simple. You only need to set a breakpoint in your code, press F5, and start using a smart document. When the breakpoint is executed, it will be suspended in Visual Studio. Some of the reason why all this becomes so easy is that the manifest.xml file uses properties for the assembly. This property means downloading the assembly to the Smart Document Solution folder, but runs from its existing location. This means that it is not necessary to move, delete the extension and attach it to the document to get the code update copy.

As a simple example, set a breakpoint in the Button1_SetCaption method, then press F5:

Figure 11. SetCAPTION events for debugging smart documents

Here, you can see the original title in the Configuration.xml file in the debugger pop-up information box (E.cAption = "this Caption!"). The code will replace the existing value with the new title "Click ME!".

Back to top

Bold ideas: array of controls

If you know how many controls you need during design and know the type of these controls, the above model can work well. This is the most common situation in intelligent document development. However, in some cases, if it is possible based on information that can only be obtained only when running (for example, the information in the database), the task pane dynamically fills the task pane, which will be great. The control array is suitable for this situation.

The idea of ​​the array of controls is very simple: in Configuration.xml, you want to dynamically add the control position to place a placeholder, then use the ControlarrayInitialize event to populate the control. You can have any number of control arrays (although the current intelligent document implementation limits the number of controls in a single DocumentAction section is not more than 256).

Let us look at a simple example of using control arrays. Add the following code to the "ActionpertAinstoentireschema" section of the Configuration.xml file and make it just below the Button1 control:

Next, add the following ControlArrayInitialize event handler to the OfficeCodeBehind class:

Private Sub MyControlArray_Initialize (ByVal controlName As String, ByVal e As ControlArrayInitializeEventArgs) 'Create a label: Dim label As SmartDocumentConfiguration.ControlRow label = e.ControlTable.NewControlRow () label.Name = "DynamicLabel" label.Caption = "Dynamic Label Control" label.Type = "C_TYPE_LABEL" e.ControlTable.AddControlRow (label) 'Create a button: Dim button As SmartDocumentConfiguration.ControlRow button = e.ControlTable.NewControlRow () button.Name = "DynamicButton" button.Caption = "Dynamic Button" button.Type = "C_TYPE_BUTTON" e.ControlTable.AddControlRow (button) 'Add the FontWeight =' bold 'property to the button Dim buttonProperty As SmartDocumentConfiguration.PropertyRow buttonProperty = e.PropertyTable.NewPropertyRow () buttonProperty.Name = "FontWeight" buttonProperty .Property_text = "bold" E.PropertyTable.AddPropertyRow (ButtonProperty) 'Associate This Property with The Button Control ButtonProperty.SetParenTrow (Button) End Sub Now running the project in F5. The first thing you will notice is that the array of controls does not appear, it doesn't work! This is because we have not updated the files in the expansion package. In short, when you attach the extension to the document, it copies the file to a new location. The reason for this is that when you attach the extension to the document, you can simplify your intelligent document deployment; the file will be downloaded (probably from the server) to the local computer. However, some strength is required during the development process: the file exists in two locations: a set of files in the Visual Studio project folder, and another set of files in the Smart Document Solutions folder. (Intelligent Document Solution Folder is located at C: / Documents and Settings / User / Local Settings / Application Data / Microsoft / Schemas / SolutionNamespace / SolutionID.) The document that is configured with the managed smart document package describes a process, which can be used. Reconfigure the project so that you don't have to manually delete and reassure the extended package to update the configuration.xml file.

Download a new copy of the expansion package file

• On the Word Tools menu, click Templates and Add-Ins.? .., then click the XML Expansion Pack tab. • Click Remove to separate the extension from the document, and then click the extended package name in the list, click Delete, click Yes to confirm the deletion. Then, click Add.-Ins to browse to the Manifest.xml file, and then click Open. • Click NO to avoid reactivate the extension instruction list security, and finally click OK to attach the extension package. The Document Actions task pane will be shown when the expansion package has been loaded and the smart document begins to run.

Figure 12. Using the Document Actions Task pane using the control array

Note that the fonts in the button are bold (due to the properties set on the control), and the controls in the control array are added to the location where the control array placeholders in the Configuration.xml file.

Back to top

summary

The hosted smart document package combines the user's intelligent document experience with object-oriented, declared, event-driven productivity advantages. In addition, the new project template automatically completes most of the boring work of the creation of intelligent document projects. The hosted smart document package also has a lot of documentation and an example smart document created with Visual Basic .NET and Word to demonstrate almost all aspects of the packaging set. Whether you are an .NET-oriented developer from an unsuccessful document, it is also a business-oriented developer with rich experience in creating smart documents, and hosting smart document packaging can bring you a lot of benefits.

About author

Susan Warren is a senior software engineer with Microsoft E-Commerce Solutions Gold Certification Partner Vertigo Software, Inc.. She recently designed and developed the design and development host of the IssueVision intelligent client application for DevDays 2004. Prior to joining Vertigo, Susan is a project manager for Microsoft, responsible for web and control frameworks in ASP.NET and the Web Matrix and Web Form Designers in Visual Studio .NET.

Keith Craig is a senior software engineer in Vertigo Software Inc. Before joining Vertigo, he developed some ASP.NET and ASP web applications, SQL Server databases, Visual Basic 6 client-server data warehouse applications, and many other software projects. Keith has a Ph.D. in the University of California at Santa Barbara, and is a Microsoft .NET Certification Solution Development Expert (MCSD).

Go to the original English page

转载请注明原文地址:https://www.9cbs.com/read-6529.html

New Post(0)