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

Table - Merge Cells Programmatically

1 Answer 240 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 12 Nov 2013, 11:12 AM
Hi,

How do you merge table cells programmatically?

I'm creating a table via code as customer merge field, but I need to merge my header row with with all cells within the same row so that is spans multiple columns.

I'm using library version 2013.1.220.40.

Here's my code thus far (Sorry it's quite long):

Table table = new Table();
 
//Payment Details Title **
Span spanPaymentDetails = new Span("Payment Details");
spanPaymentDetails.StyleName = "styleTableTitle14";
Paragraph paragraphPaymentDetails = new Paragraph();
paragraphPaymentDetails.Inlines.Add(spanPaymentDetails);
 
TableCell cellPaymentDetails = new TableCell();
cellPaymentDetails.Background = Colors.LightGray;
cellPaymentDetails.Blocks.Add(paragraphPaymentDetails);
 
 
//BACS
Span spanBACS = new Span("BACS:");
spanBACS.StyleName = "styleTableContent14";
spanBACS.FontStyle = FontStyles.Italic;
Paragraph paragraphBACS = new Paragraph();
paragraphBACS.Inlines.Add(spanBACS);
 
TableCell cellBACS = new TableCell();
cellBACS.Background = Colors.LightGray;
cellBACS.Blocks.Add(paragraphBACS);
 
 
//Bank
Span spanBankTitle = new Span("Bank: ");
spanBankTitle.StyleName = "styleTableContent14";
spanBankTitle.FontStyle = FontStyles.Italic;
Span spanBankDetail = new Span("HSBC");
spanBankDetail.StyleName = "styleTableContent14";
Paragraph paragraphBank = new Paragraph();
paragraphBank.Inlines.Add(spanBankTitle);
paragraphBank.Inlines.Add(spanBankDetail);
 
TableCell cellBank = new TableCell();
cellBank.Background = Colors.Transparent;
cellBank.Blocks.Add(paragraphBank);
 
 
//Account Name
Span spanAccountNameTitle = new Span("Account Name: ");
spanAccountNameTitle.StyleName = "styleTableContent14";
spanAccountNameTitle.FontStyle = FontStyles.Italic;
Span spanAccountNameDetail = new Span("My Company Name");
spanAccountNameDetail.StyleName = "styleTableContent14";
Paragraph paragraphAccountName = new Paragraph();
paragraphAccountName.Inlines.Add(spanAccountNameTitle);
paragraphAccountName.Inlines.Add(spanAccountNameDetail);
 
TableCell cellAccountName = new TableCell();
cellAccountName.Background = Colors.LightGray;
cellAccountName.Blocks.Add(paragraphAccountName);
 
 
//Sort Code
Span spanSortCodeTitle = new Span("Sort Code: ");
spanSortCodeTitle.StyleName = "styleTableContent14";
spanSortCodeTitle.FontStyle = FontStyles.Italic;
Span spanSortCodeDetail = new Span("22-11-33");
spanSortCodeDetail.StyleName = "styleTableContent14";
Paragraph paragraphSortCode = new Paragraph();
paragraphSortCode.Inlines.Add(spanSortCodeTitle);
paragraphSortCode.Inlines.Add(spanSortCodeDetail);
 
TableCell cellSortCode = new TableCell();
cellSortCode.Background = Colors.LightGray;
cellSortCode.Blocks.Add(paragraphSortCode);
 
 
//Account No.
Span spanAccountNoTitle = new Span("Account No. ");
spanAccountNoTitle.StyleName = "styleTableContent14";
spanAccountNoTitle.FontStyle = FontStyles.Italic;
Span spanAccountNoDetail = new Span("xxxx xxxx");
spanAccountNoDetail.StyleName = "styleTableContent14";
Paragraph paragraphAccountNo = new Paragraph();
paragraphAccountNo.Inlines.Add(spanAccountNoTitle);
paragraphAccountNo.Inlines.Add(spanAccountNoDetail);
 
TableCell cellAccountNo = new TableCell();
cellAccountNo.Background = Colors.LightGray;
cellAccountNo.Blocks.Add(paragraphAccountNo);
 
 
 
//Cheque
Span spanCheque = new Span("Cheque:");
spanCheque.StyleName = "styleTableContent14";
Paragraph paragraphCheque = new Paragraph();
paragraphCheque.Inlines.Add(spanCheque);
 
TableCell cellCheque = new TableCell();
cellCheque.Background = Colors.LightGray;
cellCheque.Blocks.Add(paragraphCheque);
 
 
//Cheque Made Payable To
Span spanChequeMadePayableTo = new Span("Made Payable To:");
spanChequeMadePayableTo.StyleName = "styleTableContent14";
Paragraph paragraphChequeMadePayableTo = new Paragraph();
paragraphChequeMadePayableTo.Inlines.Add(spanChequeMadePayableTo);
 
TableCell cellChequeMadePayableTo = new TableCell();
cellChequeMadePayableTo.Background = Colors.LightGray;
cellChequeMadePayableTo.Blocks.Add(paragraphChequeMadePayableTo);
 
 
//Cheque Details
Span spanChequeDetail = new Span("My Company Name");
spanChequeDetail.StyleName = "styleTableContent14";
Paragraph paragraphChequeDetail = new Paragraph();
paragraphChequeDetail.Inlines.Add(spanChequeDetail);
 
TableCell cellChequeDetail = new TableCell();
cellChequeDetail.Background = Colors.LightGray;
cellChequeDetail.Blocks.Add(paragraphChequeDetail);
 
 
 
 
//Add Cells To Table Row
TableRow rowTitle = new TableRow();
rowTitle.Cells.Add(cellPaymentDetails);
table.AddRow(rowTitle);
 
 
TableRow rowDetails = new TableRow();
rowDetails.Cells.Add(cellBACS);
rowDetails.Cells.Add(cellBank);
rowDetails.Cells.Add(cellAccountName);
rowDetails.Cells.Add(cellCheque);
rowDetails.Cells.Add(cellChequeMadePayableTo);
table.AddRow(rowDetails);
 
TableRow rowDetails2 = new TableRow();
rowDetails2.Cells.Add(new TableCell());
rowDetails2.Cells.Add(cellSortCode);
rowDetails2.Cells.Add(cellAccountNo);
rowDetails2.Cells.Add(new TableCell());
rowDetails2.Cells.Add(cellChequeDetail);
table.AddRow(rowDetails2);
 
//Change Cell Padding
table.CellPadding = new Padding(5, 3, 5, 3);
 
//Create Document & Apply Styles
RadDocument document = new RadDocument();
RadDocumentStyles.AddStylesToDocumentRepository(document);
 
Section section = new Section();
 
//Add Empty Paragraph
Paragraph paragraph = new Paragraph();
paragraph.StyleName = "paragraphMailMergeTable";
section.Blocks.Add(paragraph);
 
//Add Table
section.Blocks.Add(table);
 
//Add Empty Paragraph
Paragraph paragraph1 = new Paragraph();
paragraph1.StyleName = "paragraphMailMergeTable";
section.Blocks.Add(paragraph1);
 
//Add Section To Document
document.Sections.Add(section);
 
document.MeasureAndArrangeInDefaultSize();
 
return new DocumentFragment(document);


Thanks,

Rob

1 Answer, 1 is accepted

Sort by
0
Robert
Top achievements
Rank 1
answered on 12 Nov 2013, 11:56 AM
ok I found it.

cellPaymentDetails.ColumnSpan = 5;

Rob
Tags
RichTextBox
Asked by
Robert
Top achievements
Rank 1
Answers by
Robert
Top achievements
Rank 1
Share this question
or