PermaLinkCreate and populate a table with LotusScript
posted Sunday 28th, November 2004
 



Here's a sample database to show how to use LotusScript and the NotesRichTextNavigator class to create and populate a table. NotesRichTextNavigator was added to LotusScript in Designer 6, and to Java in Designer 6.5.

It's been a while since I've posted something technical. Moving across the country, building a house, new job, election, user group ...lots going on. Well, I've been using the NotesRichTextNavigator for a little bit, and it seemed that there was not a freely available and understandable tutorial or sample database to show folks how. Admittedly, I only did a quick search, so if you have posted or have found a good resource, please do let me know.

I used the Designer 7 beta to create this database, so if you have any problems, give a holler and I'll recreate using ND6. The general scheme here is that I created a few documents to store some data about some of the drink recipes that my wife and I have derived. The documents include links to where we've posted each recipe (gotta make this stuff fun, eh?). Here's a screen shot of one of the documents:

Then I wrote a LotusScript agent (the real element to examine in the database) that creates a new document, creates a table in the document, and adds a row of data for each selected document. You open then database, select one or more of the recipe documents, and select the agent's action from the Action menu. The selected documents are sorted by drink name, and written to a table. Here's a partial screen shot of the output:

I've added a lot of comments in the agent to explain what's going on. OK, not as many comments as Tom would have added, but I wanted to include at least some code :-)
Now, if you really want to do magic with rich text, check out Midas tools. If you can get what you need from simple formatted tables, then you may be able to get a start from the RTNavSample database. Cheers.
Comments :
 
 

1. Posted by Ben Langhinrichs - website09/09/2007 08:42 PM



I appreciate the plug. I also think it is a good idea to come up with these practical samples, as too many people struggle through trying to do something as obvious as creating a table without much success. Do you mind if I take your sample and expand it a bit with Midas to show the differences? I don't mean to put down the effort you have made, which is laudable, but rather to show where the limits are reached and how to go beyond them if you need to. If you would prefer I did not do it with the same example, that's OK too. I just thought it might help people understand the progression/comparison.




2. Posted by Joe Litton - website09/09/2007 08:42 PM



Ben, PLEASE expand/improve/clarify wherever and however you choose. Do with the posted stuff as you see fit. Thanks for asking.




3. Posted by Christopher Byrne - website09/09/2007 08:42 PM



You might want to think about putting a copy up in the Sandbox. I just posted to the ND6 developerWorks Forum with a link to this post.




4. Posted by Stan Rogers - website09/09/2007 08:42 PM



After spending Frisatursunday (one day with more than twenty-four hours in it) playing with heavy-duty DXL, I can't tell you how glad I was to find out that the lovely drinks recipe form was the result of manual layout twiddling and not something I'd missed in the NotesRichTextTable. Good example database, Joe -- I almost wish you'd done that before I started playing with the new classes in the RNext betas, but someone just reminded me that I'm the sort who prefers to run with scissors. It's definitely going to help people to get where they want to go.




5. Posted by Ben Langhinrichs - website09/09/2007 08:42 PM



Well, the Midas version to do just what you did is a lot shorter, but I still want to try to show some of what you can do beyond that. I did notice a bug I've never noticed before with the NotesRichTextTable class, or rather with the NotesRichTextItem.AppendTable method. Look at the reports generated, and look on the Table properties under the first tab. The Row spacing and Column spacing values are set to 0.014", when they should be set to 0". Try creating a table by hand in Notes and you'll see what I mean.

That looks reasonable in your case, but since you have no way to modify these values with the NotesRichTextParagraphStyle or NotesRichTextTable classes, you cannot create a table with the same dimensions as that which you would create by hand. I'll have to see if that is always the case or whether it is only true if you use the paragraph styles to set the widths.




6. Posted by Joe Litton - website09/09/2007 08:42 PM



Chris: Gosh, I'd never even thought about the Sandbox. I think I'll see about tossing this up there and also in the bin on OpenNTF.

Stan: DXL is an area I've only lightly explored. I've played with it enough to see that there's a lot of potential, but I need to dig in a lot more. So I can guarantee that ANY form I develop for at least another month or 3 will be done the old-fashioned way.

Ben: I'd noticed that I could not tweak the table to be the same as what I'd create by hand. I'll typically create a sample table by hand first, then write the code to emulate that formatting. I'd wanted to have slightly different row/column spacing, but that capability was not exposed. Oh well.




7. Posted by Stan Rogers - website09/09/2007 08:42 PM



Joe, what I've taken to doing is creating a two-row table by hand (a formatted header row and a single blank data row), adding that to a document using AppendRTItem, then grab that table in the RTNav and use AddRow to generate the rest of the table. Any existing formatting in the hand-rolled table will be carried through to the added rows. It's the only way you can set things like border styles and so forth without Midas, the C API or DXL.




8. Posted by Stan Rogers - website09/09/2007 08:42 PM



I should have added that the "seed table" idea was Ben's. Maybe I thought it was just so glaringly obvious I didn't need to say it




9. Posted by Julie Peck09/09/2007 08:42 PM



Thanks Joe. Your example has just come in very handy as I needed to do something very similar today.

Using your example I managed to get my script written in 20 mins ... a lot quicker than if I'd had to start by trawling my way through the help.

Thanks very much!

Julie




10. Posted by Joe Litton - website09/09/2007 08:42 PM



Julie, You just made my day :) Thanks for taking the time to comment!




11. Posted by Jule Peck09/09/2007 08:42 PM



I had plenty of time on my hands to comment because you probably saved me hours of work

Anyway, its only polite to thank someone who has helped you out (even if they didn't know they'd helped you out).

Julie




12. Posted by Volker Weber - website09/09/2007 08:42 PM



When I see what kind of application you are building there, I am getting second thoughts on drinking with you. And, yes, it seems like a good idea, not to move any cars later in the evening.




13. Posted by Les Zatony09/09/2007 08:42 PM



I've used the seed table idea for other things like adding a link without the ugly box around it. Create the link in a doc and then once you've got a handle to it you can change the text and link info and put it in a table or anywhere else in an rt field.




14. Posted by Kiran09/09/2007 08:42 PM



Ur code is really great.Its very usefull for us.i need to get particular column\row value and export it to other formats(excel....). Can i export this richtext table to other files.Please do the needfull.Thanks in advance.
Kiran.