Hello friend I want to add three table in same paragraph.
Does any one have any idea about that.
Any help will be highly appreciated.
Thanks
Shakti
Hello Shakti,
Thanks for considering Aspose.
Do you mean adding three tables in a same section of a Pdf document ? If so is the case then please try using the following code snippet. I've also attached the resultant PDF document. Please take a look and in case it does not satisfy your requirement, feel free contact.
[C#]
Pdf pdf = new Pdf();
Aspose.Pdf.Section sec1 = pdf.Sections.Add();
for (int i = 0; i <= 2; i++)
{<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
// Add the table title
sec1.Paragraphs.Add(new Text("Table"+ (i+1).ToString()));
//Instantiate a table object
Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table();
//Add the table in paragraphs collection of the desired section
sec1.Paragraphs.Add(tab1);
//Set with column widths of the table
tab1.ColumnWidths = "70 70 70";
//Set default cell border using BorderInfo object
tab1.DefaultCellBorder = new BorderInfo((int)BorderSide.All, 0.5F, new Aspose.Pdf.Color("Red"));
//Set table border using another customized BorderInfo object
tab1.Border = new BorderInfo((int)BorderSide.All, 1F, new Aspose.Pdf.Color("Blue"));
//Create MarginInfo object and set its left, bottom, right and top margins
MarginInfo margin = new MarginInfo();
margin.Top = 5f;
margin.Left = 5f;
margin.Right = 5f;
margin.Bottom = 5f;
//Set the default cell padding to the MarginInfo object
tab1.DefaultCellPadding = margin;
Aspose.Pdf.Row row1 = tab1.Rows.Add();
row1.Cells.Add("Col (" + i.ToString() +"," + "0)");
row1.Cells.Add("Col (" + i.ToString() +"," + "1)");
row1.Cells.Add("Col (" + i.ToString() +"," + "2)");
Aspose.Pdf.Row row2 = tab1.Rows.Add();
row2.Cells.Add("Col (" + (i+1).ToString() + "," + "0)");
row2.Cells.Add("Col (" + (i+1).ToString() +"," + "1)");
row2.Cells.Add("Col (" + (i+1).ToString() +"," + "2)");
// add a blank text paragraph to display separation between tables
sec1.Paragraphs.Add(new Text(""));
}
pdf.Save(@"d:/pdftest/Three_Table_Test.pdf");
Thanks for your help but I want those three table in this way,
Please find the attachment
Thanks
Hi,
You can use Nested Tables (table inside a table) to accomplish your requirement. Please try using the following code snippet. Resultant PDF is also in attachment.
[C#]
Pdf pdf = new Pdf();
Aspose.Pdf.Section sec1 = pdf.Sections.Add();
// set the page orientation as LandScape
sec1.IsLandscape = true;
Aspose.Pdf.Table maintable = new Aspose.Pdf.Table();
//Add the table in paragraphs collection of the desired section
sec1.Paragraphs.Add(maintable);
//Set with column widths of the table
maintable.ColumnWidths = "200 200 200";
// Add the row which will hold the inner table
Aspose.Pdf.Row mainrow1 = maintable.Rows.Add();
for (int i = 0; i <= 2; i++)
{
//Instantiate a table object
Aspose.Pdf.Table innertable = new Aspose.Pdf.Table();
// add innertable to main tabel row
mainrow1.Cells.Add().Paragraphs.Add(innertable);
// Add the table title
innertable.Rows.Add().Cells.Add().Paragraphs.Add(new Text("Table" + (i + 1).ToString()));
// add a row in the innertable to hold the table containing data
Aspose.Pdf.Row mainrow2 = innertable.Rows.Add();
//Instantiate a table object
Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table();
//Add the table in paragraphs collection of the desired section
mainrow2.Cells.Add().Paragraphs.Add(tab1);
//Set with column widths of the table
tab1.ColumnWidths = "60 60 60";
//Set default cell border using BorderInfo object
tab1.DefaultCellBorder = new BorderInfo((int)BorderSide.All, 0.5F, new Aspose.Pdf.Color("Red"));
//Set table border using another customized BorderInfo object
tab1.Border = new BorderInfo((int)BorderSide.All, 1F, new Aspose.Pdf.Color("Blue"));
//Create MarginInfo object and set its left, bottom, right and top margins
MarginInfo margin = new MarginInfo();
margin.Top = 5f;
margin.Left = 5f;
margin.Right = 5f;
margin.Bottom = 5f;
//Set the default cell padding to the MarginInfo object
tab1.DefaultCellPadding = margin;
Aspose.Pdf.Row row1 = tab1.Rows.Add();
row1.Cells.Add("Col (" + i.ToString() + "," + "0)");
row1.Cells.Add("Col (" + i.ToString() + "," + "1)");
row1.Cells.Add("Col (" + i.ToString() + "," + "2)");
Aspose.Pdf.Row row2 = tab1.Rows.Add();
row2.Cells.Add("Col (" + (i + 1).ToString() + "," + "0)");
row2.Cells.Add("Col (" + (i + 1).ToString() + "," + "1)");
row2.Cells.Add("Col (" + (i + 1).ToString() + "," + "2)");
// add a blank text paragraph to display separation between tables
sec1.Paragraphs.Add(new Text(""));
}
pdf.Save(@"d:/pdftest/Three_Table_Test.pdf");
I would also recommend you to visit the following link for information on how to Create Nested tables.
Thanks you are expert in aspose.
hats off for you