Method SetText
SetText(TableCell, string, CharacterFormat?)
Replaces a table cell's content with one paragraph holding text.
public static Paragraph SetText(this TableCell cell, string text, CharacterFormat? format = null)
Parameters
cellTableCellThe cell.
textstringThe text.
formatCharacterFormatThe direct run formatting, or null to specify none. The bag is cloned, so later changes to the caller's instance do not reach the document.
Returns
- Paragraph
The cell's paragraph.
Remarks
This is the call for filling a cell that AppendTable made. A cell must hold
at least one block, so every new cell already has an empty paragraph, and
AppendParagraph(TableCell, string?) adds a second one after it -
a blank line above the text in every cell. SetText writes into the paragraph that
is already there instead.
The cell's first paragraph is kept, with its paragraph formatting and its mark's
run formatting, and its content is replaced by one run. Every other block in the cell
is removed, as setting the text of a cell's range in Word does. If the cell does not
begin with a paragraph, a new one is inserted first. An empty
text leaves the cell with one empty paragraph.
Exceptions
- ArgumentNullException
cellortextis null.