Splitting Cell in to two columns

Hi i am using Aspose PDF can some body please tell me how to split the cell in two columns ,

how to adjust cell width

itried fitwidth i am facing problem with that iam unable to do that

Hello Subbarao,

Thanks for using our products.

Please visit the following link for required information on Set Width and Span of the Column.

In case it does not resolve your problem or you have any further query, please feel free to contact. We apologize for your inconvenience.

Hi Thanks for the replay

i have gone through this

But the problem is even after i use this its not reflecting in the PDF .

and the other question i have is

How to split a cell into two columns ?

Hello Subbarao,

From splitting the cell into two columns, do you mean you need the cell to occupy two columns ? If so is the case then please try using cell1.ColumnsSpan = 2;

In case it does not resolve your problem or I have not properly understood your requirement, please share the code snippet so that we can test the scenario at our end. We apologize for your inconvenience.

I need to divide a cell in to two columns columspan is for combining

How to specify cell height ?

Pdf pdf1 = new Pdf();
Section sec1 = pdf1.Sections.Add();
sec1.PageInfo.PageWidth = PageSize.LegalWidth;
sec1.PageInfo.PageHeight = PageSize.LegalHeight;
Aspose.Pdf.Table table1 = new Aspose.Pdf.Table();
sec1.Paragraphs.Add(table1);
Row row1 = table1.Rows.Add();
Cell cell1Row1 = row1.Cells.Add("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
cell1Row1.ColumnsSpan = 15;
cell1Row1.Border = new BorderInfo((int)BorderSide.All, 0.5F);

//TO create Row2
Row row2 = table1.Rows.Add();

Cell cell1Row2 = row2.Cells.Add("BBBBBBBBBBB BBBBBBBBBBBBB BBBBBBBBBBBBBBB");
cell1Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);


Cell cell2Row2 = row2.Cells.Add("CCCCCCCCCCCCCCC CCCCCCCCCCC CCCCCCCCCC");
cell2Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);


Cell cell3Row2 = row2.Cells.Add("dddddddddddddddddddddd DDDDDDDD ddddddddd");
cell3Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);

Cell cell4Row2 = row2.Cells.Add("EEEEEEEEEEEEEE EEEEEEEEE EEEEEEE");
cell4Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);


Cell cell5Row2 = row2.Cells.Add("FFFFFFFFFFFFFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFFFFFFF");
cell5Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);


Cell cell6Row2 = row2.Cells.Add("GGGGGGGGGGGGGGGGGGGGGGGGG");
cell6Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);


Cell cell7Row2 = row2.Cells.Add("HHHHHHHH HHHHHHHHHHHHHHHHH HHHHHHHHHH");
cell7Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);


Cell cell8Row2 = row2.Cells.Add("IIIIIIIIIIIIIIIIII IIIIIIIIIIIIIIIII IIIIIIIIIIIIII");
cell8Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);


Cell cell9Row2 = row2.Cells.Add("JJJJJJJJJ JJJJJJJJJJJJJJ JJJJJJJJJJJJ");
cell9Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);


Cell cell10Row2 = row2.Cells.Add("KKKKKKK KKKKKKKKK KKKKKKKK");
cell10Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);

Cell cell11Row2 = row2.Cells.Add("LLLLLLLLLL LLLLLLL LLLLLLLLLL");
cell11Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);


Cell cell12Row2 = row2.Cells.Add("mmmmmmmmmmmmmmmMMMMMMMM");
cell12Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);


Cell cell13Row2 = row2.Cells.Add("");
cell13Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);


Cell cell14Row2 = row2.Cells.Add("");
cell14Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);

Cell cell15Row2 = row2.Cells.Add("");
cell15Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);


//TO create Row3
Row row3 = table1.Rows.Add();
Cell cell4Row3 = row3.Cells.Add("male");
cell4Row3.Border = new BorderInfo((int)BorderSide.All, 0.5F);
Cell cell5Row3 = row3.Cells.Add("male");
cell5Row3.Border = new BorderInfo((int)BorderSide.All, 0.5F);
Row row4 = table1.Rows.Add();
foreach (DataRow row in dt.Rows)
{
Row row5 = table1.Rows.Add();
foreach (DataColumn col in dt.Columns)
{
Cell cell2Row5 = row5.Cells.Add(row[col].ToString());
cell2Row5.Border = new BorderInfo((int)BorderSide.All, 0.5F,new Color("Red"));
}
}
pdf1.Save("c://temp//2010Report.pdf");


First row is header it should be head , in the second row i have 15 columns
The problem is i want to specify each and every column with different width ,i used fitwidth but it is going out of PDF
when it comes to third row i want to split each and every cell in to two columns

Hello Subbarao,

I am afraid you cannot set the height for a particular table cell. In fact all the cells in a particular row should be of same height. So in order to accomplish your requirement, please try using FixedRowHeight property of Row Class.

You can set the width of columns in table by using ColumnWidths property or by using SetColumnWidth method of Table class. I am afraid Cell.FitWidht property is obsolete.

Regarding your requirement on splitting the each cell of 3rd row in to two columns, you need to use Nested tables approach i.e. Place table inside table cell. In order to accomplish this requirement, please add the following code snippet after you have created the third row.

[C#]

//TO create Row3
Row row3 = table1.Rows.Add();
// create first cell in table row
Cell Row3Cell1 = row3.Cells.Add();

// create an object for inner/nested table
Table innertable = new Table(Row3Cell1);
// add the nested table to paragraphs collection of first cell of 3rd row
Row3Cell1.Paragraphs.Add(innertable);
// set the width information for table columns
innertable.ColumnWidths ="50 50";
// set the default table border information for inner table
innertable.DefaultCellBorder = new BorderInfo((int)BorderSide.All,0.3F,new Aspose.Pdf.Color("Green"));
//Set table border for inner table using another customized BorderInfo object
innertable.Border = new BorderInfo((int)BorderSide.All,0.3F,new Aspose.Pdf.Color("Greed"));

// create a row object and add it to rows collection of inner table
Row InnerTableRow1 = innertable.Rows.Add();
// create first cell to be added to cells collection of first row of inner table
Cell InnerTableRow1Cell1 = InnerTableRow1.Cells.Add("male 1");
Cell InnerTableRow1Cell2 = InnerTableRow1.Cells.Add("male 2");

FYI, in case the table width is larger than page width and it cannot be accommodated over single page, then please set the value of IsVerticalBroken property of Table class to true. It indicates that the table is broken vertically as the table is printed out of the right page margin.

I would also recommend you to visit the following link for more related information on how to Create Nested Table

You may also try using IsLandscape property of Section class to set the page orientation as Landscape. In case it does not resolve your problem or you have any further query, please feel free to contact. We apologize for your inconvenience.

Thank you very much for the replay

I have one more problem please suggest me what to do in this case

the code is

Pdf pdf1 = new Pdf();

Section sec1 = pdf1.Sections.Add();

sec1.PageInfo.PageWidth = PageSize.LegalWidth;

sec1.PageInfo.PageWidth = PageSize.LegalHeight;

Table table1 = new Table();

Row row1 = new Row(table1);

Cell cell1Row1 = row1.Cells.Add("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");

cell1Row1.ColumnsSpan = 15;

cell1Row1.Border = new BorderInfo((int)BorderSide.All, 0.5f);

cell1Row1.Alignment = AlignmentType.Center;

Row row2 = new Row(table1);

row2.VerticalAlignment = VerticalAlignmentType.Center;

Cell cell1Row2 = row2.Cells.Add("BBBBBBBBBBBBBBBBBBBb");

cell1Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell1Row2.FitWidth = 35;

Cell cell2Row2 = row2.Cells.Add("CCCCCCCCCC");

cell2Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell2Row2.FitWidth = 35;

Cell cell3Row2 = row2.Cells.Add("DDD");

cell3Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell3Row2.FitWidth = 25;

Cell cell4Row2 = row2.Cells.Add("EEEEEEEEEEEEEEEEEEEEEEEEEEEE");

cell4Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell4Row2.FitWidth = 60;

//cell4Row2.ColumnsSpan = 2;

Cell cell5Row2 = row2.Cells.Add("FFFFFFFFFFFFFFFFFFFFFFFFFF");

cell5Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell5Row2.FitWidth = 60;

//cell5Row2.ColumnsSpan = 2;

Cell cell6Row2 = row2.Cells.Add("GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG");

cell6Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell6Row2.FitWidth = 70;

//cell6Row2.ColumnsSpan = 2;

Cell cell7Row2 = row2.Cells.Add("HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH");

cell7Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell7Row2.FitWidth = 70;

//cell7Row2.ColumnsSpan = 2;

Cell cell8Row2 = row2.Cells.Add("IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII");

cell8Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell8Row2.FitWidth = 60;

Cell cell9Row2 = row2.Cells.Add("JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ");

cell9Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell9Row2.FitWidth = 60;

Cell cell10Row2 = row2.Cells.Add("KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK");

cell10Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell10Row2.FitWidth = 70;

Cell cell11Row2 = row2.Cells.Add("LllllllllllllllllllllllllllllllllllllLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL");

cell11Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell11Row2.FitWidth = 60;

Cell cell12Row2 = row2.Cells.Add("MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM");

cell12Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell12Row2.FitWidth = 60;

Cell cell13Row2 = row2.Cells.Add("NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN");

cell13Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell13Row2.FitWidth = 60;

Cell cell14Row2 = row2.Cells.Add("OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO");

cell14Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell14Row2.FitWidth = 70;

Cell cell15Row2 = row2.Cells.Add("PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP");

cell15Row2.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell15Row2.FitWidth = 70;

Row row3 = new Row(table1);

Cell cell1Row3 = row3.Cells.Add("");

cell1Row3.FitWidth = 35;

Cell cell2Row3 = row3.Cells.Add("");

cell2Row3.FitWidth = 35;

Cell cell3Row3 = row3.Cells.Add("");

cell3Row3.FitWidth = 25;

Cell cell4Row3 = row3.Cells.Add("Male");

cell4Row3.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell4Row3.FitWidth = 30;

Cell cell5Row3 = row3.Cells.Add("FeMale");

cell5Row3.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell5Row3.FitWidth = 30;

Cell cell6Row3 = row3.Cells.Add("Male");

cell6Row3.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell6Row3.FitWidth = 30;

Cell cell7Row3 = row3.Cells.Add("FeMale");

cell7Row3.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell7Row3.FitWidth = 30;

Cell cell8Row3 = row3.Cells.Add("Male");

cell8Row3.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell8Row3.FitWidth = 30;

Cell cell9Row3 = row3.Cells.Add("FeMale");

cell9Row3.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell9Row3.FitWidth = 30;

Cell cell10Row3 = row3.Cells.Add("Male");

cell10Row3.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell10Row3.FitWidth = 30;

Cell cell11Row3 = row3.Cells.Add("FeMale");

cell11Row3.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell11Row3.FitWidth = 30;

Cell cell12Row3 = row3.Cells.Add("FeMale");

cell12Row3.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell12Row3.FitWidth = 60;

Cell cell13Row3 = row3.Cells.Add("FeMale");

cell13Row3.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell13Row3.FitWidth = 60;

Cell cell14Row3 = row3.Cells.Add("FeMale");

cell14Row3.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell14Row3.FitWidth = 60;

Cell cell15Row3 = row3.Cells.Add("FeMale");

cell15Row3.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell15Row3.FitWidth = 60;

Cell cell16Row3 = row3.Cells.Add("FeMale");

cell16Row3.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell16Row3.FitWidth = 60;

Cell cell17Row3 = row3.Cells.Add("FeMale");

cell17Row3.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell17Row3.FitWidth = 60;

Cell cell18Row3 = row3.Cells.Add("FeMale");

cell18Row3.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell18Row3.FitWidth = 60;

Cell cell19Row3 = row3.Cells.Add("FeMale");

cell19Row3.Border = new BorderInfo((int)BorderSide.All, 0.5F);

cell19Row3.FitWidth = 60;

When i run this the pdf which is executing it is going out of PDF

specially what iam looking for is

In the third row There are eight fitwidth =30 these should be come under row2 in the particular coumn where the fitwidth =60 so the two of them row3 fiwidth 30 should come under one fitwidth 60

please go through this

Thank you very much

One more quesiton

The default orientation which we have is portait

but i want landscape how can i change it

Thanks in advance

Hello Subbarao,

Thanks for using our products.

Regarding your query on setting the page orientation to Landscape, please set the value of IsLandscape property of Section class to true. You may also specify the page size and margin information for the PDF document. For more related information, please visit Set Page Size and Margins

However for the other issue of setting FitWidth value for table cells, as I have already shared this property is obsolete. So please try specifying the column width information using ColumnWidths property of Table class. For more related information, please visit Set Border Style, Margins and Padding of the Table and Set Width and Span of the Column

In case I have not properly understood your requirement or you have any further query, please feel free to contact. We apologize for your inconvenience.

If i use table width every column in the table takes it as default which i dont want