You mix text mode with composite mode.
In the first code snippet, you are working in text mode. This means that the contents of the cell are considered only text, and the properties of the cell are respected, while the properties of elements added to the cell are ignored.
In the second code snippet, you are working in complex mode. The cell switches to composite mode the moment you use the AddElement() method. In this case, the properties of the cell are ignored. Instead, element properties are used.
For example: in text mode, the contents of a cell can have only one type of alignment. In complex mode, you can have a paragraph that is left-aligned, a paragraph that is centered, and a paragraph that is right-aligned, all in the same cell.
source share