Link to home
Start Free TrialLog in
Avatar of Cuec
Cuec

asked on

why do I loose my rich text formatting

I wrote lotus script which merges two documents but the results loose its formatting....does anyone know how I can preserve this.
the script is:

Sub Click(Source As Button)
      Dim ws As New NotesUIWorkspace
      Dim uidoc As NotesUIDocument      
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim view As NotesView
      Dim selected As NotesDocument
      Dim selectedit As NotesItem
      Dim subject As NotesItem
      Dim newdoc As NotesDocument
      Dim newit As NotesRichTextItem
      Dim temp As NotesDocument
      Dim tempit As NotesRichTextItem      
      Dim section As NotesRichTextItem
      Dim content As NotesRichTextItem
      Dim mystyle As NotesRichTextStyle
      Dim reptypekey As NotesItem
      
      
      Set db = session.CurrentDatabase
      'find template for report
      '1) find the type of report
      
      Set view = db.GetView("Report_Merge")
      Set selected = view.GetFirstDocument
      Set subject = selected.GetFirstItem("RepType")
      reporttype = "Template for "+subject.text
      
      '2) find the template document for this type of report
      Set view = db.GetView("Report_Temp")
      Set selected = view.GetFirstDocument
      found = False
      Do While Not found
            Set subject = selected.GetFirstItem("SubjectDis")
            If subject.text = reporttype Then
                  found = True
            Else
                  Set selected = view.GetNextDocument(selected)
            End If
      Loop
      Set section = selected.GetFirstItem("RepType")
      subj = section.text
      'record the section names in the order as they appear in the report template
      Set section = selected.GetFirstItem("temp1")
      section1 = section.text
      Set section = selected.GetFirstItem("temp2")
      section2 = section.text
      Set reptypekey = selected.GetFirstItem("RepType_1")
      reptypekey1 = reptypekey.text
      
      
      'get the corresponding contents for each section
      Set view = db.GetView("Report_Merge")
      If Not section1 = "" Then
            '1) find the chunk of documents that belongs to section 1
            Set selected = view.GetFirstDocument
            Set temp = view.GetFirstDocument
            found = False
            Do While Not found
                  Set section = selected.GetFirstItem("RepSection")
                  If section.text = section1 Then
                        found = True
                  Else
                        Set selected = view.GetNextDocument(selected)
                        Set temp = view.GetNextDocument(temp)
                  End If
            Loop      
            '2) get all contents that belongs to the documents in this chunk
            Set tempit = temp.GetFirstItem("temp")
            finished = False
            Do While Not (selected Is Nothing) And Not finished
                  Set section = selected.GetFirstItem("RepSection")
                  If section.text = section1 Then
                        Set content = selected.GetFirstItem("Content")
                        Call tempit.AppendText(content.text)
                        Call tempit.AddNewLine(2)
                        Set selected = view.GetNextDocument(selected)
                  Else
                        finished = True
                  End If
            Loop
            content1 = tempit.text            
      End If
      
      'get the corresponding contents for each section
      Set view = db.GetView("Report_Merge")
      If Not section2 = "" Then
            '1) find the chunk of documents that belongs to section 1
            Set selected = view.GetFirstDocument
            Set temp = view.GetFirstDocument
            found = False
            Do While Not found
                  Set section = selected.GetFirstItem("RepSection")
                  If section.text = section2 Then
                        found = True
                  Else
                        Set selected = view.GetNextDocument(selected)
                        Set temp = view.GetNextDocument(temp)
                  End If
            Loop
            '2) get all contents that belongs to the documents in this chunk
            Set tempit = temp.GetFirstItem("temp")
            finished = False
            Do While Not (selected Is Nothing) And Not finished
                  Set section = selected.GetFirstItem("RepSection")
                  If section.text = section2 Then
                        Set content = selected.GetFirstItem("Content")
                        Call tempit.AppendText(content.text)
                        Call tempit.AddNewLine(2)
                        Set selected = view.GetNextDocument(selected)
                  Else
                        finished = True
                  End If
            Loop
            content2 = tempit.text
      End If
      
      Set mystyle = session.CreateRichTextStyle
      Set newdoc = view.GetFirstDocument
      Set newit = newdoc.GetFirstItem("temp2")
      If Not (section1="" And content1="") Then
            Call newit.AppendText(section1)
            Call newit.AddNewLine(2)
            Call newit.AppendText(content1)
            Call newit.AddNewLine(1)
            Call newit.AppendText("--------------------------------------------------------------------")
            Call newit.AddNewLine(2)
      End If
      If Not (section2="" And content2="") Then
            Call newit.AppendText(section2)
            Call newit.AddNewLine(2)
            Call newit.AppendText(content2)
            Call newit.AddNewLine(1)
            Call newit.AppendText("--------------------------------------------------------------------")
            Call newit.AddNewLine(2)
      End If      
      Set uidoc = ws.ComposeDocument("","","Report Skeleton")
      Call uidoc.FieldSetText("Subject", subj)
      Call uidoc.FieldSetText("ReportContent", newit.text)
      Call uidoc.FieldSetText("RepType", subj)
      Call uidoc.FieldSetText("DocType_1", reptypekey1)
End Sub
Avatar of CRAK
CRAK
Flag of Netherlands image

Avoid using the NotesRichtext.Text property. That's where the formatting get stripped from the content.
Avatar of Cuec
Cuec

ASKER

what should I use instead?
ASKER CERTIFIED SOLUTION
Avatar of CRAK
CRAK
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
How are you doing, Cuec?