logo

Response

« Return to the main article

You are viewing this page out of context. To see it in the context it is intended please click here.

About This Page

Reply posted by Jonathon Llewellyn Thomas on Mon 20 May 2002 in response to Keeping the boss happy

Exporting selected documents only... Example

Hi All


I've been using this export method quite a lot recently and found it and
excellent tool. One of the things I decided to do was allows users to export
selected document only (from a Discussion View) to MSWord.


The first thing I did was to search various Domino sites until I found an
existing method of processing selected documents on the web (much easier than
writing my own!). Anyway, much of this code I have taken from Notestips.com
and the original code can be found here:


http://www.notestips.com/80256B3A007F2692/0/F6B360E79988B37780256B7800809555?Ope
nDocument


I've just added a few feature to allow the export to Word (including how to
handle RichText etc.. and a simple search and replace feature (again,
'borrowed' from Notes.net).


Anway, I figure some people may find this useful as an example.


i. follow the instructions from the notetip page (or download the sample
database).


ii. my code for the script library is as follows (agent remains the same).


Sub ProcessMultiple(opWebDocument As NotesDocument)

On Error Goto SubError

' ******** OBJECTS *************************************
Dim oSession As NotesSession
Dim oDatabase As NotesDatabase
Dim oSelected As NotesDocument
Dim oRTItem As Variant
Dim PlainText As String
Dim CreateDate As Variant
Dim todaysDate As String

Set oSession = New NotesSession
Set oDatabase = oSession.CurrentDatabase

' ******** VARIABLES ***********************************

Dim vLoop As Long
Dim vHTML As String
Let vLoop = 0
todaysDate=SearchReplace(Date$,{/},{_})

' ******** PROCESS SELECTED DOCUMENTS ******************

vHTML = vHTML + {<FONT Face="Arial" SIZE="4"><B>General Discussion
Area</B></FONT><BR><BR>}
vHTML = vHTML + {<TABLE STYLE="font : 8pt Verdana">}

Print{Content-Type:application/msword}
Print {Content-Disposition:Attachment; filename="DiscussionDocuments_}
+ todaysDate + {.doc"}

Forall DocID In opWebDocument.CheckBox

Set oSelected = oDatabase.GetDocumentByUNID(DocID)

CreateDate = oSelected.Created

vHTML = vHTML + "<TR><TD><B>" + oSelected.subject(0) +
{</B></TD><TR><TD>}
vHTML = vHTML + oSelected.From(0) + { - } + Cstr(CreateDate) +
{</td></tr>}

Set ortitem = oSelected.GetFirstItem( "Body" )
If ( ortitem.Type = RICHTEXT ) Then
plainText = ortitem.GetFormattedText( False, 200 )
End If

If oSelected.hasItem("ParentForm") Then
vHTML = vHTML + "<TR><TD><B>Response Document</B></TD></TR><TR><TD>"
+ plainText + {</TD></TR>}
Else
vHTML = vHTML +"<TR><TD>" + plainText + {</td></tr>}
End If

vHTML = vHTML + "<TR></TR>"

' ** PROCESS DOCUMENT **
oSelected.Save True, True

' ** PROCESS DOCUMENT **

End Forall



' ******** PRINT RESULTS ****************************

Print vHTML

' ******** EXIT *************************************
SubExit:
Exit Sub

' ******** ERROR TRAP *******************************
SubError:
Print "Error:" + Cstr(Err) + " " + Error
Resume SubExit
End Sub


iii. the code for the Searchand Replace function as follows (included in the
library). NOTE: turn off option declare/explicit or declare all variables in
following script:


Function SearchReplace(FullString$ , OldText$ , NewText$) As String
REM This function will replace OldText$ with NewText$ in FullString$
REM Example Call: URL$ = SearchReplace(URL$ , {.com/} , {.net/})

AnyText$ = FullString$

pos& = Instr(AnyText$ , OldText$)

While pos& > 0
AnyText$ = Left$(AnyText$,pos& -1) + NewText$ +
Right$(AnyText$,Len(AnyText$) - pos& - Len(OldText$) + 1)
pos& = pos& + Len(NewText$)
pos& = Instr(pos&, AnyText$ , OldText$)
Wend

SearchReplace = AnyText$

End Function


And there you have it, this works brilliantly for me.


Hope this is of use to other people.


Regards
Jonathon