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):
Thanks,
Rob
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);//BACSSpan 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);//BankSpan 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 NameSpan 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 CodeSpan 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);//ChequeSpan 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 ToSpan 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 DetailsSpan 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 RowTableRow 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 Paddingtable.CellPadding = new Padding(5, 3, 5, 3);//Create Document & Apply StylesRadDocument document = new RadDocument();RadDocumentStyles.AddStylesToDocumentRepository(document);Section section = new Section();//Add Empty ParagraphParagraph paragraph = new Paragraph();paragraph.StyleName = "paragraphMailMergeTable";section.Blocks.Add(paragraph);//Add Tablesection.Blocks.Add(table);//Add Empty ParagraphParagraph paragraph1 = new Paragraph();paragraph1.StyleName = "paragraphMailMergeTable";section.Blocks.Add(paragraph1);//Add Section To Documentdocument.Sections.Add(section);document.MeasureAndArrangeInDefaultSize();return new DocumentFragment(document);Thanks,
Rob