Solved

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

Posted on 2009-05-20
1
344 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
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Problem "Can you help me recover my changes?  I double-clicked the attachment, made changes, and then hit Save before closing it.  But when I try to re-open it, my changes are missing!"    Solution This solution opens the Outlook Secure Temp Fold…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 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

10 Experts available now in Live!

Get 1:1 Help Now