Integration of Domino and word
Chen Bin, software engineer, and IBM Chen Bin are senior software development engineers from IBM cstl. They are now responsible for the development, support, and team leadership of Lotus Domino for IBM I. Chen Yun, software engineer, and IBM Chen Yun are software development engineers from IBM cstl. They are now engaged in the development and support of Lotus Domino for IBM I.
Introduction:In most OA (office automation) systems, there are modules that involve document circulation. These modules are often the core modules of the entire OA system. There is a lot of demand in document circulation, it is to retain the "Traces" in the circulation of documents (for example, who added, deleted, or modified the document, the leaders' opinions, and comments, for reference by various personnel during document circulation. This article describes how to use Lotus script to trace Microsoft Word documents in document flow.
Mark this article!
Release date:November 30, 2010
Level:Elementary
Access status836 views
Suggestion: 0 (Add Comment)
Average score (1 in total)
Object Linking and Embedding (OLE) object
OLE technology, called object connection and embedding technology, is an object-oriented technology that defines and implements applications.ProgramAs a mechanism for connecting objects to each other to complete integration between applications. Ole is a set of comprehensive standards for transmitting and sharing information between customer applications. Based on the Component Object Model (COM ), it has been widely used in workbooks, word processing, financial software, project management software, and so on.
Createobject and GetObject Functions
To create or obtain an OLE object in Lotus script, you must use the Createobject function or the GetObject function.
Createobject Function
Create an OLE object of the specified type
Syntax
Createobject (classname)
Parameters
Classname is a string in appname. appclass format, indicating the type of the object to be created, such as "wordpro. application ". Appname indicates the application name that supports Ole, and appclass indicates the type of the object to be created
Return Value
Returns an OLE object reference.
Usage
In Lotus script, set is used to assign the object reference returned by the Createobject function to a variable of the variant type (variant.
If this type of application is not running, the Createobject function starts this application before creating an OLE object. The OLE object reference is valid only when the application is running. If the application exits when the OLE object reference is used, LotusScript throws a runtime error. Each OLE object has a set of classes defined and provided by it, through which the application can be operated.
Example
Sub initialize 'create a word. Application object set MyApp = Createobject ("word. application") 'and set the visible attribute of this object to true MyApp. Visible = true end sub |
GetObject function
Open the OLE object contained in an application file or return a specified type of OLE object for the current activity.
Syntax
GetObject ([pathname] [, classname])
Parameters
Pathname: An application file that contains the full path file name or is empty. This application must support Ole. If it is an empty string ("") or omitted, you must specify a classname and return the objects of the current activity.
Classname is the same as the classname parameter of Createobject. However, it can be omitted. If it is omitted, more pathname is used to determine the returned OLE object.
Return Value
Returns an OLE object reference.
Usage
Same as Createobject
Example
Sub initialize dim mydoc as variant 'obtains the wordpro. Document Object from the file. Set mydoc = GetObject ("D: \ wordpro \ docs \ test. lwp", "wordpro. Document") 'calls the print method of the wordpro. Document Object. Mydoc. Print end sub |
Back to Top
Achieve Microsoft Word document mark in document flow
The following example shows how to use Lotus script to mark Microsoft Word documents in the document flow. In this example, the user first creates a manuscript, the body is a Word document, the poster writes the text and saves it as an attachment, and then submits it for review. The review process will show marks, after the review is completed, a formal document will be formed. You can view the body but cannot modify it later. You can view or hide the revised information. In this example, no error handling is added to make the reader look convenient.CodeIn practice, you must add this Code to ensure that the word program exits and the temporary files are cleared when an error occurs.
First, create a blank wordtest. NSF creates a form named "Post", not "fawen". To simplify the form, it only contains three fields: Status, title, and body. Status indicates the status of the document flow. Each form button is hidden or displayed based on the status value. Status itself is always hidden. title indicates the title of the text, and the body stores the word body, which is always hidden, this prevents you from using the form button to operate the word body in the body field. In this example, a simple document flow process is implemented, including document drafting, approval, and viewing after approval. All codes are completed in the document form operation. Next let's take a look at the code for drafting the body.
Listing 1
Sub click (source as button) dim activedoc as variant dim wordapp as variant dim s as new notessession dim ws as new notesuiworkspace dim dB as notesdatabase dim uidoc as notesuidocument dim doc as notesdocument set DB = s. currentdatabase set uidoc = ws. currentdocument set Doc = uidoc. document dim rtitem as notesrichtextitem set rtitem = Doc. getfirstitem ("body") if rtitem is nothing then set rtitem = new notesrichtextitem (Doc, "body") end if 'defines the file name and full path file name dim sfilename as string, sfilepath as string 'determines the text file name sfilename = trim (uidoc. fieldgettext ("title") + ". doc "If sfilename = ". doc "then msgbox" Enter the title "Call uidoc. gotofield ("title") Exit sub end if sfilepath = "C: \" + sfilename 'create the word object set wordapp = Createobject ("word. application ") wordapp. visible = true' open or create a new body if not openworddoc (wordapp, uidoc, sfilename) Then exit sub 'activate the current document set activedoc = wordapp. activedocument 'sets the author of the Word document as the current user's wordapp. username = S. commonusername wordapp. activate activedoc. activate 'maximize wordapp in the word window. windowstate = 1' save after editing and exit word msgbox "Click OK to complete editing", 32, "message" 'Save the body and exit word call activedoc. saveas (sfilepath) Call activedoc. close (0) Call wordapp. quit (0) set activedoc = nothing set wordapp = nothing 'attaches the modified body set rtitem = new notesrichtextitem (Doc, "body") Call rtitem. embedobject (embed_attachment, "", sfilepath) Doc. saveoptions = 0 call uidoc. close Doc. saveoptions = 1 Doc. status = "draft" Doc. form = "fawen" Call Doc. save (True, true) 'delete the temporary file kill sfilepath call ws on the hard disk. editdocument (false, DOC) msgbox "body drafted" End sub |
In this example, determine the name of the word body File Based on the title, create a word object, set word visibility, and call openworddoc () function to create or open a Word document that already exists in the body field, and then pass the current Notes user name to the word as the author of the Word document and activate the word program. The following sentence is very important, it is equivalent to pausing the program so that users can write the text body in the Word document. After the editing is complete, click OK to continue the subsequent program execution.
Msgbox "Click OK to complete editing", 32, "message" |
After editing, call the VBA-related method to save the Word document, exit the word program, embed the text into the body field, and delete the temporary files that are left on the hard disk.
The following is the implementation of the openworddoc () function:
Listing 2
Function openworddoc (wordapp as variant, uidoc as notesuidocument, sfilename as string) as Boolean openworddoc = true dim doc as notesdocument set Doc = uidoc. document 'if the body attachment already exists, open the modification directly. Otherwise, create an empty word file based on the status or exit dim attachment as notesembeddedobject set attachment = Doc. getattachment (sfilename) if not attachment is nothing then if dir $ (attachment. name) <> "" Then kill "C: \" + sfilename "unbind the body attachment to the hard disk and enable call attachment. extractfile ("C: \" + sfilename) Call wordapp. documents. open ("C: \" + sfilename) if not Doc. status (0) = "reviewed" then call Doc. removeitem ("body") end if else if (Doc. status (0) = "draft") or (Doc. status (0) = "") then call wordapp. documents. add else msgbox "No body found. Draft the body first." openworddoc = false exit function end if end Function
|
This function is relatively simple. First, determine whether the word body already exists. If it exists, decompress it to the hard disk and call the open () method to open the Word document with word. Otherwise, based on the current posting status, if you create a new word document in the draft phase, otherwise an error is reported and you exit.
The drafting body can be completed multiple times. Once the drafting is completed, you can click "submit for review" to enter the review stage. The operation code is as follows, set the value of the Status field to "under review". The code is very simple and will not be analyzed here.
Listing 3
Sub click (source as button) dim ws as new notesuiworkspace dim uidoc as notesuidocument dim doc as notesdocument set uidoc = ws. currentdocument set Doc = uidoc. document dim rtitem as notesrichtextitem set rtitem = Doc. getfirstitem ("body") if rtitem is nothing then msgbox "No body found, draft the body first" Exit sub end if Dim sfilename as string sfilename = trim (uidoc. fieldgettext ("title") + ". doc "dim attachment as notesembeddedobject set attachment = Doc. getattachment (sfilename) If attachment is nothing then msgbox "No body found. Please draft the body first" Exit sub end if uidoc. editmode = true call uidoc. fieldsettext ("status", "under review") Call uidoc. save msgbox "submitted for review" Call uidoc. close end sub |
After submitting the review, you will enter the review stage. clicking "Review Body" will open the word body in the body field and set the body to the revised state, in this way, all changes to the document will be recorded. The Code is as follows:
Listing 4
Sub click (source as button) dim activedoc as variant dim wordapp as variant dim s as new notessession dim ws as new notesuiworkspace dim dB as notesdatabase dim uidoc as notesuidocument dim doc as notesdocument set DB = s. currentdatabase set uidoc = ws. currentdocument set Doc = uidoc. document dim rtitem as notesrichtextitem set rtitem = Doc. getfirstitem ("body") if rtitem is nothing then msgbox "No body found, draft the body first." Exit sub end if 'defines the file name and full path file name dim sfilename as string, sfilepath as string 'determines the text file name sfilename = trim (uidoc. fieldgettext ("title") + ". doc "sfilepath =" C: \ "+ sfilename 'create the word object set wordapp = Createobject (" word. application ") wordapp. visible = true' hide the relevant menu call hidewordmenu (wordapp) 'in word to open the body if not openworddoc (wordapp, uidoc, sfilename) then exit sub 'activate the current document set activedoc = wordapp. activedocument 'sets the author of the Word document as the current user's wordapp. username = S. commonusername wordapp. activate activedoc. activate 'maximize wordapp in the word window. windowstate = 1' sets trace protection if activedoc. protectiontype =-1 then activedoc. protect (0) end if activedoc. trackrevisions = true activedoc. printrevisions = true activedoc. showrevisions = true' save and exit word msgbox after review is complete ", 32," message "'Restore word menu call wordapp. commandbars ("menu bar "). reset Call activedoc. saveas (sfilepath) Call activedoc. close (0) Call wordapp. quit (0) set activedoc = nothing set wordapp = nothing 'attaches the body set rtitem = new notesrichtextitem (Doc, "body") Call rtitem. embedobject (embed_attachment, "", sfilepath) Doc. saveoptions = 0 call uidoc. close Doc. saveoptions = 1 Doc. status = "checking" Call Doc. save (True, true) 'delete the temporary file kill sfilepath call ws on the hard disk. editdocument (false, DOC) msgbox "End of body review" End sub |
In the above Code, there are two parts to be discussed in detail.
The first is to hide the relevant menus in Word by calling hidewordmenu (), and the second is to implement the specific revision mark, which is analyzed separately below.
Use hidewordmenu () to hide the relevant menu in word. The Code is as follows:
Listing 5
Sub hidewordmenu (wordapp as variant) dim commandbar as variant 'hide tool menu set commandbar = wordapp. commandbars. findcontrol (, 30007, true) if not commandbar is nothing then commandbar. visible = false commandbar. enabled = false end if 'hide the VB Editor menu set commandbar = wordapp. commandbars. findcontrol (, 1695, true) if not commandbar is nothing then commandbar. visible = false commandbar. enabled = false end if 'hide the recording macro menu set commandbar = wordapp. commandbars. findcontrol (, 2780, true) if not commandbar is nothing then commandbar. visible = false commandbar. enabled = false end if end sub |
This process hides the tool menu of word, the VB Editor menu, and the recording macro menu, to avoid misoperation during user review and change the revision trace status of the current document. In practical applications, this is more complex. You may need to hide more menu items and add custom menus, which is related to the project details. To hide any menu, use the findcontrol () method to obtain the menu. For detailed usage of this method, see VBA help. To use this method, the most important thing is to obtain the menu ID to hide. For example, in the code above, the tool menu ID is 30007, And the id value remains unchanged, you can use a simple program to obtain the word menu ID. also available in NSF, specifically in the document form operation "take word menu ID. The Code is as follows:
Listing 6
Sub click (source as button) 'create the word object dim ws as new notesuiworkspace set wordapp = Createobject ("word. application ") wordapp. visible = true TMP $ = "" for I = 1 to 35000 set CTL = wordapp. commandbars. findcontrol (, I) if not CTL is nothing then TMP $ = TMP $ + CSTR (I) + ": caption =" + CTL. caption + CHR (13) + CHR (10) end if next call ws. currentdocument. fieldsettext ("body", TMP $) Call wordapp. quit (0) set wordapp = nothing end sub |
If you run this program, the correspondence between the IDs and names of all word menus will be obtained in the body field of the form. This program is simple, that is, to enumerate all IDs. Note that in wordtest. nsf, the body field and the operation "retrieve word menu ID" are hidden. To use this function, you must first remove the hidden Formula.
Achieve specific revision marks
The main code is as follows:
Listing 7
If activedoc. protectiontype =-1 then activedoc. Protect (0) end if activedoc. trackrevisions = true activedoc. printrevisions = true activedoc. showrevisions = true |
Here, protectiontype returns the Protection Type of the current document. The possible values and descriptions are as follows:
- -1 is not protected
- 0 only revisions and comments are allowed
- 1. Only comments are allowed.
- 2. cannot be modified or annotated
First, determine whether the current document protection has been enabled. If not, the current document will be protected at a level that can be revised and annotated. Note that you must first use protectiontype to determine whether the current document has been protected. Otherwise, if the document has been protected, the protect method will report an error.
Set the attributes trackrevisions, printrevisions, and showrevisions to true respectively. This ensures that all the modifications are marked when the user modifies the text, and all the modifications are displayed, it will also be printed. The modifications mentioned here include adding, modifying, and deleting. The following describes the three attributes:
- Document. trackrevisions: If the attribute value is true, the modifications to the specified document are marked. Boolean type, which can be read and written.
- Document. printrevisions: If the attribute value is true, the revision mark is printed while the document is printed. If false is returned, the revision mark is not printed (that is, the status after the revision is accepted ). Boolean type, which can be read and written.
- Document. showrevisions: If the attribute value is true, a revision to the specified document is displayed on the screen. Boolean type, which can be read and written.
After the review is completed, the body can be set to read-only protection, and the function of viewing the body is also provided, you can view the text in either the revision information display or the revision information hidden, allowing authorized users to view the text. These functions are mainly implemented by setting the Document Protection and revision status, the specific code can be found in wordtest. the NSF post form is displayed in the corresponding action.
Demonstrate document mark keeping Function
Below are the steps to demonstrate document TRACE in wordtest. nsf and:
-
- Open wordtest. nsf in the Notes Client
Figure 1. Open wordtest. nsf in the Notes Client
-
- Click "new" in the view to create a document.
Figure XXX. Requires a heading
-
- Click "new" in the view to create a document.
Figure 2. Create a Word document
- Enter the title and click the "Draft body" button. A new word document is created and the document content is drafted in this document.
Figure 3. Switch to the Notes Client
-
- Click OK. The system automatically saves the Word document and saves it as an attachment in the hidden body domain.
-
- You can click the "Draft body" button multiple times to edit the draft.
-
- After drafting, click "submit for review". In this way, the status of the body is set to "under review", and the "Draft body" and "submit for review" buttons are hidden, the "Review Body" and "Review completed" buttons are displayed.
Figure 4. The "Review Body" and "Review completed" buttons are displayed for submission and review.
-
- Click the "Review Body" button to go to the review process. This process can be completed by multiple people. During this process, any changes to the body will be retained, including who modified the body, at the same time, you can see that the corresponding menu has been hidden.
Figure 5. Enter the review process
-
- After the review is complete, click the "Review completed" button, and the body will be read-only, indicating that this is the final revised version. At the same time, the original "Review Body" and "Review completed" buttons are hidden and the "view body" button is displayed.
Figure 6. view the body
-
- When viewing the body, if you select to display the revision information, the content is the same as the status before the final review, and the modification trace is displayed directly, but it cannot be modified again, if you choose to hide the revision information, all the modifications are merged and displayed.
Figure 7. view the body
Back to Top
Conclusion
This example shows how to use Lotus script to implement the Common Document mark-keeping function in the OA system. It is expected that more complex mark-keeping functions can be implemented based on this.
Back to Top
Download
Description |
Name |
Size |
Download Method |
Download the code in this article |
Wordtest.zip |
41 KB |
HTTP |
Information about the Download Method
References
Learning
- See developerworksArticle: "How to Process Groups in Lotus script ".
- See the developerworks article: "using LotusScript to automatically generate and Operate Excel reports ".
- See the developerworks article "simulate events for custom objects in Lotus script ".
- See the developerworks article "using Lotus script to flexibly operate rich text fields in Lotus Notes ".
Discussion
- Join my developerworks ChineseCommunity.
Author Profile
Chen Bin is a Senior Software Development engineer from IBM cstl and is now responsible for the development, support and team leadership of Lotus Domino for IBM I.
Chen Yun is a software development engineer from IBM cstl and is now engaged in the development and support of Lotus Domino for IBM I.