Subject: Importing html to richtext field
Here is some simple code to import a straight HTML ascii file into a Rich Text Field in a form called “Memo”. What you do with it once there is up to you - I am using this code as part of a mail-merge function to take HTML generated by MS Word, personalize it from a Notes database source, and email it out. It is activated by an action from another document that contains some parameters that my mail-merge needs, but you could bypass all of the references to “curdoc” in the code.
Hope this all helps.
Type EditImportData
FileName As String * 100
FontID As Long
End Type
Declare Function ImportHtmlTextFile Lib “NIHTML” Alias “ImportHtmlTextFile”_
( D As EditImportData, Byval F As Integer, Byval M As Long, Byval A As String, Byval N As String) As Integer
Declare Sub NEMDisplayError Lib “NNOTESWS” Alias “NEMDisplayError” ( Byval S As Integer)
Declare Function MailAddMessageBodyComposite Lib “NNOTES” Alias “MailAddMessageBodyComposite” _
( Byval hM As Long, Byval N As String, Byval F As String) As Integer
Sub Click(Source As Button)
Dim session As New NotesSession
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim curdoc as NotesDocument
Dim doc as NotesDocument
Set uidoc = workspace.CurrentDocument
Set curdoc = uidoc.Document
Set doc = New NotesDocument(session.CurrentDatabase) ' create a new document to contain the import
infile$= curdoc.ImportFileName(0) 'this is the name of the file to be imported - in my case it's a variable, but you could make it a constant like "C:\InputDocument.htm"
Set rti = New NotesRichTextItem(doc, "Body") ' create a rich text object
With doc
.Subject=curdoc.Subject(0)
.Form = "Memo"
Call ImportHTMLFile(doc, infile$, "Body") ' this is where the import happens
rti.IsSigned = False
rti.IsEncrypted = False
Call workspace.EditDocument(True, doc,,,True)
End With
End Sub
Sub ImportHTMLfile(doc,filename$, field$)
Const temp = "C:\TEMP\NOTESCD.TMP"
Dim D As EditImportData
D.FileName = temp
s% = ImportHtmlTextFile(D, 3, 0, "", filename$)
If Not s% = 0 Then
NEMDisplayError s%
Exit Sub
End If
With doc
s% = MailAddMessageBodyComposite(.Handle, field$, temp)
If Not s% = 0 Then
NEMDisplayError s%
Exit Sub
End If
End With
Kill temp
End Sub