We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Insert a table created from a XML Template into a table created dynamically from the API?

Hi,

How can I add a table (created from a XML Template*) to a table created in the code?

*//Create a Pdf instance and bind the XML template file to Pdf instance
Pdf pdf1 = new Pdf();
pdf1.BindXML("Template.xml", null);
Table table1 = sec1.Paragraphs["Table1"] as Table;

Table newTable = new Table();
Row row = newTable.Rows.Add();
Cell cell = row.Cells.Add();

Is it possible to add "table1" to "cell"? I know it is possible via the xml template, but I have to built up a page dynamically and I don't want to repeat the xml table code.

Many thanks for your help.

Hi,

For information on creating nested tables please consult http://www.aspose.com/Products/Aspose.Pdf/Api/CreateNestedTable.html .

You should use CreateObjFromXml method to get the table from xml that you want to add to the existing table. For more information please consult http://www.aspose.com/Products/Aspose.Pdf/Api/Aspose.Pdf.Pdf.CreateObjFromXml_overloads.html

Thanks.

Hi again,

Thanks, for your quick answer. Unfortunately the hyperlinks do not provide the right information for my problem. I've created a XML-Template file and it contains a nested table. Now I need to copy the nested table in several cells.

Pdf pdf1 = new Pdf();
pdf1.BindXML("Template.xml", null); //it contains information about a nested table "table1"

Table newTable = new Table(); //create a new Table (copy destination)
Row row = newTable.Rows.Add(); // create a new Row
Cell cell = row.Cells.Add(); //create the destination Cell for the "table1"

The documentation is providing the following example:
Table table1 = sec1.Paragraphs["Table1"] as Table;

My question is how to add the xml-table "table1" to a specific cell, not to Paragraphs? Is it possible, if yes, please send an example? I'm new to Aspose.PDF and maybe I use the wrong syntax.

Many thanks.


Hi,

Look, you wanted to place the table present in the XML into the cell you have made in the code. You have to perform the following steps to get your desired results:

1. Binding XML to Pdf object

2. If you remember table Id in XML and Section, then you can use the below statement otherwise you need to loop through to get to your required table, which you need to Add inside New Table cell.

Table table1 = sec1.Paragraphs["Table1"] as Table;

3. When you get table1, then create new Table using the statement you have written above like :

Table newTable = new Table(); //create a new Table (copy destination)
Row row = newTable.Rows.Add(); // create a new Row
Cell cell = row.Cells.Add(); //create the destination Cell for the "table1"

4. Now you have to add table1 to cell. Use the following statement to add it into the cell.

//Add the nested table into the paragraphs collection of the cell

cell.Paragraphs.Add(table1)

Just to add to your knowledge, that Table is also a paragraph in Aspose.Pdf DOM. You can have more knowledge on Aspose.Pdf DOM. Please refer to :

http://www.aspose.com/Products/Aspose.Pdf/Api/IntroductiontoDOM.html

Hope it works! Should you have any queries, please feel free to ask.

Thanks.