Profile Picture

How to identify a table in RTF document

Posted By Tom Galczynski 5 Years Ago
Author
Message
Tom Galczynski
Posted 5 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)

Group: Forum Members
Last Active: 4 Years Ago
Posts: 29, Visits: 87
Got it!  Thanks for your help. I have it working where I can insert a table at the caret or replace a selected table with another.  :-)

Nevron Support
Posted 5 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009
Hi Tom,
Please take a look at the following topic in the documentation:
http://helpopenvision.nevron.com/#WorkingWithTextDocuments_Selection.html

You can get the currently selected inline and dig your way up the tree using the following code:
   nRichTextViewWithRibbonControl1.Widget.View.SaveToFile("c:\\temp\\test.pdf", new Nevron.Nov.Text.Formats.NPdfTextFormat());

    NSelection selection = nRichTextViewWithRibbonControl1.Widget.View.Selection;
    if (selection.Mode == ENSelectionMode.Caret)
    {
      NTable table = (NTable)selection.GetSelectedInlines(false)[0].GetFirstAncestor(NTable.NTableSchema);

      table.BackgroundFill = new NColorFill(NColor.Red);
    }

The idea is to get the current inline where the cursor is located and then try to get the first table that contains it. The code specifically checks whether the selection mode is caret so that it avoids the Range selection mode in which you can have two or more tables selected simultaneously.
Hope this helps - let us know if you have any questions.

Best Regards,
Nevron Support Team



Tom Galczynski
Posted 5 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)

Group: Forum Members
Last Active: 4 Years Ago
Posts: 29, Visits: 87
Thanks. If the user places the cursor at a particular location in the document, or selects a table or text, can I know where that is and be able to replace the selected text/table with a new one? Or be able to insert a table/text at the cursor location in the document?

Thank you!


Nevron Support
Posted 5 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009
Hi Tom,
After you load the document the whole DOM is open for modification - so you can clear the contents of a table and replace it with your own - or replace the table itself - the following code for example gets the first table and replaces it with another table (which is a clone of the first one but with different color):
   var listOfTables = nRichTextViewWithRibbonControl1.Widget.View.Content.GetDescendants(Nevron.Nov.Text.NTable.NTableSchema);

    if (listOfTables.Count > 0)
    {
      NTable table = (NTable)listOfTables[0];
      NTable tableClone = (NTable )table.DeepClone();
      tableClone.BackgroundFill = new NColorFill(NColor.Red);

      NBlock parent = table.ParentBlock;

      NNode childBlocks = parent.GetChild(parent.GetChildBlocksChild());

      int indexInParent = childBlocks.IndexOfChild(table);
      childBlocks.RemoveChild(table);

      childBlocks.InsertChild(indexInParent, tableClone);
    }
Inserting a section break at a specific location is achieved with:
nRichTextViewWithRibbonControl1.Widget.View.Selection.InsertSectionBreak(ENSectionBreakType.Continuous);

Hope this helps - let us know if you meet any problems...

Best Regards,
Nevron Support Team



Tom Galczynski
Posted 5 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)

Group: Forum Members
Last Active: 4 Years Ago
Posts: 29, Visits: 87
Thank you. I did take a look at the docs shipped with NOV and they were a help to create the tables. What I am trying to accomplish is to create a document with sections, tables, paragraphs, save it to RTF.  Then after loading it back from RTF into the rich text view control, have a toolbar button such that when pressed it will replace a specific table (or section) with a new table (section). Is there a way to do that?  For example, once the rtf string is loaded into the control, are all the NOV objects available?  Can I use your table list example and take a table object, clear it out and replace it with different rows/cols? Or if not, can I take a section and replace it?  Also, is there a way to add a section to the position the user has placed the cursor in the view control?

I realize these are fairly open ended questions.  Still trying to get a handle on the structure of the content.  Thanks!


Nevron Support
Posted 5 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009
Hi Tom,
You can take a look at the examples shipped with NOV - they show how to work with tables in general. There is a Tag property attached to each object in NOV, which you can use to add some identification, however it is not serialized (not written to / from RTF or other serialization formats). Alternatively you can identify tables by their position in the document using the table range:
tableWithoutCellSpacing.Range
this gives you the span of characters covered by a table.This can be used to check how tables are ordered in the document. So a way of table naming that is persistent will be to assign a tag to each table after you read it from RTF, prior to writing to create a map from position to table name and write that one along with the document. Then when you read you can assign tables their tags by going back from the position to table name. 
Hope this helps - let us know if you have any questions or meet any problems.

Best Regards,
Nevron Support Team



Tom Galczynski
Posted 5 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)

Group: Forum Members
Last Active: 4 Years Ago
Posts: 29, Visits: 87
Thank you, that's a help.  However, how can I identify a specific table?  Can I "name" or "tag" the table object somehow so as I traverse the list of tables I can work with the table I want?

Also, please let me know if there is any documentation on working with tables, dot net examples preferred.  I had trouble getting to the Live Demos link and could not find any documentation other than brief example in the programmers reference.

Thanks!


Nevron Support
Posted 5 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009
Hi Tom,

You can easily get all tables in a document using the GetDescandants method with schema filter. The following code for example applies red background to all tables in a document:

   var listOfTables = nRichTextViewWithRibbonControl1.Widget.View.Content.GetDescendants(Nevron.Nov.Text.NTable.NTableSchema);

    for (int i = 0; i < listOfTables.Count; i++)
    {
      NTable table = (NTable)listOfTables[i];

      table.BackgroundFill = new NColorFill(NColor.Red);
    }


Best Regards,
Nevron Support Team



Tom Galczynski
Posted 5 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)

Group: Forum Members
Last Active: 4 Years Ago
Posts: 29, Visits: 87
Hello.  I am creating multiple ntables in a document, saving the document to an RTF string into a sql table. My question is, how can I identify/locate a specific table in the doc so I can remove it and create another table in its place? I would like to give my users the option of re-creating specific tables in the doc but i'm not sure how I could find the table once it's been loaded into the NRichTextView.

Thanks!




Similar Topics


Reading This Topic