1

After creating table2 and inserting it after table1, how would u give table2 properties of another table that exists in the document? Properties I am speaking of include Keep with next, Keep lines together, Allow rows to break across pages, etc..

Novacode.Table table1 = template.Tables[index];
Novacode.Table table2 = table1.InsertTableAfterSelf(1, 2);
//table2.properties = table1.properties
Phillip
  • 255
  • 1
  • 12

1 Answers1

0

I'm still a novice myself at Novacode-DocX, but I believe you can do an assignment like this

 table2.Design = table1.Design;

This code is able to compile, but I have not tested it's results thoroughly.

You can do a lot of assignments like that, it's not the best, but it depends on what your needs are. A great place for DocX questions is the discussion board. You can find a number of posts with custom code modifications to the .dll file that might suit future needs.

A useful tool to have when using the DocX code library, is the help documentation text. Unfortunately, it hasn't been updated in some time, but you can still download an older version which has many of the functions defined from here

Hopefully this gets you going

Have an awesome day, and be well!

  • I have been messing around with `Design` and I can't seem to figure out what it takes from the existing table. It does not seem to take any of the existing properties. If I do `table1.Design.ToString()` it always seems to be TableGrid no matter if I change properties. I have look at the website before, but not the discussion that much. I might have to check it out. – Phillip Aug 12 '15 at 13:29
  • I actually got around this issue, by having `doc1` with all the tables and properties on those tables that I need. Then I grab the table i need from `doc1`and insert it into `doc2` where it belongs. This only works if you are not adding rows to these tables after inserting, because the newly added rows do not take the rest of the tables' properties. – Phillip Aug 12 '15 at 13:34
  • @Phillip What specific property are you looking for? Font colour? If the template table has a consistent colour you could foreach loop through the paragraphs in table2 and change the text colour to table1's colour. `foreach (Paragraph p in Table2) { p.Color = Table1.Paragraphs[0].Color; } ` – Celebrating Octopus Emoji Aug 12 '15 at 13:40
  • @Phillip I'm happy that you got around the issue by copying the table, but why wouldn't you mention that you wanted identical tables with identical content? Properties are things like colour and font size, by asking for properties it was implied that you had different content. I think [this](http://stackoverflow.com/q/24534638/4990978) question might help – Celebrating Octopus Emoji Aug 12 '15 at 13:52
  • 1
    I didn't want to have identical tables because I have a lot of different types of tables. Also, the properties I was looking for were things like: Keep with next, Keep lines together, Allow rows to break across pages, etc.. More of the complex properties, not just color or border. – Phillip Aug 12 '15 at 14:16