/// <summary> /// Adds the runs to SDT content cell. /// </summary> /// <param name="sdtContentCell">The SDT content cell.</param> /// <param name="runs">The runs.</param> private void AddRunsToSdtContentCell(SdtContentCell sdtContentCell, List <Run> runs) { TableCell cell = new TableCell(); Paragraph para = new Paragraph(); para.RemoveAllChildren(); if (sdtContentCell.Descendants <ParagraphProperties>().Count() > 0) { para.ParagraphProperties = (ParagraphProperties)sdtContentCell.Descendants <ParagraphProperties>().First().Clone(); } foreach (Run run in runs) { para.AppendChild <Run>(run); } cell.AppendChild <Paragraph>(para); SetSdtContentKeepingPermissionElements(sdtContentCell, cell); }
public static void FillTextBox(this SdtContentCell content, string newText, JustificationValues alignment) { if (content != null) { // Retrieve old paragraph to get the current style of text Paragraph oldParagraph = content.Descendants <TableCell>().FirstOrDefault().Elements <Paragraph>().FirstOrDefault(); // Create a new text var paragraph = CreateParagraph(oldParagraph, newText, alignment); // Replace old text with new one if (oldParagraph != null) { content.Descendants <TableCell>().FirstOrDefault().ReplaceChild(paragraph, oldParagraph); } else { content.Descendants <TableCell>().FirstOrDefault().Append(paragraph); } } }
/// <summary> /// Adds the runs to SDT content cell. /// </summary> /// <param name="sdtContentCell">The SDT content cell.</param> /// <param name="runs">The runs.</param> private void AddRunsToSdtContentCell(SdtContentCell sdtContentCell, List<Run> runs) { TableCell cell = new TableCell(); Paragraph para = new Paragraph(); para.RemoveAllChildren(); if (sdtContentCell.Descendants<ParagraphProperties>().Count() > 0) para.ParagraphProperties = (ParagraphProperties)sdtContentCell.Descendants<ParagraphProperties>().First().Clone(); foreach (Run run in runs) { para.AppendChild<Run>(run); } cell.AppendChild<Paragraph>(para); SetSdtContentKeepingPermissionElements(sdtContentCell, cell); }