Solved

how to create nested tables and nested section at run time in lotus notes using c++ api.

Posted on 2009-05-20
1
348 Views
Last Modified: 2013-11-16
hi,

i have to create nested sections and within these nested sections i have to create tables and nested tables and the nested tables can have any kind of data i.e
rich text, hyper link, paragraph, further table.

as the information is not fixed how many table and what kind of data will be in each cell i have to generate all this at run time.

how can i do this using lotus notes c plus plus api.

i am able to create each and every thing individually like (section,table,hyper link,attachment etc.)

but at run time i am not able to backtrack the cursor position when the structure are nested.


0
Comment
Question by:davinder101
1 Comment
 
LVL 22

Accepted Solution

by:
mbonaci earned 500 total points
ID: 24431383
This is RTTable (RTTABLE.CPP file) example of notescpp Samples.
It creates table in RT item.
It demonstrates how to navigate the newly created table using RTCursor and also how to initialize LNTableCell using simple TableRef( rowNum, colNum ) syntax.
void AppendRTTable( LNDocument *NewDoc, LNINT Rows, LNINT Cols )

{

	LNSTATUS		lnstatus;

	LNRichText		RT;

	LNRTCursor		Cursor1, Cursor2, SectionBeginCursor, SectionEndCursor;

	LNRTCursor		TableCursor;

	LNTable			Table1, Table2;

	LNTableCell		ThisCell1, ThisCell2;

	LNString		CellText;

	char			Buffer[80];

	LNINT			Row, Col;

	LNString		SectionTitle, ButtonTitle;

	LNFormula		Formula("@Prompt([Ok];\"Greeting\";\"Hi, how are you?!\")");

	LNButton		Button1, Button2;

	

	// Get the rich text "Body" field from the document.  

	// We will append the table to it later.
 

	NewDoc->GetItem("Body", &RT);
 

	// Create a section that contains this table.

	// So we need to get a cursor before the table.
 

	RT.GetCursor(&SectionBeginCursor);
 

	// Append a string to the end of the field where the table will follow.
 

	RT << "\nThe New TABLE Goes Between Here:\n\n";

	RT << "\n\nAnd Here:\n";
 

	// Get a cursor at the end of this RT object and move it back to the

	// point between the two strings above.
 

	RT.GetEndCursor(&Cursor1);

	Cursor1-=12;
 

	// Create a new table just after the end cursor position.

	// This is more efficient than constructing a table on the stack and

	// then inserting it into the rich text because we can avoid an extra copy.
 

	RT.CreateTable(Rows, Cols, &Cursor1, &Table1);
 

	// Get an end cursor again and create a string section between the two

	// cursor positions.
 

	RT.GetEndCursor(&SectionEndCursor);

	SectionTitle = "Here is the table:";

	RT.CreateStringSection(SectionTitle, &SectionBeginCursor, &SectionEndCursor);
 

	// Get a cursor for the table positioned at the first cell: [R0:C0].
 

	Table1.GetCursor(&TableCursor);
 

	// Iterate through each row.
 

	for (Row=0; Row<(int)Rows; Row++)

	{

		// Iterate through each column.
 

		for (Col=0; Col<(int)Cols; Col++)

		{			

			// Add text in each cell that identifies its

			// row/column position. (i.e., "Cell: [R3:C5]")
 

			sprintf(Buffer, "Cell: [R%d:C%d]", Row, Col );
 

			// Insert the text in the current cell
 

			Table1.Insert( Buffer, &TableCursor );
 

			// Get the cell object for the current cursor position.

			// We can determine if the cursor is in a table cell,

			// and get a smart pointer to the table cell.
 

			lnstatus = TableCursor.GetParentContainer( LNRTTYPE_TABLE_CELL, &ThisCell1 );
 

			// Since we know the cursor is inside a table, it must be inside a 

			// table cell.
 

			if (lnstatus == LNWARN_NOT_FOUND) 

				throw ("Object is not in table cell");
 

			// Confirm that the table cell's row and columns match what we think

			// the cursor's position is.
 

			if ((ThisCell1.GetRowIndex() != Row) ||

				(ThisCell1.GetColumnIndex() != Col))

				throw ("The cursor is not in the correct table cell");
 

			// Find out which row and column we are on and, if on

			// an outside cell, remove the outer borders to make 

			// a tic-tac-toe-like structure.
 

			if (Row==0) // first row.

			{

				if (Col==0) // Left top corner.

				{

					// Remove left border.

					ThisCell1.SetLeftBorderWidth( LNTABLEBORDERTYPE_NONE );
 

					// Remove top border.

					ThisCell1.SetTopBorderWidth( LNTABLEBORDERTYPE_NONE );

				}

								

				else if (Col==(Cols-1)) // Right top corner.

				{

					// Remove top border.
 

					ThisCell1.SetTopBorderWidth( LNTABLEBORDERTYPE_NONE );
 

					// Remove right border.
 

					ThisCell1.SetRightBorderWidth( LNTABLEBORDERTYPE_NONE );

				}

				else // Somewhere in middle of top row.

				{

					// Remove top border only.
 

					ThisCell1.SetTopBorderWidth( LNTABLEBORDERTYPE_NONE );

				}

			}

						

			else if (Row==(Rows-1)) // Last row.

			{

				if ( Col==0) // Left bottom corner.

				{

					// Remove left border.
 

					ThisCell1.SetLeftBorderWidth( LNTABLEBORDERTYPE_NONE );

					

					// Remove bottom border.
 

					ThisCell1.SetBottomBorderWidth( LNTABLEBORDERTYPE_NONE );

				}

				else if (Col==(Cols-1)) // Right bottom corner border.

				{

					// Remove right border.
 

					ThisCell1.SetRightBorderWidth( LNTABLEBORDERTYPE_NONE );
 

					// Remove bottom border.
 

					ThisCell1.SetBottomBorderWidth( LNTABLEBORDERTYPE_NONE );

				}

				else // Somewhere in middle of bottom row.

				{

					// Remove bottom border only.
 

					ThisCell1.SetBottomBorderWidth( LNTABLEBORDERTYPE_NONE );

				}

			}

			else // Any row in between.

			{

				if (Col==0) // Somewhere in middle of first left column.

				{

					// Remove left border only.
 

					ThisCell1.SetLeftBorderWidth( LNTABLEBORDERTYPE_NONE );

				}

				if (Col==(Cols-1)) // Somewhere in middle of last right column.

				{

					// Remove right border only.
 

					ThisCell1.SetRightBorderWidth( LNTABLEBORDERTYPE_NONE );

				}
 

			} // END if(Row)
 

			TableCursor++; // Curser increments through table like reading a book.
 

		} // END (iterate Columns loop) 
 

	} // END (iterate Rows loop)
 

	// Now let's create another table and demonstrate a few other methods of

	// LNTable class.
 

	RT.Append("\n\nAnother table goes here:\n");

	RT.GetEndCursor(&Cursor1);

	Rows = 1;

	Cols = 2;

	RT.CreateTable(Rows, Cols, &Cursor1, &Table2);
 

	// Now let's append another row to this table.
 

	Table2.AppendRows(1);
 

	// Change the border style.

	// For some reason, this erases the "inside" borders of the table.

	// Filed an SPR about it.

	// Table2.SetBorderStyle(LNTABLEBORDERSTYLE_EMBOSSED);
 

	// Change the background color of the table
 

	Table2.SetBackgroundColor(LNCOLOR_CYAN);

	

	// Now we'll show how to insert and delete rich text items for a table cell

	// Let's create two buttons and delete one of them:

	// First choose the cells where to place the buttons
 

	ThisCell1 = Table2(1,1);

	ThisCell2 = Table2(0, 0);
 

	// Append a comment
 

	ThisCell1.Append("The button goes here: ");

	ThisCell2.Append("The button goes here: ");
 

	// Get the end cursors to place the buttons 
 

	ThisCell1.GetEndCursor(&Cursor1);

	ThisCell2.GetEndCursor(&Cursor2);
 

	// Create the buttons
 

	ButtonTitle = "Click Me!";

	ThisCell1.CreateButton(ButtonTitle, Formula,  &Cursor1, &Button1);

	ThisCell2.CreateButton(ButtonTitle, Formula,  &Cursor2, &Button2);

	

	// Now let's delete one of the buttons and replace the comment in that cell
 

	ThisCell2.Delete(&Button2);

	ThisCell2.SetValue("The button used to be here");
 

	// Save the note to disk.

	NewDoc->Save();
 

} // END AppendRTTable()

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Add code to Lotus Notes view column 2 117
Lotus Domino Server 9 4 82
How to auto purge mail to keep latest one month mail of a replica? 4 95
@Mailsend 3 41
This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now