Table color through lotusscript

Hi,

I have developed an agent ( given below ) , which sends an table report to the persons. this agent takes the reference by taking view.allentries and then entry.document and so on.

Now the thing comes up when department needs certain changes like they need also color table, like we have this view contains information about tickets they are receiving from their respective customers, and there in also stautus like open/closure… like that,…

So we have been told that if the tickets those are on closuere or pending should be as red background color in table ( ie table cell should be “Red” color, if the closed then it would treat as "Green " background color.

Now the agent i developed sends an plain table and data into that. now the question comes around making them colorful depends on the status of the information.

here the code of the agent goes

////////////////////////////////////////////////////////////////////

Sub Initialize

Dim VwDocCreated As NotesView

Dim doccoll As NotesDocumentCollection

Dim maildoc As NotesDocument

Dim ritem As notesrichtextitem 

Dim  viewentryColl As NotesViewEntryCollection 

Dim FldTitles(4) As String

Dim FldNames(4) As String

Dim msgTitle As String

Dim msgBody As String

Dim Recep(1) As String

Dim rtnav As NotesRichTextNavigator



Set session=New NotesSession

Set db=session.CurrentDatabase

’ view to be used

Set VwDocCreated=db.GetView("Sev1\By StartDate")

'document collection generated from the specified view

'Set doccoll=VwDocCreated.GetAllDocumentsByKey(“Y”,True)

Set viewentryColl = VwDocCreated.AllEntries

'Set docvw24Hrs=VwDocCreated.GetFirstDocument 

’ Field titles/ Report headings to be set

FldTitles(0)="test1"

FldTitles(1)="test2"

FldTitles(2)="test3"

FldTitles(3)="Incident Ticket Number"

FldTitles(4)="test4"

’ Field names/ item names in the documents corresponding to the field titles

FldNames(0)="xr"

FldNames(1)="sy"

FldNames(2)="z"

FldNames(3)="1"

FldNames(4)="Doc_Link"

’ For using a document link use the field name as ‘Doc_Link’

'Recepients mailing address

Recep(0)="XUZ"

'Message title

msgTitle="This is an auto generated mail. Please do not reply"

'Message body

msgBody="test"



If  viewentryColl.Count >0  Then

	Set maildoc=db.CreateDocument

	maildoc.form="memo"

	maildoc.subject="test"

	maildoc.sendto=Recep

	Set ritem=New NotesRichTextItem(maildoc,"body")

’ passing the rich text item & other relevant details

	Set ritem=CreateTable(FldTitles,FldNames,viewentryColl,ritem,msgTitle,msgBody)

	

	ritem.AddNewline(2)

	ritem.AppendText("--------------------------------------------------------------------------------------------------------------------------")

	

	maildoc.Send(False)

End If

End Sub

//////////////////////////////////////////////////////////////////////

Function CreateTable(FldTitles As Variant ,FldNames As Variant, viewentryColl As NotesViewEntryCollection,rtitem As NotesRichTextItem,msgTitle As String,msgBody As String ) As NotesRichtextitem

'Function starts 'from here*

'Takes Documentcollection & creates tabular information on to the passed rtitem (rich text item)

Set ritem=rtitem

Set rtnav = ritem.CreateNavigator



Set rstyle=session.CreateRichTextStyle

'===================================================

'heading in the body section of the mail

rstyle.Bold=True

rstyle.NotesColor=COLOR_RED

rstyle.Underline=True

rstyle.NotesFont=FONT_COURIER

rstyle.FontSize=12

Call ritem.AppendStyle(rstyle)

ritem.AppendText(msgTitle)



rstyle.Underline=False

rstyle.NotesColor=COLOR_RED

ritem.AddNewline(2)



rstyle.FontSize=10

rstyle.Bold=False

rstyle.NotesColor=COLOR_BLACK

Call ritem.AppendStyle(rstyle)

ritem.AppendText(msgBody)

ritem.AddNewline(1)

'===================================================

rows=viewentryColl.Count +1

cols=Cint(Ubound(FldTitles)+1)



Call ritem.AppendTable(rows,cols)

Call rtnav.FindFirstElement(RTELEM_TYPE_TABLECELL)

'=================================================

'heading of the table

rstyle.Bold=True

rstyle.NotesColor=COLOR_BLUE

rstyle.FontSize=10

Call ritem.AppendStyle(rstyle)



For i=0 To Ubound(FldTitles)

	Call ritem.BeginInsert(rtnav)

	Call ritem.AppendText(FldTitles(i))

	Call ritem.EndInsert

	Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)

Next

'=================================================

rstyle.FontSize=10

rstyle.Bold=False

rstyle.NotesColor=COLOR_BLACK

Call ritem.AppendStyle(rstyle)



Set entry=viewentryColl.GetFirstEntry 





While Not (entry Is Nothing)

	

	For i=0 To Ubound(FldNames)

'check for date/ names document link

		Call ritem.BeginInsert(rtnav)

		Set entrydoc = entry.Document 

		If FldNames(i)="Doc_Link" Then

			Call ritem.AppendDocLink(entrydoc,entrydoc.Created)

		Else

			Set TempNitem=entrydoc.GetFirstItem(FldNames(i))

			If TempNitem.IsNames Then

				Set TempNm=Nothing

				Set TempNm=New NotesName(TempNitem.Values(0))

				Call ritem.AppendText(TempNm.Common)

			Elseif Isdate(TempNitem.Values(0)) Then

				Call ritem.AppendText(Format(TempNitem.Values(0),"DD-MMM-YYYY"))

				

			Else

				Call ritem.AppendText(TempNitem.Values(0))

			End If

			

		End If

		

		Call ritem.EndInsert

		Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)

	Next

	

	Set entry= viewentryColl.GetNextEntry(entry)

	

Wend



Set CreateTable=ritem

End Function

////////////////////////////////////////////

i can play with field that if it is closure then it would go on that way, but i have already done as richtextitem now question comes around how i can implement color table into it.

Thanks

Man

Subject: Table color through lotusscript

I don’t have the time to modify your code, but here is a snippet of code I use for making the heading row in a table a different colour…

'Define colors for the heading and the data cells		

	Dim headerColor As NotesColorObject

	Dim dataColor As NotesColorObject

	Set headerColor = session.CreateColorObject

	Call headerColor.SetRGB(153,204,255)

	Set dataColor = session.CreateColorObject

	Call dataColor.SetRGB(255,255,255)

	

	' create an empty table 

	Call rtf.AppendTable(rowCount,columnCount,,,ThreeColumnStyle)

	

	

	' create navigator to position the text insertion point within table cells.

	Dim nav As NotesRichTextNavigator

	Set nav = rtf.CreateNavigator( )

	

	' Get an object describing the table.

	Dim table As NotesRichTextTable

	nav.FindLastElement RTELEM_TYPE_TABLE

	Set table = nav.GetElement

’ Set table to use different color for the top column.

	table.Style = TABLESTYLE_TOP

	table.SetColor headerColor

	table.SetAlternateColor dataColor

	rtf.AppendStyle columnHeaderStyle ' this will be in effect until changed.

Subject: Table color through lotusscript

I don’t know that you can with the notesrichtexttable class.

One easy way to do it is to use the NotesMIMEEntity class and create an HTML table, assigning it to the rich text field. Look up the SetContentFromText method in the help.