This is a migrated thread and some comments may be shown as answers.

Inserting Table inside Table Cell.

6 Answers 1054 Views
PdfProcessing
This is a migrated thread and some comments may be shown as answers.
jaipal
Top achievements
Rank 1
jaipal asked on 17 Jul 2018, 02:36 PM

 Hi All,

For the PDF Processing , I have to attache a  single table row and  there will be two cells.(some thing which is simillar to the attachment).

1.First  cell  constitutes of Question.

2.Second Sells constitues of a table.

 

It his scenario possible?

 

Regards,

JP

 

6 Answers, 1 is accepted

Sort by
0
jaipal
Top achievements
Rank 1
answered on 19 Jul 2018, 07:41 PM

I was looking somthing simillar thos attached implementation.

 

Regards, 

JP

0
Georgi
Telerik team
answered on 20 Jul 2018, 01:18 PM
Hello Jaipal,

To create a TableCell instance in PdfProcessing which occupies a specified number of rows you can set the RowSpan property. For example:
TableCell cell = row.Cells.AddTableCell();
cell.RowSpan = 2; // number of rows to occupy
Block cellBlock = cell.Blocks.AddBlock();
cellBlock.VerticalAlignment = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.VerticalAlignment.Center;
cellBlock.HorizontalAlignment = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment.Center;
cellBlock.InsertText("Cell Value");

You can set default styling to all cells in a table using the Table's DefaultCellProperties property. In order to set alternating background color for Table rows, you should manually apply the Background color for the cells in each alternating row:
Table table = new Table();
 
Border border = new Border();
table.Borders = new TableBorders(border);
table.DefaultCellProperties.Borders = new TableCellBorders(border, border, border, border);
table.DefaultCellProperties.Background = mainColor;
 
TableRow firstRow = table.Rows.AddTableRow();
TableCell cell = firstRow.Cells.AddTableCell();
Block block = cell.Blocks.AddBlock();
block.InsertText(new FontFamily("Arial"), FontStyles.Normal, FontWeights.Bold, "First Heading Cell");
 
cell = firstRow.Cells.AddTableCell();
block = cell.Blocks.AddBlock();
block.InsertText(new FontFamily("Arial"), FontStyles.Normal, FontWeights.Bold, "Second Heading Cell");
 
TableRow secondRow = table.Rows.AddTableRow();
cell = secondRow.Cells.AddTableCell();
cell.Background = alternateColor;
block = cell.Blocks.AddBlock();
block.InsertText("First Value Cell");
 
cell = secondRow.Cells.AddTableCell();
cell.Background = alternateColor;
block = cell.Blocks.AddBlock();
block.InsertText("Second Value Cell");


When a table is generated, it could be inserted in the PDF document using the RadFixedDocumentEditor's InsertTable() method as can be seen in the Drawing Table with RadFixedDocumentEditor section of the documentation.

I hope this helps.

Regards,
Georgi
Progress Telerik

0
jaipal
Top achievements
Rank 1
answered on 23 Jul 2018, 04:29 PM

Georgi,

Thank you for the inputs , we were able to solve much complicated scenarios invoiving tables , Cells and Blocks but this is where we are struck right now.I am looking for a more specific solution simillar to what is ther in the attachement. 

I can give both column spans and Row Spans but what i am looking at is first coloumn needs to have certain content and rest of the coloumns would be having rows.Is this possible ?

Regards,

JP

0
Georgi
Telerik team
answered on 26 Jul 2018, 12:51 PM
Hello JP,

To accomplish the desired result, you can set the TableCell.RowSpan property of the first cell to the number of the table rows. This way you can set your own content which will occupy through the rows of the entire table:
TableCell leftSpannedCell = firstRow.Cells.AddTableCell();
leftSpannedCell.RowSpan = table.Rows.Count;
leftSpannedCell.InsertText("Representatives from each country");

After this, you can add the preceding text cell by adding cell on the first row and setting the TableCell.ColumnSpan property to the number of remaining columns:
TableCell topSpannedCell = firstRow.Cells.AddTableCell();
topSpannedCell.ColumnSpan = 3; // the number of columns to occupy
topSpannedCell.InsertText("This a text before Table");

Please, note that setting the table rows height is currently not implemented in PdfProcessing. We have logged feature request in our feedback portal: PdfProcessing: Implement option for setting height to table rows, where you can subscribe to be notified for any status updates and vote to increase the priority. Alternatively, you can apply a certain row height by setting the TableCell.Padding property:
topSpannedCell.Padding = new Thickness(0, 10, 0, 10);

Please, find the attached solution, which creates a sample table similar to the attachment you have provided.

I hope this helps.

Regards,
Georgi
Progress Telerik

0
Kong
Top achievements
Rank 1
answered on 21 Dec 2020, 08:57 PM
How do you style a single cell? For instance, I need to add bottom border to a single cell in a table.
0
Martin
Telerik team
answered on 22 Dec 2020, 09:05 AM

Hello Kong,

I already answer your question in the support ticket you have opened and will place the answer here as well.

You can create a table containing a single cell with a bottom border set in the following manner: 

Table table = new Table();
TableRow firstRow = table.Rows.AddTableRow();
TableCell firstCell = firstRow.Cells.AddTableCell();
firstCell.PreferredWidth = 50;
Block firstCellBlock = firstCell.Blocks.AddBlock();
firstCellBlock.GraphicProperties.FillColor = RgbColors.White;
firstCellBlock.InsertText(".");
Border border = new Border(1, RgbColors.Black);
firstCell.Borders = new TableCellBorders(null, null, null, bottom: border);

I have to mention, currently, there is a limitation in the Table object (the setting of a table row height is not supported) so if you create a table row with an empty table cell the bottom border would be drawn in place of the top border because the table height won't be set (the table cell starting point is the top left corner). The border would be correctly drawn if the table cell has content (in the provided code snippet we are setting the color of this content to white in order to not be visible). We have an item logged in our backlog to implement an option for setting the height to table rows: PdfProcessing: Implement an option for setting the height to table rows. You can cast your vote for the implementation as well as subscribe to the task by clicking the Follow button so you can receive updates when its status changes.

Ones you created the table you can insert it in the document using both RadFixedDocumentEditor`s InsertTable() method and FixedContentEditor`s DrawTable() method.

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
PdfProcessing
Asked by
jaipal
Top achievements
Rank 1
Answers by
jaipal
Top achievements
Rank 1
Georgi
Telerik team
Kong
Top achievements
Rank 1
Martin
Telerik team
Share this question
or