private static PDF.PdfPCell GetFormattedCell(TableCell cell)
        {
            PDF.PdfPCell formattedCell = new PDF.PdfPCell();

            Element[] cellElements = cell.SubElements;

            foreach (Element temp in cellElements)
            {
                switch (temp.GetElementType())
                {
                    //TODO: Add other enum values
                    case ElementType.Text:
                        IT.Phrase phrase = new IT.Phrase(TextFormatter.GetFormattedText((Text)temp));
                        formattedCell.AddElement(phrase);
                        break;

                    case ElementType.Paragraph:
                        formattedCell.AddElement(ParagraphFormatter.GetFormattedParagraph((Paragraph)temp));
                        break;

                    case ElementType.Table:
                        formattedCell.AddElement(TableFormatter.GetFormattedTable((Table)temp));
                        break;

                    case ElementType.Image:
                        formattedCell.AddElement(ImageFormatter.GetFormattedImage((Image)temp));
                        break;
                }

            }

            return formattedCell;
        }
        private static Word.StyleTableCellProperties GetCellProperties(TableCell cell)
        {
            Word.StyleTableCellProperties cellProps = new Word.StyleTableCellProperties();

            Word.TableCellVerticalAlignment vAlign = new Word.TableCellVerticalAlignment();

            switch (cell.VerticalAlignment)
            {
                case VerticalAlignment.Top:
                    vAlign.Val = Word.TableVerticalAlignmentValues.Top;
                    break;
                case VerticalAlignment.Center:
                    vAlign.Val = Word.TableVerticalAlignmentValues.Center;
                    break;
                case VerticalAlignment.Bottom:
                    vAlign.Val = Word.TableVerticalAlignmentValues.Bottom;
                    break;
                default:
                    break;
            }

            cellProps.Append(vAlign);

            return cellProps;
        }
        private static OpenXmlElement GetFormattedCell(TableCell cell)
        {
            //The only way to handle empty cells in OOXML - add an empty paragaph or prevent creating the document
            if (cell == null || cell.SubElements.Count() == 0)
            {
                var emptyCell = new Word.TableCell();
                emptyCell.Append(new Word.Paragraph());
                return emptyCell;
            }

            Word.TableCell formattedCell = new Word.TableCell();
            formattedCell.Append(GetCellProperties(cell));

            Element[] cellElements = cell.SubElements;

            foreach (Element cellElement in cellElements)
            {
                switch (cellElement.GetElementType())
                {
                    case ElementType.Table:
                        Word.Paragraph nestedTablePara = new Word.Paragraph();
                        formattedCell.Append(GetFormattedElement(cellElement as Table));
                        formattedCell.Append(new Word.Paragraph());
                        break;

                    default:
                        if (cell.CanContain(cellElement.GetElementType()))
                        {
                            formattedCell.Append(ElementFactory.GetElement(cellElement));
                            break;
                        }
                        else throw new InvalidSubFeatureException(cell.GetElementType().ToString(), cellElement.GetElementType().ToString());
                }
            }

            return formattedCell;
        }
Exemple #4
0
 public void AddCell(TableCell cell)
 {
     cells.Add(cell);
 }
Exemple #5
0
 public TableRow(TableCell[] cells)
 {
     this.cells = new List<Element>(cells);
 }