TemplNET.TemplDoc.CellCopyContents C# (CSharp) Méthode

CellCopyContents() public static méthode

Copy (text) contents of srcCell into dstCell. Clears text of dstCell plus all but first paragraph instance before copying.
public static CellCopyContents ( Cell srcCell, Cell dstCell ) : void
srcCell Novacode.Cell
dstCell Novacode.Cell
Résultat void
        public static void CellCopyContents(Cell srcCell, Cell dstCell)
        {
            CellClear(dstCell, true);
            srcCell.Paragraphs.ToList().ForEach(p => dstCell.InsertParagraph(p));
        }
    }

Usage Example

Exemple #1
0
        public override TemplMatchTable Handler(DocX doc, object model, TemplMatchTable m)
        {
            var width = m.Table.Rows.First().Cells.Count;
            var keys  = TemplModelEntry.Get(model, m.Body).ToStringKeys();
            var nrows = (int)Math.Ceiling(keys.Count() / (float)width);

            m.Validate();
            m.RemovePlaceholder();
            for (int n = 0; n < width; n++)
            {
                if (n != m.CellIndex)
                {
                    TemplDoc.CellCopyContents(m.Cell, m.Row.Cells[n]);
                }
            }
            Row row = m.Row;

            for (int keyIdx = 0; keyIdx < nrows * width; keyIdx++)
            {
                if (keyIdx % width == 0)
                {
                    row = m.Table.InsertRow(m.Row, m.RowIndex + keyIdx / width + 1);
                }
                Cell cell = row.Cells[keyIdx % width];
                if (keyIdx < keys.Count())
                {
                    new TemplCollectionModule().BuildFromScope(doc, model, cell.Paragraphs, $"{m.Body}[{keys[keyIdx]}]");
                }
                else
                {
                    TemplDoc.CellClear(cell);
                }
            }
            m.Row.Remove();
            m.Removed = true;
            return(m);
        }