Solved

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

Posted on 2009-05-20
1
356 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvinā€¦
IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦

756 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