Genii Weblog
Parse table into separate documents
Thu 1 Sep 2005, 04:53 PM
Tweetby Ben Langhinrichs
There was a post on the Gold forum where a person asked:<blockquote>I've got one document with a table (1000 rows) and I want to transfer this table into 1000 single documents. Each row one document. I get the table and the cells with a NotesRichTextNavigator. With normal text it is ok, but when I have a cell with an embedded image, I don't get the image.
If the cell has a doclink, I get the doclink with FindFirstElement(RTELEM_TYPE_DOCLINK), but how do I get an image?
Any ideas?</blockquote>Doug Cohen who works for SUNY (State University of New York) suggested that the person try our Midas Rich Text LSX. He did, and I just wanted to share this code, which is the sample I created which does the job even more easily than I had thought. The following code works even if (as I created in the sample) there are doclinks, images and nested tables. Pretty good for 35 lines of code, wouldn't you agree. I am putting this up as a sample database on our website tomorrow if anybody wants to try it out. Look for the Parse Table sample. Oh, and thanks to Doug Cohen! We depend on people like Doug for word of mouth recommendations, and we appreciate them immensely when they are given publicly like this,
Sub Initialize
' *** Domino class objects
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim newdoc As NotesDocument
' *** Midas class objects
Dim rtitem As New GeniiRTItem
Dim rtchunk As GeniiRTChunk
Dim rtchunk2 As GeniiRTChunk
Dim new_rtitem As New GeniiRTItem
Dim new_rtchunk As GeniiRTChunk
' *** Cycle through each row on the rich text, creating a new document for each and then
' *** appending the chunk which is inside the table cell.
Set db = session.CurrentDatabase
Set doc = session.DocumentContext
Call rtitem.ConnectBackend(doc.Handle, "Body", False)
If rtitem.IsConnected Then
Set rtchunk = rtitem.DefineChunk("Table 1; Row 1")
While rtchunk.Exists
Set rtchunk2 = rtchunk.DefineSubChunk("Inside Column 1")
Set newdoc = New NotesDocument(db)
newdoc.Form = "Example Form"
Call new_rtitem.CreateBackend(newdoc.Handle, "Body")
Set new_rtchunk = new_rtitem.DefineChunk("Everything")
newdoc.Subject = doc.Subject(0) + " (contents of "+rtchunk.Definition+")"
Call new_rtchunk.AppendRTChunk(rtchunk2)
new_rtitem.Save
rtchunk.GetNextTarget
Wend
End If
End Sub
Copyright © 2005 Genii Software Ltd.
What has been said:
360.1. Doug Cohen (09/02/2005 07:46 AM)
You're welcome!
It just so happens that I just finished working on a project that makes heavy use of NotesRichTextTables. Since we are just using the tables to layout a report, all the cells are text based, however I did learn that tables are limited to 255 rows.