Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Designing Smart Documents in Office 2003 : Page 3

Today, most organizations have a wealth of Office documents that contain critical information, but finding, extracting, and reusing that information programmatically remains a largely unrealized goal. Fortunately, that's changing as XML processing in Microsoft Office 2003 grows up.


advertisement
Applying Schema
The schema definition in Listing 1 should give you an idea of how to design custom markup in XML format. You need to apply the schema defined in the XSD to the document. You can add schema and UI structure dynamically (via programming) using bookmark identifiers or you can pre-define them while creating the template. For now, take the pre-defined approach, which you can accomplish using only Word.

  1. Open the document template, click the dropdown menu at the top of the Task pane and select "XML Structure."
  2. Click the Tools menu and select "Templates and Add-Ins"—the Options tab pops up with default as "XML Schema."
  3. Click "Add schema" and select the Customer.xsd schema. By clicking the XML Options button, you can see the various XML Options settings available for the document. For now, leave the default settings and click OK.
  4. In the XML Structure task pane you'll see a documentRoot element. Click that element in the task pane. You get an information box asking you whether to apply the element for the entire document or just the selection. Click on "apply to entire document". Word will add a pink DocumentElement tag surrounding the document content.
  5. In the XML Structure task pane's "elements in the document" section you'll see a yellow question mark indicator which informs you that something is missing in the document and the schema is not valid. The next element to select is displayed as section in the "Choose an element to apply" area at the bottom of the task pane.
  6. Click the documentElement tag, which will select the content (the two tables) and then click the section element in the task pane. Word applies that tag with a different indicator in the XML Structure task panes "documentRoot" element. Right click the element and you'll see a message stating that the content for that element is incomplete. Click the "Attributes" option and add the values shown in the enclosed document template.
  7. Select the first (Customer) table and then click the customer element in the task pane to apply that to the table. Continue by clicking in the appropriate table fields to apply the customername, and address elements, selecting each child element from the task pane. Repeat these actions to define the elements for the Item table. Note that Word does validate, but it doesn't stop you from creating invalid schema, especially when you're working manually against an unprotected document.
Author's Note: You don't have to apply the region element and attributes right now because you'll see an example of adding node attributes and values dynamically later in this article.

Creating a Shim
You've done the configuration work you need to get started programming. Now you need to make the document intelligent. If you were wondering why I mentioned you need VB 6.0 installed, it's because you can create VB 6.0-based wrapper classes (not PIA) that will make calls to managed code. Though these are not required to program Office 2003 applications, to get started easily we use shims. If you specifically want to avoid using shims, refer to this article on MSDN for more information. Doing this will require configuration changes with your manifest and altering CAS settings for the managed code. Assuming you opt for unmanaged shims as described here (called "Action Handlers" in SmartDocument terminology), the approach is as follows:

  1. Create a new VB6 ActiveX DLL project and name it as DocumentShim. Rename the default class to SmartDocShim.cls
  2. Add a reference to the Microsoft Smart Tags 2.0 Type library and implement the ISmartDocument interface.
  3. Each method/property of this interface is significant as discussed later. For now, create an instance of ISmartDocument type in the SmartDocInitialize event, for example:

Private ObjSmartdocument as ISmartDocument Private Sub ISmartDocument_SmartDocInitialize(...) Set objSmartdocument = CreateObject( _ "Office.Samples.SmartDocument.Customer") ... End Sub

The class ID in the preceding code refers to a managed code Customer class DLL that you will create. This VB6 DLL simply acts as a hookup to the managed code.

  1. You implement all method/property calls and route the calls to the managed code instance defined within the SmartDocInitialize method. The class file SmartDocShim.cls in the DocumentShim.vbp project is just a direct hookup of the initialized document. You can find a thorough explanation of the reasoning behind this method of implementing the definitions in this MSDN article.
Author's Note: The shim needs to interoperate with managed code arrays in few methods, which is why you will see a ResetArrayList method in SmartDocShim.cls.




Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date