iTextSharp.text.Cell.AddElement C# (CSharp) Метод

AddElement() публичный Метод

Adds an element to this Cell.
You can't add ListItems, Rows, Cells, JPEGs, GIFs or PNGs to a Cell.
public AddElement ( IElement element ) : void
element IElement the Element to add
Результат void
        public void AddElement(IElement element) {
            if (IsTable()) {
                Table table = (Table) arrayList[0];
                Cell tmp = new Cell(element);
                tmp.Border = NO_BORDER;
                tmp.Colspan = table.Columns;
                table.AddCell(tmp);
                return;
            }
            switch (element.Type) {
                case Element.LISTITEM:
                case Element.ROW:
                case Element.CELL:
                    throw new BadElementException("You can't add listitems, rows or cells to a cell.");
                case Element.JPEG:
                case Element.IMGRAW:
                case Element.IMGTEMPLATE:
                    arrayList.Add(element);
                    break;
                case Element.LIST:
                    if (float.IsNaN(this.Leading)) {
                        leading = ((List) element).TotalLeading;
                    }
                    if (((List) element).IsEmpty()) return;
                    arrayList.Add(element);
                    return;
                case Element.ANCHOR:
                case Element.PARAGRAPH:
                case Element.PHRASE:
                    if (float.IsNaN(leading)) {
                        leading = ((Phrase) element).Leading;
                    }
                    if (((Phrase) element).IsEmpty()) return;
                    arrayList.Add(element);
                    return;
                case Element.CHUNK:
                    if (((Chunk) element).IsEmpty()) return;
                    arrayList.Add(element);
                    return;
                case Element.TABLE:
                    Table table = new Table(3);
                    float[] widths = new float[3];
                    widths[1] = ((Table)element).Width;

                    switch (((Table)element).Alignment) {
                        case Element.ALIGN_LEFT:
                            widths[0] = 0f;
                            widths[2] = 100f - widths[1];
                            break;
                        case Element.ALIGN_CENTER:
                            widths[0] = (100f - widths[1]) / 2f;
                            widths[2] = widths[0];
                            break;
                        case Element.ALIGN_RIGHT:
                            widths[0] = 100f - widths[1];
                            widths[2] = 0f;
                            break;
                    }
                    table.Widths = widths;
                    Cell tmp;
                    if (arrayList.Count == 0) {
                        table.AddCell(Cell.DummyCell);
                    }
                    else {
                        tmp = new Cell();
                        tmp.Border = NO_BORDER;
                        tmp.Colspan = 3;
                        foreach (IElement ele in arrayList) {
                            tmp.Add(ele);
                        }
                        table.AddCell(tmp);
                    }
                    tmp = new Cell();
                    tmp.Border = NO_BORDER;
                    table.AddCell(tmp);
                    table.InsertTable((Table)element);
                    tmp = new Cell();
                    tmp.Border = NO_BORDER;
                    table.AddCell(tmp);
                    table.AddCell(Cell.DummyCell);
                    Clear();
                    arrayList.Add(table);
                    return;
                default:
                    arrayList.Add(element);
                    break;
            }
        }

Usage Example

Пример #1
0
        /**
         * Creates a Cell with these attributes.
         * @param rowAttributes
         * @return a cell based on these attributes.
         * @throws BadElementException
         */
        public Cell CreateCell(SimpleCell rowAttributes)
        {
            Cell cell = new Cell();

            cell.CloneNonPositionParameters(rowAttributes);
            cell.SoftCloneNonPositionParameters(this);
            cell.Colspan             = colspan;
            cell.HorizontalAlignment = horizontalAlignment;
            cell.VerticalAlignment   = verticalAlignment;
            cell.UseAscender         = useAscender;
            cell.UseBorderPadding    = useBorderPadding;
            cell.UseDescender        = useDescender;
            foreach (IElement element in content)
            {
                cell.AddElement(element);
            }
            return(cell);
        }
All Usage Examples Of iTextSharp.text.Cell::AddElement