public TableRow GenerateTableRow(CellProps[] cellProps, UInt32Value height)
        {
            TableRow tableRow1 = new TableRow();
            TableRowProperties tableRowProperties1 = generateTableRowProperties(height);
            tableRow1.Append(tableRowProperties1);

            foreach (CellProps cp in cellProps) {
                if (cp.span == 0) continue;
                TableCell tableCell1 = new TableCell();
                TableCellProperties tableCellProperties1 = new TableCellProperties();

                TableCellBorders tableCellBorders1 = generateTableCellBordersPlain();
                Shading shading1 = new Shading() { Val = ShadingPatternValues.Clear, Color = "auto", Fill = "auto" };
                NoWrap noWrap1 = new NoWrap();
                TableCellVerticalAlignment tableCellVerticalAlignment1 = new TableCellVerticalAlignment() { Val = TableVerticalAlignmentValues.Center };
                HideMark hideMark1 = new HideMark();

                if (cp.span > 1) {
                    GridSpan span = new GridSpan() { Val = (Int32Value)cp.span };
                    tableCellProperties1.Append(span);
                }

                tableCellProperties1.Append(tableCellBorders1);
                tableCellProperties1.Append(shading1);
                tableCellProperties1.Append(noWrap1);
                tableCellProperties1.Append(tableCellVerticalAlignment1);
                tableCellProperties1.Append(hideMark1);

                Paragraph paragraph1 = new Paragraph();

                ParagraphProperties paragraphProperties1 = new ParagraphProperties();
                Justification justification1 = new Justification() { Val = cp.align };

                ParagraphMarkRunProperties paragraphMarkRunProperties1 = new ParagraphMarkRunProperties();
                FontSize fontSize1 = new FontSize() { Val = "18" };
                FontSizeComplexScript fontSizeComplexScript1 = new FontSizeComplexScript() { Val = "18" };

                paragraphMarkRunProperties1.Append(fontSize1);
                paragraphMarkRunProperties1.Append(fontSizeComplexScript1);

                paragraphProperties1.Append(justification1);
                paragraphProperties1.Append(paragraphMarkRunProperties1);

                Run run1 = new Run();

                RunProperties runProperties1 = new RunProperties();
                FontSize fontSize2 = new FontSize() { Val = "18" };
                FontSizeComplexScript fontSizeComplexScript2 = new FontSizeComplexScript() { Val = "18" };

                runProperties1.Append(fontSize2);
                runProperties1.Append(fontSizeComplexScript2);

                run1.Append(runProperties1);
                if (cp.text != null) {
                    Text text1 = new Text();
                    text1.Text = cp.text;
                    run1.Append(text1);
                }

                paragraph1.Append(paragraphProperties1);
                paragraph1.Append(run1);

                tableCell1.Append(tableCellProperties1);
                tableCell1.Append(paragraph1);
                tableRow1.Append(tableCell1);

            }

            return tableRow1;
        }
        public TableRow GenerateTableFooterRow(CellProps[] cellProps, UInt32Value height)
        {
            // Add table row properties
            TableRow tableRow1 = new TableRow();
            TableRowProperties tableRowProperties1 = generateTableRowProperties(height);
            tableRow1.Append(tableRowProperties1);

            foreach (CellProps cp in cellProps) {
                if (cp.span == 0) continue;
                TableCell tableCell1 = new TableCell();
                TableCellProperties tableCellProperties1 = new TableCellProperties();
                TableCellBorders tableCellBorders1;

                if (cp.boxed) {
                    tableCellBorders1 = generateTableCellBordersBox();
                } else {
                    tableCellBorders1 = generateTableCellBordersPlain();
                }

                Shading shading1 = new Shading() { Val = ShadingPatternValues.Clear, Color = "auto", Fill = "auto" };
                NoWrap noWrap1 = new NoWrap();
                TableCellVerticalAlignment tableCellVerticalAlignment1 = new TableCellVerticalAlignment() { Val = TableVerticalAlignmentValues.Center };
                HideMark hideMark1 = new HideMark();

                tableCellProperties1.Append(tableCellBorders1);
                tableCellProperties1.Append(shading1);
                tableCellProperties1.Append(noWrap1);
                tableCellProperties1.Append(tableCellVerticalAlignment1);
                tableCellProperties1.Append(hideMark1);

                Paragraph paragraph1 = new Paragraph();

                ParagraphProperties paragraphProperties1 = new ParagraphProperties();
                Justification justification1 = new Justification() { Val = JustificationValues.Right };

                ParagraphMarkRunProperties paragraphMarkRunProperties1 = new ParagraphMarkRunProperties();
                Bold bold1 = new Bold();
                BoldComplexScript boldComplexScript1 = new BoldComplexScript();
                Color color1 = new Color() { Val = "333399" };
                FontSize fontSize1 = new FontSize() { Val = "18" };
                FontSizeComplexScript fontSizeComplexScript1 = new FontSizeComplexScript() { Val = "18" };

                paragraphMarkRunProperties1.Append(bold1);
                paragraphMarkRunProperties1.Append(boldComplexScript1);
                paragraphMarkRunProperties1.Append(color1);
                paragraphMarkRunProperties1.Append(fontSize1);
                paragraphMarkRunProperties1.Append(fontSizeComplexScript1);

                paragraphProperties1.Append(justification1);
                paragraphProperties1.Append(paragraphMarkRunProperties1);

                Run run1 = new Run();

                RunProperties runProperties1 = new RunProperties();
                Bold bold2 = new Bold();
                BoldComplexScript boldComplexScript2 = new BoldComplexScript();
                Color color2 = new Color() { Val = "333399" };
                FontSize fontSize2 = new FontSize() { Val = "18" };
                FontSizeComplexScript fontSizeComplexScript2 = new FontSizeComplexScript() { Val = "18" };

                runProperties1.Append(bold2);
                runProperties1.Append(boldComplexScript2);
                runProperties1.Append(color2);
                runProperties1.Append(fontSize2);
                runProperties1.Append(fontSizeComplexScript2);
                run1.Append(runProperties1);

                if (cp.text != null) {
                    Text text1 = new Text();
                    text1.Text = cp.text;
                    run1.Append(text1);
                }

                paragraph1.Append(paragraphProperties1);
                paragraph1.Append(run1);

                tableCell1.Append(tableCellProperties1);
                tableCell1.Append(paragraph1);
                tableRow1.Append(tableCell1);
            }
            return tableRow1;
        }
Example #3
0
        public void AddTableToDoc()
        {
            // open document and create table
            WordprocessingDocument myDoc = WordprocessingDocument.Open(docName, true);
            MainDocumentPart mainPart = myDoc.MainDocumentPart;
            Document doc = mainPart.Document;

            // create table to hold strategy details
            StrategyTable stratTab = new StrategyTable();
            string[] colwidths = {"3700", "980", "1180", "1120", "1480", "1120", "1160"};
            Table table1 = stratTab.CreateTable(colwidths);

            // create a header row
            CellProps[] cellProps = new CellProps[] {
            new CellProps() { align = JustificationValues.Left },
            new CellProps(),
            new CellProps() { text = "Weighting" },
            new CellProps() { text = "Amount" },
            new CellProps() { text = "Expected Yield*" },
            new CellProps() { text = "Projected Income*" }
            };
            TableRow header = stratTab.GenerateTableHeaderRow(cellProps, 465U);
            table1.Append(header);

            //  create an asset class section
            cellProps = new CellProps[] {
            new CellProps() { text = "Cash", align = JustificationValues.Left },
            new CellProps() { text = "1.5%" },
            new CellProps(),
            new CellProps(),
            new CellProps(),
            new CellProps()

            };
            header = stratTab.GenerateTableHeaderRow(cellProps, 255U);
            table1.Append(header);

            // create a content row
            cellProps = new CellProps[] {
            new CellProps() { span = 2, text = "Aviva Emerging Market Local Currency Bond Fund", align = JustificationValues.Left },
            new CellProps() { span = 0 },
            new CellProps() { text = "1.50%" },
            new CellProps() { text = "£15,000" },
            new CellProps() { text = "0.10%" },
            new CellProps() { text = "£15.00" }
            };

            TableRow row = stratTab.GenerateTableRow(cellProps, 255U);
            table1.Append(row);

            // create a footer row
            cellProps = new CellProps[] {
            new CellProps(),
            new CellProps() { text= "100.0%" },
            new CellProps(),
            new CellProps() { text = "£,1000,000", boxed = true },
            new CellProps(),
            new CellProps() { text = "£24,779", boxed = true }
            };

            TableRow footer = stratTab.GenerateTableFooterRow(cellProps, 255U);
            table1.Append(footer);

            // add table to doc and save
            List<SdtBlock> stdList =
                mainPart.Document.Descendants<SdtBlock>()
                .Where(s => "portfolio"
                .Contains
                (s.SdtProperties.GetFirstChild<SdtAlias>().Val.Value)).ToList();

            if (stdList.Count != 0) {
                SdtBlock sdt = stdList.First<SdtBlock>();
                OpenXmlElement parent = sdt.Parent;
                parent.InsertAfter(table1, sdt);
                //sdt.Remove();
            }

            doc.Save();
        }