Exemple #1
0
        private void AddCells()
        {
            var tableCells = tableRow.Descendants <DocumentFormat.OpenXml.Wordprocessing.TableCell>().ToArray();

            cells = new TableCell[table.NumberOfColumns];

            if (tableCells.Count() > 0)
            {
                for (int i = 0; i < table.NumberOfColumns; i++)
                {
                    cells[i] = new TableCell(this, tableCells[i]);
                }
            }
            else
            {
                for (int i = 0; i < table.NumberOfColumns; i++)
                {
                    var tableCell = tableRow.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());

                    var tableCellProperties = tableCell.GetOrCreate <TableCellProperties>(true);
                    var tableCellWidth      = tableCellProperties.GetOrCreate <TableCellWidth>();
                    tableCellWidth.Width = table.ColumnWidths[i];
                    tableCellWidth.Type  = TableWidthUnitValues.Dxa;

                    var cell = new TableCell(this, tableCell);
                    cell.AddParagraph();

                    cells[i] = cell;
                }
            }
        }
Exemple #2
0
        protected void btnIspisi_Click(object sender, EventArgs e)
        {
            Body      body;
            Paragraph par;
            Run       run;

            DocumentFormat.OpenXml.Wordprocessing.TableRow  tr;
            DocumentFormat.OpenXml.Wordprocessing.TableCell tc;
            TableCellProperties tcp;
            RunProperties       rp;

            WordprocessingDocument package = WordprocessingDocument.Create(HttpRuntime.AppDomainAppPath + "\\izleti.docx", WordprocessingDocumentType.Document);

            package.AddMainDocumentPart();

            Document document = new Document();

            package.MainDocumentPart.Document = document;
            body = document.AppendChild(new Body());
            SectionProperties sectionProps = body.AppendChild(new SectionProperties());

            sectionProps.Append(new PageMargin()
            {
                Top = 720, Right = 720, Bottom = 720, Left = 720, Header = 0, Footer = 0, Gutter = 0
            });                                                                                                                             // 1440 = 1", 720 = 0.5";

            par = body.AppendChild(new Paragraph());
            run = par.AppendChild(new Run());
            rp  = run.AppendChild(new RunProperties());
            rp.AppendChild(new Bold()
            {
                Val = OnOffValue.FromBoolean(true)
            });
            rp.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.FontSize()
            {
                Val = "32"
            });
            run.AppendChild(new Text("Izleti"));

            DocumentFormat.OpenXml.Wordprocessing.Table table = new DocumentFormat.OpenXml.Wordprocessing.Table();
            TableProperties props = new TableProperties
                                    (
                new TableBorders
                (
                    new TableWidth {
                Width = "5000", Type = TableWidthUnitValues.Pct
            },                                                                                  // 100%
                    new TopBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.None),
                Size = 6
            },
                    new BottomBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.Single),
                Size = 6
            },
                    new LeftBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.None),
                Size = 6
            },
                    new RightBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.None),
                Size = 6
            },
                    new InsideHorizontalBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.Single),
                Size = 6
            },
                    new InsideVerticalBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.None),
                Size = 6
            }
                )
                                    );

            table.AppendChild <TableProperties>(props);

            // red
            tr = table.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableRow());
            // ćelija
            tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
            tcp = tc.AppendChild(new TableCellProperties());
            tcp.Append(new Shading()
            {
                Val = ShadingPatternValues.Clear, Color = "auto", Fill = "black"
            });
            par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
            {
                Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
            })));
            run = par.AppendChild(new Run());
            rp  = run.AppendChild(new RunProperties());
            rp.Append(new Color()
            {
                Val = "ffffff"
            });
            rp.Append(new Bold()
            {
                Val = OnOffValue.FromBoolean(true)
            });
            run.Append(new Text("Datum"));
            // ćelija
            tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
            tcp = tc.AppendChild(new TableCellProperties());
            tcp.Append(new Shading()
            {
                Val = ShadingPatternValues.Clear, Color = "auto", Fill = "black"
            });
            par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
            {
                Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
            })));
            run = par.AppendChild(new Run());
            rp  = run.AppendChild(new RunProperties());
            rp.Append(new Color()
            {
                Val = "ffffff"
            });
            rp.Append(new Bold()
            {
                Val = OnOffValue.FromBoolean(true)
            });
            run.Append(new Text("Naziv"));
            // ćelija
            tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
            tcp = tc.AppendChild(new TableCellProperties());
            tcp.Append(new Shading()
            {
                Val = ShadingPatternValues.Clear, Color = "auto", Fill = "black"
            });
            par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
            {
                Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
            })));
            run = par.AppendChild(new Run());
            rp  = run.AppendChild(new RunProperties());
            rp.Append(new Color()
            {
                Val = "ffffff"
            });
            rp.Append(new Bold()
            {
                Val = OnOffValue.FromBoolean(true)
            });
            run.Append(new Text("Glavni vodič"));
            // ćelija
            tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
            tcp = tc.AppendChild(new TableCellProperties());
            tcp.Append(new Shading()
            {
                Val = ShadingPatternValues.Clear, Color = "auto", Fill = "black"
            });
            par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
            {
                Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
            })));
            run = par.AppendChild(new Run());
            rp  = run.AppendChild(new RunProperties());
            rp.Append(new Color()
            {
                Val = "ffffff"
            });
            rp.Append(new Bold()
            {
                Val = OnOffValue.FromBoolean(true)
            });
            run.Append(new Text("Pomoćni vodič"));
            // ćelija
            tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
            tcp = tc.AppendChild(new TableCellProperties());
            tcp.Append(new Shading()
            {
                Val = ShadingPatternValues.Clear, Color = "auto", Fill = "black"
            });
            par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
            {
                Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
            })));
            run = par.AppendChild(new Run());
            rp  = run.AppendChild(new RunProperties());
            rp.Append(new Color()
            {
                Val = "ffffff"
            });
            rp.Append(new Bold()
            {
                Val = OnOffValue.FromBoolean(true)
            });
            run.Append(new Text("Udruga"));
            // ćelija
            tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
            tcp = tc.AppendChild(new TableCellProperties());
            tcp.Append(new Shading()
            {
                Val = ShadingPatternValues.Clear, Color = "auto", Fill = "black"
            });
            par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
            {
                Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
            })));
            run = par.AppendChild(new Run());
            rp  = run.AppendChild(new RunProperties());
            rp.Append(new Color()
            {
                Val = "ffffff"
            });
            rp.Append(new Bold()
            {
                Val = OnOffValue.FromBoolean(true)
            });
            run.Append(new Text("Odredište"));
            // ćelija
            tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
            tcp = tc.AppendChild(new TableCellProperties());
            tcp.Append(new Shading()
            {
                Val = ShadingPatternValues.Clear, Color = "auto", Fill = "black"
            });
            par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
            {
                Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
            })));
            run = par.AppendChild(new Run());
            rp  = run.AppendChild(new RunProperties());
            rp.Append(new Color()
            {
                Val = "ffffff"
            });
            rp.Append(new Bold()
            {
                Val = OnOffValue.FromBoolean(true)
            });
            run.Append(new Text("Trajanje"));
            // ćelija
            tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
            tcp = tc.AppendChild(new TableCellProperties());
            tcp.Append(new Shading()
            {
                Val = ShadingPatternValues.Clear, Color = "auto", Fill = "black"
            });
            par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
            {
                Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
            })));
            run = par.AppendChild(new Run());
            rp  = run.AppendChild(new RunProperties());
            rp.Append(new Color()
            {
                Val = "ffffff"
            });
            rp.Append(new Bold()
            {
                Val = OnOffValue.FromBoolean(true)
            });
            run.Append(new Text("Broj sudionika"));

            string          query = "select izleti.datum, izleti.naziv, vodicig.prezime + ', ' + vodicig.ime as glavnivodic, vodicip.prezime + ', ' + vodicip.ime as pomocnivodic, udruge.naziv as udruga, izleti.odrediste, izleti.trajanje, izleti.brojsudionika from ((izleti left join vodici as vodicig on izleti.glavni_vod_id = vodicig.id) left join vodici as vodicip on izleti.pomocni_vod_id = vodicip.id) left join udruge on izleti.udr_id = udruge.id where 1 = 1 " + ViewState["filter"] + " order by datum desc";
            OleDbConnection con   = new OleDbConnection(ConfigurationManager.ConnectionStrings["connstr"].ConnectionString);
            OleDbCommand    cmd   = new OleDbCommand();

            cmd.CommandText = query;
            cmd.CommandType = CommandType.Text;
            cmd.Connection  = con;
            con.Open();
            OleDbDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                tr  = new DocumentFormat.OpenXml.Wordprocessing.TableRow();
                tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
                tcp = tc.AppendChild(new TableCellProperties());
                par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
                {
                    Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
                })));
                run = par.AppendChild(new Run());
                rp  = run.AppendChild(new RunProperties());
                run.Append(new Text(Convert.ToDateTime(dr["datum"]).ToString("dd.MM.yyyy.")));

                tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
                tcp = tc.AppendChild(new TableCellProperties());
                par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
                {
                    Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
                })));
                run = par.AppendChild(new Run());
                rp  = run.AppendChild(new RunProperties());
                run.Append(new Text(dr["naziv"] as string));

                tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
                tcp = tc.AppendChild(new TableCellProperties());
                par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
                {
                    Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
                })));
                run = par.AppendChild(new Run());
                rp  = run.AppendChild(new RunProperties());
                run.Append(new Text(dr["glavnivodic"] as string));

                tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
                tcp = tc.AppendChild(new TableCellProperties());
                par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
                {
                    Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
                })));
                run = par.AppendChild(new Run());
                rp  = run.AppendChild(new RunProperties());
                run.Append(new Text(dr["pomocnivodic"] as string));

                tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
                tcp = tc.AppendChild(new TableCellProperties());
                par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
                {
                    Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
                })));
                run = par.AppendChild(new Run());
                rp  = run.AppendChild(new RunProperties());
                run.Append(new Text(dr["udruga"] as string));

                tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
                tcp = tc.AppendChild(new TableCellProperties());
                par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
                {
                    Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
                })));
                run = par.AppendChild(new Run());
                rp  = run.AppendChild(new RunProperties());
                run.Append(new Text(dr["odrediste"] as string));

                tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
                tcp = tc.AppendChild(new TableCellProperties());
                par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
                {
                    Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
                })));
                run = par.AppendChild(new Run());
                rp  = run.AppendChild(new RunProperties());
                run.Append(new Text(dr["trajanje"].ToString()));

                tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
                tcp = tc.AppendChild(new TableCellProperties());
                par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
                {
                    Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
                })));
                run = par.AppendChild(new Run());
                rp  = run.AppendChild(new RunProperties());
                run.Append(new Text(dr["brojsudionika"].ToString()));

                table.Append(tr);
            }
            document.Body.Append(table);
            document.Save();
            package.Close();

            con.Close();

            Response.ContentType = "Application/docx";
            Response.AppendHeader("Content-Disposition", "attachment; filename=izleti.docx");
            Response.TransmitFile(HttpRuntime.AppDomainAppPath + "\\izleti.docx");
            Response.End();
        }
        /// <summary>
        /// The write table.
        /// </summary>
        /// <param name="t">The t.</param>
        public void WriteTable(Table t)
        {
            this.body.AppendChild(CreateParagraph(t.GetFullCaption(this.style), TableCaptionId));

            var table = new DocumentFormat.OpenXml.Wordprocessing.Table();

            var tableProperties1 = new TableProperties();
            var tableStyle1      = new TableStyle {
                Val = "TableGrid"
            };
            var tableWidth1 = new TableWidth {
                Width = "0", Type = TableWidthUnitValues.Auto
            };
            var tableLook1 = new TableLook
            {
                Val              = "04A0",
                FirstRow         = true,
                LastRow          = false,
                FirstColumn      = true,
                LastColumn       = false,
                NoHorizontalBand = false,
                NoVerticalBand   = true
            };

            tableProperties1.AppendChild(tableStyle1);
            tableProperties1.AppendChild(tableWidth1);
            tableProperties1.AppendChild(tableLook1);

            var tableGrid1 = new TableGrid();

            // ReSharper disable once UnusedVariable
            foreach (var tc in t.Columns)
            {
                // TODO: use tc.Width to set the width of the column
                var gridColumn1 = new GridColumn {
                    Width = "3070"
                };
                tableGrid1.AppendChild(gridColumn1);
            }

            foreach (var row in t.Rows)
            {
                var tr = new TableRow();

                if (row.IsHeader)
                {
                    var trp          = new TableRowProperties();
                    var tableHeader1 = new TableHeader();
                    trp.AppendChild(tableHeader1);
                    tr.AppendChild(trp);
                }

                int j = 0;
                foreach (var c in row.Cells)
                {
                    bool isHeader = row.IsHeader || t.Columns[j++].IsHeader;
                    var  cell     = new TableCell();
                    var  tcp      = new TableCellProperties();
                    var  borders  = new TableCellBorders();
                    borders.AppendChild(
                        new BottomBorder
                    {
                        Val   = BorderValues.Single,
                        Size  = 4U,
                        Space = 0U,
                        Color = "auto"
                    });
                    borders.AppendChild(
                        new TopBorder
                    {
                        Val   = BorderValues.Single,
                        Size  = 4U,
                        Space = 0U,
                        Color = "auto"
                    });
                    borders.AppendChild(
                        new LeftBorder
                    {
                        Val   = BorderValues.Single,
                        Size  = 4U,
                        Space = 0U,
                        Color = "auto"
                    });
                    borders.AppendChild(
                        new RightBorder
                    {
                        Val   = BorderValues.Single,
                        Size  = 4U,
                        Space = 0U,
                        Color = "auto"
                    });
                    tcp.AppendChild(borders);

                    cell.AppendChild(tcp);
                    string styleId = isHeader ? "TableHeader" : "TableText";
                    cell.AppendChild(CreateParagraph(c.Content, styleId));
                    tr.AppendChild(cell);
                }

                table.AppendChild(tr);
            }

            this.body.AppendChild(table);
        }
 Word.TableRow CreateRow(ArrayList cellText)
 {
     Word.TableRow tr = new Word.TableRow();
     // Create cells with simple text.
     foreach (string s in cellText)
     {
         Word.TableCell tc = new Word.TableCell();
         Word.Paragraph p = new Word.Paragraph();
         Word.Run r = new Word.Run();
         Word.Text t = new Word.Text(s);
         r.AppendChild(t);
         p.AppendChild(r);
         tc.AppendChild(p);
         tr.AppendChild(tc);
     }
     return tr;
 }
        public void InsertForcesTable(IForcesModel forces)
        {
            Paragraph     para          = _body.AppendChild(new Paragraph());
            Run           run           = para.AppendChild(new Run());
            RunProperties runProperties = getHeading2(run);

            run.AppendChild(new Text(++_diagmarCounter + ". Decision Forces Viewpoint: " + forces.Name));
            //_body.AppendChild(new Paragraph(new Run(new Text(++_diagmarCounter + ". Decision Forces Viewpoint"))));
            _body.AppendChild(new Paragraph(new Run(new Text())));

            var table = new Table();

            var props = new TableProperties(
                new TableBorders(
                    new TopBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.Single),
                Size = 11
            },
                    new BottomBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.Single),
                Size = 11
            },
                    new LeftBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.Single),
                Size = 11
            },
                    new RightBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.Single),
                Size = 11
            },
                    new InsideHorizontalBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.Single),
                Size = 11
            },
                    new InsideVerticalBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.Single),
                Size = 11
            }));

            table.AppendChild(props);

            var emptyCell = new TableCell();

            // insert an empty cell in tol left of forces table
            var decRow = new TableRow();

            decRow.AppendChild(emptyCell);
            emptyCell.AppendChild(new Paragraph(new Run(new Text(""))));

            // insert the concern header and the decisions names
            var concCellHeader = new TableCell(new Paragraph(new Run(new Text("Concerns"))));

            decRow.AppendChild(concCellHeader);
            foreach (
                TableCell decCell in
                forces.GetDecisions()
                .Select(decision => new TableCell(new Paragraph(new Run(new Text(decision.Name))))))
            {
                decRow.AppendChild(decCell);
            }
            table.AppendChild(decRow);


            foreach (var concernsPerForces in forces.GetConcernsPerForce())
            {
                IEAElement        force    = concernsPerForces.Key;
                List <IEAElement> concerns = concernsPerForces.Value;

                foreach (IEAElement concern in concerns)
                {
                    var forceRow  = new TableRow();
                    var forceCell = new TableCell(new Paragraph(new Run(new Text(force.Name))));
                    forceRow.AppendChild(forceCell);
                    var concCell = new TableCell();
                    concCell.AppendChild(new Paragraph(new Run(new Text(concern.Name))));
                    forceRow.AppendChild(concCell);

                    // insert ratings
                    foreach (Rating rating in forces.GetRatings())
                    {
                        if (rating.ForceGUID != force.GUID || rating.ConcernGUID != concern.GUID)
                        {
                            continue;
                        }
                        if (forces.GetDecisions().Any(decision => rating.DecisionGUID == decision.GUID))
                        {
                            var ratCell = new TableCell();
                            ratCell.AppendChild(new Paragraph(new Run(new Text(rating.Value))));
                            forceRow.AppendChild(ratCell);
                        }
                    }
                    table.AppendChild(forceRow);
                }
            }


            _body.AppendChild(table);
            _body.AppendChild(new Paragraph());
        }
Exemple #6
0
        protected void btnIspisi_Click(object sender, EventArgs e)
        {
            Body      body;
            Paragraph par;
            Run       run;

            DocumentFormat.OpenXml.Wordprocessing.TableRow  tr;
            DocumentFormat.OpenXml.Wordprocessing.TableCell tc;
            TableCellProperties tcp;
            RunProperties       rp;

            WordprocessingDocument package = WordprocessingDocument.Create(HttpRuntime.AppDomainAppPath + "\\poste.docx", WordprocessingDocumentType.Document);

            package.AddMainDocumentPart();

            Document document = new Document();

            package.MainDocumentPart.Document = document;
            body = document.AppendChild(new Body());
            SectionProperties sectionProps = body.AppendChild(new SectionProperties());

            sectionProps.Append(new PageMargin()
            {
                Top = 720, Right = 720, Bottom = 720, Left = 720, Header = 0, Footer = 0, Gutter = 0
            });                                                                                                                             // 1440 = 1", 720 = 0.5";

            par = body.AppendChild(new Paragraph());
            run = par.AppendChild(new Run());
            rp  = run.AppendChild(new RunProperties());
            rp.AppendChild(new Bold()
            {
                Val = OnOffValue.FromBoolean(true)
            });
            rp.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.FontSize()
            {
                Val = "32"
            });
            run.AppendChild(new Text("Države"));

            DocumentFormat.OpenXml.Wordprocessing.Table table = new DocumentFormat.OpenXml.Wordprocessing.Table();
            TableProperties props = new TableProperties
                                    (
                new TableBorders
                (
                    new TableWidth {
                Width = "5000", Type = TableWidthUnitValues.Pct
            },                                                                                  // 100%
                    new TopBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.None),
                Size = 6
            },
                    new BottomBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.Single),
                Size = 6
            },
                    new LeftBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.None),
                Size = 6
            },
                    new RightBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.None),
                Size = 6
            },
                    new InsideHorizontalBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.Single),
                Size = 6
            },
                    new InsideVerticalBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.None),
                Size = 6
            }
                )
                                    );

            table.AppendChild <TableProperties>(props);

            // red
            tr = table.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableRow());
            // ćelija
            tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
            tcp = tc.AppendChild(new TableCellProperties());
            tcp.Append(new Shading()
            {
                Val = ShadingPatternValues.Clear, Color = "auto", Fill = "black"
            });
            par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
            {
                Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
            })));
            run = par.AppendChild(new Run());
            rp  = run.AppendChild(new RunProperties());
            rp.Append(new Color()
            {
                Val = "ffffff"
            });
            rp.Append(new Bold()
            {
                Val = OnOffValue.FromBoolean(true)
            });
            run.Append(new Text("Broj"));
            // ćelija
            tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
            tcp = tc.AppendChild(new TableCellProperties());
            tcp.Append(new Shading()
            {
                Val = ShadingPatternValues.Clear, Color = "auto", Fill = "black"
            });
            par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
            {
                Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
            })));
            run = par.AppendChild(new Run());
            rp  = run.AppendChild(new RunProperties());
            rp.Append(new Color()
            {
                Val = "ffffff"
            });
            rp.Append(new Bold()
            {
                Val = OnOffValue.FromBoolean(true)
            });
            run.Append(new Text("Naziv"));

            string          query = "select broj, naziv from poste where 1 = 1 " + ViewState["filter"] + " order by broj, naziv";
            OleDbConnection con   = new OleDbConnection(ConfigurationManager.ConnectionStrings["connstr"].ConnectionString);
            OleDbCommand    cmd   = new OleDbCommand();

            cmd.CommandText = query;
            cmd.CommandType = CommandType.Text;
            cmd.Connection  = con;
            con.Open();
            OleDbDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                tr  = new DocumentFormat.OpenXml.Wordprocessing.TableRow();
                tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
                tcp = tc.AppendChild(new TableCellProperties());
                par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
                {
                    Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
                })));
                run = par.AppendChild(new Run());
                rp  = run.AppendChild(new RunProperties());
                run.Append(new Text(dr[0] as string));

                tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
                tcp = tc.AppendChild(new TableCellProperties());
                par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
                {
                    Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
                })));
                run = par.AppendChild(new Run());
                rp  = run.AppendChild(new RunProperties());
                run.Append(new Text(dr[1] as string));

                table.Append(tr);
            }
            document.Body.Append(table);
            document.Save();
            package.Close();

            con.Close();

            Response.ContentType = "Application/docx";
            Response.AppendHeader("Content-Disposition", "attachment; filename=poste.docx");
            Response.TransmitFile(HttpRuntime.AppDomainAppPath + "\\poste.docx");
            Response.End();
        }
Exemple #7
0
        protected void btnIspisi_Click(object sender, EventArgs e)
        {
            /*DateTime dt;
             * string d1 = "";
             * string d2 = "";
             * try {
             *  dt = Convert.ToDateTime(txtOdDatuma.Text);
             *  d1 = "#" + dt.Month + "/" + dt.Day + "/" + dt.Year + "#";
             * }
             * catch {
             * }
             * try {
             *  dt = Convert.ToDateTime(txtDoDatuma.Text);
             *  d2 = "#" + dt.Month + "/" + dt.Day + "/" + dt.Year + "#";
             * }
             * catch {
             * }*/

            Body      body;
            Paragraph par;
            Run       run;

            DocumentFormat.OpenXml.Wordprocessing.TableRow  tr;
            DocumentFormat.OpenXml.Wordprocessing.TableCell tc;
            TableCellProperties tcp;
            RunProperties       rp;

            WordprocessingDocument package = WordprocessingDocument.Create(HttpRuntime.AppDomainAppPath + "\\sintetika.docx", WordprocessingDocumentType.Document);

            package.AddMainDocumentPart();

            Document document = new Document();

            package.MainDocumentPart.Document = document;
            body = document.AppendChild(new Body());
            SectionProperties sectionProps = body.AppendChild(new SectionProperties());

            sectionProps.Append(new PageMargin()
            {
                Top = 720, Right = 720, Bottom = 720, Left = 720, Header = 0, Footer = 0, Gutter = 0
            });                                                                                                                             // 1440 = 1", 720 = 0.5";

            par = body.AppendChild(new Paragraph());
            run = par.AppendChild(new Run());
            rp  = run.AppendChild(new RunProperties());
            rp.AppendChild(new Bold()
            {
                Val = OnOffValue.FromBoolean(true)
            });
            rp.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.FontSize()
            {
                Val = "32"
            });
            run.AppendChild(new Text("Sintetika"));

            DocumentFormat.OpenXml.Wordprocessing.Table table = new DocumentFormat.OpenXml.Wordprocessing.Table();
            TableProperties props = new TableProperties
                                    (
                new TableBorders
                (
                    new TableWidth {
                Width = "5000", Type = TableWidthUnitValues.Pct
            },                                                                                  // 100%
                    new TopBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.None),
                Size = 6
            },
                    new BottomBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.Single),
                Size = 6
            },
                    new LeftBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.None),
                Size = 6
            },
                    new RightBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.None),
                Size = 6
            },
                    new InsideHorizontalBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.Single),
                Size = 6
            },
                    new InsideVerticalBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.None),
                Size = 6
            }
                )
                                    );

            table.AppendChild <TableProperties>(props);

            tr  = new DocumentFormat.OpenXml.Wordprocessing.TableRow();
            tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
            tcp = tc.AppendChild(new TableCellProperties());
            tcp.Append(new GridSpan()
            {
                Val = 2
            });
            par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
            {
                Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
            })));
            run = par.AppendChild(new Run());
            rp  = run.AppendChild(new RunProperties());
            rp.Append(new Bold()
            {
                Val = OnOffValue.FromBoolean(true)
            });
            rp.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.FontSize()
            {
                Val = "28"
            });
            run.Append(new Text("PRIPRAVNICI"));
            table.Append(tr);

            tr = new DocumentFormat.OpenXml.Wordprocessing.TableRow();
            // ćelija
            tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
            tcp = tc.AppendChild(new TableCellProperties());
            tcp.Append(new Shading()
            {
                Val = ShadingPatternValues.Clear, Color = "auto", Fill = "black"
            });
            par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
            {
                Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
            })));
            run = par.AppendChild(new Run());
            rp  = run.AppendChild(new RunProperties());
            rp.Append(new Color()
            {
                Val = "ffffff"
            });
            rp.Append(new Bold()
            {
                Val = OnOffValue.FromBoolean(true)
            });
            run.Append(new Text("Standard"));

            // ćelija
            tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
            tcp = tc.AppendChild(new TableCellProperties());
            tcp.Append(new Shading()
            {
                Val = ShadingPatternValues.Clear, Color = "auto", Fill = "black"
            });
            par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
            {
                Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
            })));
            run = par.AppendChild(new Run());
            rp  = run.AppendChild(new RunProperties());
            rp.Append(new Color()
            {
                Val = "ffffff"
            });
            rp.Append(new Bold()
            {
                Val = OnOffValue.FromBoolean(true)
            });
            run.Append(new Text("Broj"));

            table.Append(tr);

            string          query = query = "select qvodicitecajevi.standard, count(*) as broj from vodici inner join qvodicitecajevi on vodici.id = qvodicitecajevi.vod_id where vodici.clanarina like '%" + txtGodina.Text + "%' group by qvodicitecajevi.standard order by qvodicitecajevi.standard";
            OleDbConnection con   = new OleDbConnection(ConfigurationManager.ConnectionStrings["connstr"].ConnectionString);
            OleDbCommand    cmd   = new OleDbCommand();

            cmd.CommandText = query;
            cmd.CommandType = CommandType.Text;
            cmd.Connection  = con;
            con.Open();
            OleDbDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                tr  = new DocumentFormat.OpenXml.Wordprocessing.TableRow();
                tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
                tcp = tc.AppendChild(new TableCellProperties());
                par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
                {
                    Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
                })));
                run = par.AppendChild(new Run());
                rp  = run.AppendChild(new RunProperties());
                run.Append(new Text(dr["standard"].ToString()));

                tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
                tcp = tc.AppendChild(new TableCellProperties());
                par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
                {
                    Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
                })));
                run = par.AppendChild(new Run());
                rp  = run.AppendChild(new RunProperties());
                run.Append(new Text(dr["broj"].ToString()));

                table.Append(tr);
            }


            tr = new DocumentFormat.OpenXml.Wordprocessing.TableRow();
            // ćelija
            tc = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
            //tcp = tc.AppendChild(new TableCellProperties());
            //tcp.Append(new Shading() { Val = ShadingPatternValues.Clear, Color = "auto", Fill = "black" });
            par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
            {
                Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
            })));
            run = par.AppendChild(new Run());
            rp  = run.AppendChild(new RunProperties());
            //rp.Append(new Color() { Val = "ffffff" });
            //rp.Append(new Bold() { Val = OnOffValue.FromBoolean(true) });
            run.Append(new Text(""));
            table.Append(tr);


            tr  = new DocumentFormat.OpenXml.Wordprocessing.TableRow();
            tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
            tcp = tc.AppendChild(new TableCellProperties());
            tcp.Append(new GridSpan()
            {
                Val = 2
            });
            par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
            {
                Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
            })));
            run = par.AppendChild(new Run());
            rp  = run.AppendChild(new RunProperties());
            rp.Append(new Bold()
            {
                Val = OnOffValue.FromBoolean(true)
            });
            rp.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.FontSize()
            {
                Val = "28"
            });
            run.Append(new Text("VODIČI"));
            table.Append(tr);

            tr = new DocumentFormat.OpenXml.Wordprocessing.TableRow();
            // ćelija
            tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
            tcp = tc.AppendChild(new TableCellProperties());
            tcp.Append(new Shading()
            {
                Val = ShadingPatternValues.Clear, Color = "auto", Fill = "black"
            });
            par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
            {
                Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
            })));
            run = par.AppendChild(new Run());
            rp  = run.AppendChild(new RunProperties());
            rp.Append(new Color()
            {
                Val = "ffffff"
            });
            rp.Append(new Bold()
            {
                Val = OnOffValue.FromBoolean(true)
            });
            run.Append(new Text("Standard"));

            // ćelija
            tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
            tcp = tc.AppendChild(new TableCellProperties());
            tcp.Append(new Shading()
            {
                Val = ShadingPatternValues.Clear, Color = "auto", Fill = "black"
            });
            par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
            {
                Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
            })));
            run = par.AppendChild(new Run());
            rp  = run.AppendChild(new RunProperties());
            rp.Append(new Color()
            {
                Val = "ffffff"
            });
            rp.Append(new Bold()
            {
                Val = OnOffValue.FromBoolean(true)
            });
            run.Append(new Text("Broj"));

            table.Append(tr);

            query           = "select qvodiciispiti.standard, count(*) as broj from vodici inner join qvodiciispiti on vodici.id = qvodiciispiti.vod_id where vodici.clanarina like '%" + txtGodina.Text + "%' group by qvodiciispiti.standard order by qvodiciispiti.standard";
            cmd.CommandText = query;
            dr.Close();
            dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                tr  = new DocumentFormat.OpenXml.Wordprocessing.TableRow();
                tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
                tcp = tc.AppendChild(new TableCellProperties());
                par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
                {
                    Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
                })));
                run = par.AppendChild(new Run());
                rp  = run.AppendChild(new RunProperties());
                run.Append(new Text(dr["standard"].ToString()));

                tc  = tr.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.TableCell());
                tcp = tc.AppendChild(new TableCellProperties());
                par = tc.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines()
                {
                    Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0"
                })));
                run = par.AppendChild(new Run());
                rp  = run.AppendChild(new RunProperties());
                run.Append(new Text(dr["broj"].ToString()));

                table.Append(tr);
            }

            document.Body.Append(table);
            document.Save();
            package.Close();

            con.Close();

            Response.ContentType = "Application/docx";
            Response.AppendHeader("Content-Disposition", "attachment; filename=sintetika.docx");
            Response.TransmitFile(HttpRuntime.AppDomainAppPath + "\\sintetika.docx");
            Response.End();
        }
        public void InsertDecisionTable(IDecision decision)
        {
            var dataDict = new Dictionary <String, IList <String> >();

            dataDict.Add("Name", new List <string>());
            dataDict.Add("State", new List <string>());
            dataDict.Add("Problem", new List <string>());
            dataDict.Add("Decision", new List <string>());
            dataDict.Add("Argumentation", new List <string>());
            dataDict.Add("Alternatives", new List <string>());
            dataDict.Add("Related Decisions", new List <string>());
            dataDict.Add("Forces", new List <string>());
            dataDict.Add("Traces", new List <string>());
            dataDict.Add("Stakeholder Involvement", new List <string>());
            dataDict.Add("History", new List <string>());


            dataDict["Name"].Add(decision.Name);
            dataDict["State"].Add(decision.State);
            //dataDict["Problem"].Add(decision.Problem);
            //dataDict["Decision"].Add(decision.Solution);
            //dataDict["Argumentation"].Add(decision.Argumentation);

            _decisionCounter++;
            //_body.AppendChild(new Paragraph(new Run(new Text("Decision " +_decisionCounter.ToString() +": " + decision.Name))));

            var table = new Table();

            var props = new TableProperties(
                new TableBorders(
                    new TopBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.Single),
                Size = 11
            },
                    new BottomBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.Single),
                Size = 11
            },
                    new LeftBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.Single),
                Size = 11
            },
                    new RightBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.Single),
                Size = 11
            },
                    new InsideHorizontalBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.Single),
                Size = 11
            },
                    new InsideVerticalBorder
            {
                Val  = new EnumValue <BorderValues>(BorderValues.Single),
                Size = 11
            },
                    new TableWidth
            {
                Width = "5000",
                Type  = TableWidthUnitValues.Pct
            }
                    ),
                new TableCaption
            {
                Val = new StringValue("My Caption Val")         // Does not work..
            });

            table.AppendChild(props);

            foreach (IDecisionRelation relation in decision.RelatedDecisions)
            {
                dataDict["Related Decisions"].Add(relation.Decision.GUID.Equals(decision.GUID)
                                                      ? "<<this>> " + decision.Name + " - " + relation.Type +
                                                  " - " +
                                                  relation.RelatedDecision.Name
                                                      : relation.Decision.Name + " - " + relation.Type +
                                                  " - <<this>> " + decision.Name + "\r\n");
            }

            foreach (IDecisionRelation alternative in decision.Alternatives)
            {
                dataDict["Alternatives"].Add(alternative.Decision.GUID.Equals(decision.GUID)
                                                 ? "<<this>> " + decision.Name + " - " + alternative.Type +
                                             " - " + alternative.RelatedDecision.Name
                                                 : alternative.Decision.Name + " - " + alternative.Type +
                                             " - <<this>> " + decision.Name + "\r\n");
            }


            foreach (IForceEvaluation rating in decision.Forces)
            {
                IEAElement force = EAMain.Repository.GetElementByGUID(rating.Force.ForceGUID);
                dataDict["Forces"].Add(rating.Force.Name + " - " + force.Notes);
            }


            foreach (ITraceLink trace in decision.Traces)
            {
                dataDict["Traces"].Add(trace.TracedElementName);
            }


            foreach (IHistoryEntry entry in decision.History)
            {
                dataDict["History"].Add(entry.State + " " + entry.Modified.ToShortDateString());
            }

            foreach (IStakeholderAction stakeholderInvolvment in decision.Stakeholders)
            {
                string line = string.Format(Messages.ReportingStakeholderInvolvmentLine,
                                            stakeholderInvolvment.Stakeholder.Role,
                                            stakeholderInvolvment.Stakeholder.Name,
                                            stakeholderInvolvment.Action);
                dataDict["Stakeholder Involvement"].Add(line);
            }


            foreach (var entry in dataDict)
            {
                if (entry.Value.Count == 0)
                {
                    continue;
                }
                if ("".Equals(entry.Value[0]))
                {
                    continue;
                }

                var tableRow = new TableRow();

                var rowHeader = new TableCell();
                rowHeader.Append(new TableCellWidth {
                    Type = TableWidthUnitValues.Dxa, Width = "1821"
                });
                rowHeader.Append(
                    new TableCellProperties(new Shading
                {
                    Val   = ShadingPatternValues.Clear,
                    Color = "auto",
                    Fill  = "##d3d4d6"
                }));
                Paragraph para = rowHeader.AppendChild(new Paragraph());
                Run       run  = para.AppendChild(new Run());
                getBold(run);
                run.AppendChild(new Text(entry.Key));

                var       rowValue     = new TableCell();
                Paragraph rowValuePara = rowValue.AppendChild(new Paragraph());
                Run       rowValueRun  = rowValuePara.AppendChild(new Run());
                int       lineCount    = 0;
                foreach (string line in entry.Value)
                {
                    rowValueRun.AppendChild(new Text(line));
                    if (++lineCount != entry.Value.Count)
                    {
                        rowValueRun.AppendChild(new Break());
                    }
                }

                tableRow.AppendChild(rowHeader);
                tableRow.AppendChild(rowValue);
                table.AppendChild(tableRow);
            }

            /*  for (int i = 0; i <= data.GetUpperBound(0); i++)
             * {
             *  var tr = new TableRow();
             *  for (int j = 0; j <= data.GetUpperBound(1); j++)
             *  {
             *      var tc = new TableCell();
             *      if (j == 0)
             *      {
             *          //Apply the same width at column 1 (0)
             *          tc.Append(new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = "1821"});
             *          tc.Append(new TableCellProperties(new Shading{Val = ShadingPatternValues.Clear,Color = "auto",Fill = "##d3d4d6"}));
             *          Paragraph para = tc.AppendChild(new Paragraph());
             *          Run run = para.AppendChild(new Run());
             *          RunProperties runProperties = getBold(run);
             *          run.AppendChild(new Text(dataDict.));
             *      }
             *      else
             *      {
             *          tc.AppendChild(new Paragraph(new Run(new Text(data[i, j]))));
             *      }
             *
             *      tr.AppendChild(tc);
             *  }
             *  if (data[i, 1] != "")
             *      table.AppendChild(tr);
             * }*/

            _body.AppendChild(table);
            _body.AppendChild(new Paragraph());
        }
        private static void FillFirstTableRow(OpenXmlElement table, string relationshipId)
        {
            var tableRow = new TableRow
            {
                TextId               = HexBinaryValue.FromString("77777777"),
                ParagraphId          = HexBinaryValue.FromString("080C4265"),
                RsidTableRowAddition = HexBinaryValue.FromString("009B2C1D")
            };
            var rowProperties = new TableRowProperties();

            rowProperties.AppendChild(new GridAfter
            {
                Val = Int32Value.FromInt32(2)
            });
            rowProperties.AppendChild(new WidthAfterTableRow
            {
                Width = StringValue.FromString("6375"),
                Type  = new EnumValue <TableWidthUnitValues> {
                    Value = TableWidthUnitValues.Dxa
                }
            });
            tableRow.TableRowProperties = rowProperties;

            var tableCell = new TableCell
            {
                TableCellProperties = new TableCellProperties
                {
                    TableCellWidth = new TableCellWidth
                    {
                        Width = StringValue.FromString("800"),
                        Type  = new EnumValue <TableWidthUnitValues> {
                            Value = TableWidthUnitValues.Dxa
                        }
                    },
                    TableCellBorders = new TableCellBorders
                    {
                        TopBorder = new TopBorder
                        {
                            Val = new EnumValue <BorderValues> {
                                Value = BorderValues.Single
                            },
                            Size  = UInt32Value.FromUInt32(0),
                            Space = UInt32Value.FromUInt32(0),
                            Color = StringValue.FromString("FFFFFF")
                        },
                        LeftBorder = new LeftBorder
                        {
                            Val = new EnumValue <BorderValues> {
                                Value = BorderValues.Single
                            },
                            Size  = UInt32Value.FromUInt32(0),
                            Space = UInt32Value.FromUInt32(0),
                            Color = StringValue.FromString("FFFFFF")
                        },
                        BottomBorder = new BottomBorder
                        {
                            Val = new EnumValue <BorderValues> {
                                Value = BorderValues.Single
                            },
                            Size  = UInt32Value.FromUInt32(0),
                            Space = UInt32Value.FromUInt32(0),
                            Color = StringValue.FromString("FFFFFF")
                        },
                        RightBorder = new RightBorder
                        {
                            Val = new EnumValue <BorderValues> {
                                Value = BorderValues.Single
                            },
                            Size  = UInt32Value.FromUInt32(0),
                            Space = UInt32Value.FromUInt32(0),
                            Color = StringValue.FromString("FFFFFF")
                        }
                    }
                }
            };

            AddMainLogo(tableCell, relationshipId);

            tableRow.AppendChild(tableCell);

            table.AppendChild(tableRow);
        }
        private static void FillSecondTableRow(OpenXmlElement table)
        {
            var tableRow = new TableRow
            {
                TextId               = HexBinaryValue.FromString("77777777"),
                ParagraphId          = HexBinaryValue.FromString("3125C09D"),
                RsidTableRowAddition = HexBinaryValue.FromString("009B2C1D")
            };
            var rowProperties = new TableRowProperties();

            rowProperties.AppendChild(new GridAfter
            {
                Val = Int32Value.FromInt32(2)
            });
            rowProperties.AppendChild(new WidthAfterTableRow
            {
                Width = StringValue.FromString("6375"),
                Type  = new EnumValue <TableWidthUnitValues> {
                    Value = TableWidthUnitValues.Dxa
                }
            });
            tableRow.TableRowProperties = rowProperties;

            var tableCell = new TableCell
            {
                TableCellProperties = new TableCellProperties
                {
                    TableCellWidth = new TableCellWidth
                    {
                        Width = StringValue.FromString("800"),
                        Type  = new EnumValue <TableWidthUnitValues> {
                            Value = TableWidthUnitValues.Dxa
                        }
                    },
                    TableCellBorders = new TableCellBorders
                    {
                        TopBorder = new TopBorder
                        {
                            Val = new EnumValue <BorderValues> {
                                Value = BorderValues.Single
                            },
                            Size  = UInt32Value.FromUInt32(0),
                            Space = UInt32Value.FromUInt32(0),
                            Color = StringValue.FromString("FFFFFF")
                        },
                        LeftBorder = new LeftBorder
                        {
                            Val = new EnumValue <BorderValues> {
                                Value = BorderValues.Single
                            },
                            Size  = UInt32Value.FromUInt32(0),
                            Space = UInt32Value.FromUInt32(0),
                            Color = StringValue.FromString("FFFFFF")
                        },
                        BottomBorder = new BottomBorder
                        {
                            Val = new EnumValue <BorderValues> {
                                Value = BorderValues.Single
                            },
                            Size  = UInt32Value.FromUInt32(0),
                            Space = UInt32Value.FromUInt32(0),
                            Color = StringValue.FromString("FFFFFF")
                        },
                        RightBorder = new RightBorder
                        {
                            Val = new EnumValue <BorderValues> {
                                Value = BorderValues.Single
                            },
                            Size  = UInt32Value.FromUInt32(0),
                            Space = UInt32Value.FromUInt32(0),
                            Color = StringValue.FromString("FFFFFF")
                        }
                    }
                }
            };

            tableCell.AppendChild(new Paragraph
            {
                ParagraphId            = HexBinaryValue.FromString("595BC873"),
                TextId                 = HexBinaryValue.FromString("77777777"),
                RsidParagraphAddition  = HexBinaryValue.FromString("009B2C1D"),
                RsidRunAdditionDefault = HexBinaryValue.FromString("009B2C1D")
            });
            tableRow.AppendChild(tableCell);
            table.AppendChild(tableRow);
        }
        private static void FillFourthTableRow(OpenXmlElement table, GenerationData data)
        {
            var tableRow = new TableRow
            {
                TextId               = HexBinaryValue.FromString("77777777"),
                ParagraphId          = HexBinaryValue.FromString("0E828CE9"),
                RsidTableRowAddition = HexBinaryValue.FromString("009B2C1D")
            };

            var tableCell1 = new TableCell
            {
                TableCellProperties = new TableCellProperties
                {
                    TableCellWidth = new TableCellWidth
                    {
                        Width = StringValue.FromString("800"),
                        Type  = new EnumValue <TableWidthUnitValues> {
                            Value = TableWidthUnitValues.Dxa
                        }
                    },
                    TableCellBorders = new TableCellBorders
                    {
                        TopBorder = new TopBorder
                        {
                            Val = new EnumValue <BorderValues> {
                                Value = BorderValues.Single
                            },
                            Size  = UInt32Value.FromUInt32(0),
                            Space = UInt32Value.FromUInt32(0),
                            Color = StringValue.FromString("FFFFFF")
                        },
                        LeftBorder = new LeftBorder
                        {
                            Val = new EnumValue <BorderValues> {
                                Value = BorderValues.Single
                            },
                            Size  = UInt32Value.FromUInt32(0),
                            Space = UInt32Value.FromUInt32(0),
                            Color = StringValue.FromString("FFFFFF")
                        },
                        BottomBorder = new BottomBorder
                        {
                            Val = new EnumValue <BorderValues> {
                                Value = BorderValues.Single
                            },
                            Size  = UInt32Value.FromUInt32(0),
                            Space = UInt32Value.FromUInt32(0),
                            Color = StringValue.FromString("FFFFFF")
                        },
                        RightBorder = new RightBorder
                        {
                            Val = new EnumValue <BorderValues> {
                                Value = BorderValues.Single
                            },
                            Size  = UInt32Value.FromUInt32(0),
                            Space = UInt32Value.FromUInt32(0),
                            Color = StringValue.FromString("FFFFFF")
                        }
                    }
                }
            };

            tableCell1.AppendChild(new Paragraph {
                ParagraphId            = HexBinaryValue.FromString("7D33E7CB"),
                TextId                 = HexBinaryValue.FromString("77777777"),
                RsidParagraphAddition  = HexBinaryValue.FromString("009B2C1D"),
                RsidRunAdditionDefault = HexBinaryValue.FromString("009B2C1D")
            });
            tableRow.AppendChild(tableCell1);

            var tableCell2 = new TableCell
            {
                TableCellProperties = new TableCellProperties
                {
                    TableCellWidth = new TableCellWidth
                    {
                        Width = StringValue.FromString("2550"),
                        Type  = new EnumValue <TableWidthUnitValues> {
                            Value = TableWidthUnitValues.Dxa
                        }
                    },
                    TableCellBorders = new TableCellBorders
                    {
                        TopBorder = new TopBorder
                        {
                            Val = new EnumValue <BorderValues> {
                                Value = BorderValues.Single
                            },
                            Size  = UInt32Value.FromUInt32(0),
                            Space = UInt32Value.FromUInt32(0),
                            Color = StringValue.FromString("FFFFFF")
                        },
                        LeftBorder = new LeftBorder
                        {
                            Val = new EnumValue <BorderValues> {
                                Value = BorderValues.Single
                            },
                            Size  = UInt32Value.FromUInt32(0),
                            Space = UInt32Value.FromUInt32(0),
                            Color = StringValue.FromString("FFFFFF")
                        },
                        BottomBorder = new BottomBorder
                        {
                            Val = new EnumValue <BorderValues> {
                                Value = BorderValues.Single
                            },
                            Size  = UInt32Value.FromUInt32(0),
                            Space = UInt32Value.FromUInt32(0),
                            Color = StringValue.FromString("FFFFFF")
                        },
                        RightBorder = new RightBorder
                        {
                            Val = new EnumValue <BorderValues> {
                                Value = BorderValues.Single
                            },
                            Size  = UInt32Value.FromUInt32(0),
                            Space = UInt32Value.FromUInt32(0),
                            Color = StringValue.FromString("FFFFFF")
                        }
                    }
                }
            };

            tableCell2.AppendChild(new Paragraph
            {
                ParagraphId            = HexBinaryValue.FromString("4B505573"),
                TextId                 = HexBinaryValue.FromString("77777777"),
                RsidParagraphAddition  = HexBinaryValue.FromString("009B2C1D"),
                RsidRunAdditionDefault = HexBinaryValue.FromString("009B2C1D")
            });
            tableRow.AppendChild(tableCell2);

            var tableCell3 = new TableCell
            {
                TableCellProperties = new TableCellProperties
                {
                    TableCellWidth = new TableCellWidth
                    {
                        Width = StringValue.FromString("3825"),
                        Type  = new EnumValue <TableWidthUnitValues> {
                            Value = TableWidthUnitValues.Dxa
                        }
                    },
                    TableCellBorders = new TableCellBorders
                    {
                        TopBorder = new TopBorder
                        {
                            Val = new EnumValue <BorderValues> {
                                Value = BorderValues.Single
                            },
                            Size  = UInt32Value.FromUInt32(0),
                            Space = UInt32Value.FromUInt32(0),
                            Color = StringValue.FromString("FFFFFF")
                        },
                        LeftBorder = new LeftBorder
                        {
                            Val = new EnumValue <BorderValues> {
                                Value = BorderValues.Single
                            },
                            Size  = UInt32Value.FromUInt32(0),
                            Space = UInt32Value.FromUInt32(0),
                            Color = StringValue.FromString("FFFFFF")
                        },
                        BottomBorder = new BottomBorder
                        {
                            Val = new EnumValue <BorderValues> {
                                Value = BorderValues.Single
                            },
                            Size  = UInt32Value.FromUInt32(0),
                            Space = UInt32Value.FromUInt32(0),
                            Color = StringValue.FromString("FFFFFF")
                        },
                        RightBorder = new RightBorder
                        {
                            Val = new EnumValue <BorderValues> {
                                Value = BorderValues.Single
                            },
                            Size  = UInt32Value.FromUInt32(0),
                            Space = UInt32Value.FromUInt32(0),
                            Color = StringValue.FromString("FFFFFF")
                        }
                    },
                    Shading = new Shading
                    {
                        Val = new EnumValue <ShadingPatternValues> {
                            Value = ShadingPatternValues.Clear
                        },
                        Color = StringValue.FromString("auto"),
                        Fill  = StringValue.FromString("0069B4")
                    },
                    TableCellVerticalAlignment = new TableCellVerticalAlignment
                    {
                        Val = new EnumValue <TableVerticalAlignmentValues> {
                            Value = TableVerticalAlignmentValues.Center
                        }
                    }
                }
            };

            tableCell3.AppendChild(new Paragraph(new Run(new DocumentFormat.OpenXml.Wordprocessing.Text(data.TitleArea.Title))
            {
                RunProperties = new DocumentFormat.OpenXml.Wordprocessing.RunProperties
                {
                    Color = new Color {
                        Val = StringValue.FromString("FFFFFF")
                    },
                    FontSize = new FontSize {
                        Val = StringValue.FromString("18")
                    },
                    FontSizeComplexScript = new FontSizeComplexScript {
                        Val = StringValue.FromString("18")
                    }
                }
            })
            {
                ParagraphId            = HexBinaryValue.FromString("63EAFC9C"),
                TextId                 = HexBinaryValue.FromString("77777777"),
                RsidParagraphAddition  = HexBinaryValue.FromString("009B2C1D"),
                RsidRunAdditionDefault = HexBinaryValue.FromString("009E39C2"),
                ParagraphProperties    = new DocumentFormat.OpenXml.Wordprocessing.ParagraphProperties
                {
                    SpacingBetweenLines = new SpacingBetweenLines
                    {
                        Before = StringValue.FromString("550"),
                        After  = StringValue.FromString("800")
                    },
                    Indentation = new Indentation
                    {
                        Left = StringValue.FromString("432")
                    }
                }
            });
            tableCell3.AppendChild(new Paragraph(new Run(new DocumentFormat.OpenXml.Wordprocessing.Text(data.TitleArea.Name))
            {
                RunProperties = new DocumentFormat.OpenXml.Wordprocessing.RunProperties
                {
                    Color = new Color {
                        Val = StringValue.FromString("FFFFFF")
                    },
                    FontSize = new FontSize {
                        Val = StringValue.FromString("33")
                    },
                    FontSizeComplexScript = new FontSizeComplexScript {
                        Val = StringValue.FromString("33")
                    }
                }
            })
            {
                ParagraphId            = HexBinaryValue.FromString("48E9D2B9"),
                TextId                 = HexBinaryValue.FromString("77777777"),
                RsidParagraphAddition  = HexBinaryValue.FromString("009B2C1D"),
                RsidRunAdditionDefault = HexBinaryValue.FromString("0007641E"),
                ParagraphProperties    = new DocumentFormat.OpenXml.Wordprocessing.ParagraphProperties
                {
                    SpacingBetweenLines = new SpacingBetweenLines
                    {
                        After = StringValue.FromString("0")
                    },
                    Indentation = new Indentation
                    {
                        Left = StringValue.FromString("432")
                    }
                }
            });
            tableCell3.AppendChild(new Paragraph(new Run(new DocumentFormat.OpenXml.Wordprocessing.Text(data.TitleArea.Date))
            {
                RunProperties = new DocumentFormat.OpenXml.Wordprocessing.RunProperties
                {
                    Color = new Color {
                        Val = StringValue.FromString("FFFFFF")
                    },
                    FontSize = new FontSize {
                        Val = StringValue.FromString("18")
                    },
                    FontSizeComplexScript = new FontSizeComplexScript {
                        Val = StringValue.FromString("18")
                    }
                }
            })
            {
                ParagraphId            = HexBinaryValue.FromString("4D45EC2E"),
                TextId                 = HexBinaryValue.FromString("77777777"),
                RsidParagraphAddition  = HexBinaryValue.FromString("009B2C1D"),
                RsidRunAdditionDefault = HexBinaryValue.FromString("009E39C2"),
                ParagraphProperties    = new DocumentFormat.OpenXml.Wordprocessing.ParagraphProperties
                {
                    SpacingBetweenLines = new SpacingBetweenLines
                    {
                        Before   = StringValue.FromString("800"),
                        After    = StringValue.FromString("550"),
                        Line     = StringValue.FromString("240"),
                        LineRule = new EnumValue <LineSpacingRuleValues> {
                            Value = LineSpacingRuleValues.Auto
                        }
                    },
                    Indentation = new Indentation
                    {
                        Left = StringValue.FromString("432")
                    }
                }
            });
            tableRow.AppendChild(tableCell3);

            table.AppendChild(tableRow);
        }
        /// <summary>
        /// The write table.
        /// </summary>
        /// <param name="t">The t.</param>
        public void WriteTable(Table t)
        {
            this.body.AppendChild(CreateParagraph(t.GetFullCaption(this.style), TableCaptionId));

            var table = new DocumentFormat.OpenXml.Wordprocessing.Table();

            var tableProperties1 = new TableProperties();
            var tableStyle1 = new TableStyle { Val = "TableGrid" };
            var tableWidth1 = new TableWidth { Width = "0", Type = TableWidthUnitValues.Auto };
            var tableLook1 = new TableLook
                {
                    Val = "04A0",
                    FirstRow = true,
                    LastRow = false,
                    FirstColumn = true,
                    LastColumn = false,
                    NoHorizontalBand = false,
                    NoVerticalBand = true
                };

            tableProperties1.AppendChild(tableStyle1);
            tableProperties1.AppendChild(tableWidth1);
            tableProperties1.AppendChild(tableLook1);

            var tableGrid1 = new TableGrid();
            // ReSharper disable once UnusedVariable
            foreach (var tc in t.Columns)
            {
                // TODO: use tc.Width to set the width of the column
                var gridColumn1 = new GridColumn { Width = "3070" };
                tableGrid1.AppendChild(gridColumn1);
            }

            foreach (var row in t.Rows)
            {
                var tr = new TableRow();

                if (row.IsHeader)
                {
                    var trp = new TableRowProperties();
                    var tableHeader1 = new TableHeader();
                    trp.AppendChild(tableHeader1);
                    tr.AppendChild(trp);
                }

                int j = 0;
                foreach (var c in row.Cells)
                {
                    bool isHeader = row.IsHeader || t.Columns[j++].IsHeader;
                    var cell = new TableCell();
                    var tcp = new TableCellProperties();
                    var borders = new TableCellBorders();
                    borders.AppendChild(
                        new BottomBorder
                            {
                                Val = BorderValues.Single,
                                Size = 4U,
                                Space = 0U,
                                Color = "auto"
                            });
                    borders.AppendChild(
                        new TopBorder
                            {
                                Val = BorderValues.Single,
                                Size = 4U,
                                Space = 0U,
                                Color = "auto"
                            });
                    borders.AppendChild(
                        new LeftBorder
                            {
                                Val = BorderValues.Single,
                                Size = 4U,
                                Space = 0U,
                                Color = "auto"
                            });
                    borders.AppendChild(
                        new RightBorder
                            {
                                Val = BorderValues.Single,
                                Size = 4U,
                                Space = 0U,
                                Color = "auto"
                            });
                    tcp.AppendChild(borders);

                    cell.AppendChild(tcp);
                    string styleId = isHeader ? "TableHeader" : "TableText";
                    cell.AppendChild(CreateParagraph(c.Content, styleId));
                    tr.AppendChild(cell);
                }

                table.AppendChild(tr);
            }

            this.body.AppendChild(table);
        }
        public static void Fill(OpenXmlElement docNode, XmlElement macroListXml, WordprocessingDocument wdDoc)
        {
            /* Форматированный текст для встроенных элементов */
            IEnumerable <Paragraph> paragraphs = docNode.Elements <Paragraph>();

            foreach (Paragraph paragraph in paragraphs)
            {
                IEnumerable <SdtRun> sdtRuns = paragraph.Elements <SdtRun>();
                foreach (SdtRun sdtRun in sdtRuns)
                {
                    // Из SdtProperties взять Tag для идентификации Content Control
                    SdtProperties sdtProperties = sdtRun.GetFirstChild <SdtProperties>();
                    Tag           tag           = sdtProperties.GetFirstChild <Tag>();

                    // Найти в macroListXml Node макропеременной
                    String macroVarValue = FindMacroVar(macroListXml, tag.Val);

                    if (macroVarValue != null)
                    {
                        // Сохранить старый стиль Run
                        SdtContentRun  sdtContentRun = sdtRun.GetFirstChild <SdtContentRun>();
                        OpenXmlElement oldRunProps   = sdtContentRun.GetFirstChild <Run>().GetFirstChild <RunProperties>().CloneNode(true);

                        // Очистить Node Content Control
                        sdtContentRun.RemoveAllChildren();

                        // Создать новую Run Node
                        Run newRun = sdtContentRun.AppendChild(new Run());
                        // Вернуть старый стиль
                        newRun.AppendChild(oldRunProps);

                        // Вставить текст (без переносов строк!!!)
                        newRun.AppendChild(new Text(macroVarValue));
                    }
                }
            }

            /* Получить остальные Content Control */
            IEnumerable <SdtBlock> sdtBlocks = docNode.Elements <SdtBlock>();

            foreach (SdtBlock sdtBlock in sdtBlocks)
            {
                // Получить параметры(SdtProperties) Content Control
                SdtProperties sdtProperties = sdtBlock.GetFirstChild <SdtProperties>();

                // Получить Tag для идентификации Content Control
                Tag tag = sdtProperties.GetFirstChild <Tag>();

                // Получить значение макроперенной из macroListXml
                Console.WriteLine("Tag: " + tag.Val);
                String macroVarValue = FindMacroVar(macroListXml, tag.Val);

                // Если макропеременная есть в MacroListXml
                if (macroVarValue != null)
                {
                    Console.WriteLine("Value: " + macroVarValue);
                    // Получить блок содержимого Content Control
                    SdtContentBlock sdtContentBlock = sdtBlock.GetFirstChild <SdtContentBlock>();

                    /* Форматированный текст для абзацев */
                    if (sdtProperties.GetFirstChild <SdtPlaceholder>() != null && sdtContentBlock.GetFirstChild <Paragraph>() != null)
                    {
                        // Сохранить старый стиль параграфа
                        ParagraphProperties oldParagraphProperties = sdtContentBlock.GetFirstChild <Paragraph>().GetFirstChild <ParagraphProperties>().CloneNode(true) as ParagraphProperties;
                        String oldParagraphPropertiesXml           = oldParagraphProperties.InnerXml;

                        // Очистить ноду с контентом
                        sdtContentBlock.RemoveAllChildren();

                        InsertText(macroVarValue, oldParagraphPropertiesXml, sdtContentBlock);
                    }

                    /* Таблицы */
                    if (sdtProperties.GetFirstChild <SdtPlaceholder>() != null && sdtContentBlock.GetFirstChild <Table>() != null)
                    {
                        // Получить ноду таблицы
                        Table table = sdtContentBlock.GetFirstChild <Table>();

                        // Получить все строки таблицы
                        IEnumerable <TableRow> tableRows = table.Elements <TableRow>();

                        // Получить вторую строку из таблицы
                        TableRow tableRow     = tableRows.ElementAt(1) as TableRow;
                        Type     tableRowType = tableRow.GetType();

                        // Получить все стили столбцов
                        List <String> paragraphCellStyles       = new List <string>();
                        IEnumerable <OpenXmlElement> tableCells = tableRow.Elements <TableCell>();
                        foreach (OpenXmlElement tableCell in tableCells)
                        {
                            String paragraphCellStyleXml = tableCell.GetFirstChild <Paragraph>().GetFirstChild <ParagraphProperties>().InnerXml;
                            paragraphCellStyles.Add(paragraphCellStyleXml);
                        }

                        // Удалить все строки, после первой
                        while (tableRows.Count <TableRow>() > 1)
                        {
                            TableRow lastTableRows = tableRows.Last <TableRow>();
                            lastTableRows.Remove();
                        }

                        // Удалить последний элемент, если это не TableRow
                        OpenXmlElement lastNode = table.LastChild;
                        if (lastNode.GetType() != tableRowType)
                        {
                            lastNode.Remove();
                        }

                        string[] rowDelimiters    = new string[] { "|||" };
                        string[] columnDelimiters = new string[] { "^^^" };

                        // Получить массив строк из макропеременной
                        String[] rowsXml = macroVarValue.Split(rowDelimiters, StringSplitOptions.None);
                        int      i       = 0;
                        while (i < rowsXml.Length)
                        {
                            // Получить строку
                            String rowXml = rowsXml[i];

                            // Добавить ноду строки таблицы
                            TableRow newTableRow = table.AppendChild(new TableRow());

                            // Получить из строки массив ячеек
                            String[] cellsXml = rowXml.Split(columnDelimiters, StringSplitOptions.None);

                            int j = 0;
                            while (j < cellsXml.Length)
                            {
                                // Получить ячейку
                                String cellXml = cellsXml[j];

                                // Убрать символ CRLF в конце строки
                                cellXml = cellXml.TrimEnd(new char[] { '\n', '\r' });

                                // Добавить ноду ячейку в строку таблицы
                                TableCell newTableCell = newTableRow.AppendChild(new TableCell());

                                // Вставить текст
                                InsertText(cellXml, paragraphCellStyles[j], newTableCell);

                                j++;
                            }

                            i++;
                        }
                    }

                    /* Картинки */
                    if (sdtProperties.GetFirstChild <SdtContentPicture>() != null)
                    {
                        // Получить путь к файлу
                        String imageFilePath = macroVarValue;

                        // Получить расширение файла
                        String        extension = System.IO.Path.GetExtension(imageFilePath).ToLower();
                        ImagePartType imagePartType;
                        switch (extension)
                        {
                        case "jpeg":
                            imagePartType = ImagePartType.Jpeg;
                            break;

                        case "jpg":
                            imagePartType = ImagePartType.Jpeg;
                            break;

                        case "png":
                            imagePartType = ImagePartType.Png;
                            break;

                        case "bmp":
                            imagePartType = ImagePartType.Bmp;
                            break;

                        case "gif":
                            imagePartType = ImagePartType.Gif;
                            break;

                        default:
                            imagePartType = ImagePartType.Jpeg;
                            break;
                        }
                        ;

                        // Добавить ImagePart в документ
                        ImagePart imagePart = wdDoc.MainDocumentPart.AddImagePart(imagePartType);

                        // Получить картинку
                        using (FileStream stream = new FileStream(imageFilePath, FileMode.Open))
                        {
                            imagePart.FeedData(stream);
                        }

                        // Вычислить width и height
                        Bitmap    img         = new Bitmap(imageFilePath);
                        var       widthPx     = img.Width;
                        var       heightPx    = img.Height;
                        var       horzRezDpi  = img.HorizontalResolution;
                        var       vertRezDpi  = img.VerticalResolution;
                        const int emusPerInch = 914400;
                        const int emusPerCm   = 360000;
                        var       widthEmus   = (long)(widthPx / horzRezDpi * emusPerInch);
                        var       heightEmus  = (long)(heightPx / vertRezDpi * emusPerInch);

                        // Получить ID ImagePart
                        string relationShipId = wdDoc.MainDocumentPart.GetIdOfPart(imagePart);

                        Paragraph   paragraph   = sdtContentBlock.GetFirstChild <Paragraph>();
                        Run         run         = paragraph.GetFirstChild <Run>();
                        Drawing     drawing     = run.GetFirstChild <Drawing>();
                        Inline      inline      = drawing.GetFirstChild <Inline>();
                        Graphic     graphic     = inline.GetFirstChild <Graphic>();
                        GraphicData graphicData = graphic.GetFirstChild <GraphicData>();
                        Picture     pic         = graphicData.GetFirstChild <Picture>();
                        BlipFill    blipFill    = pic.GetFirstChild <BlipFill>();
                        Blip        blip        = blipFill.GetFirstChild <Blip>();

                        string prefix       = "r";
                        string localName    = "embed";
                        string namespaceUri = @"http://schemas.openxmlformats.org/officeDocument/2006/relationships";

                        OpenXmlAttribute oldEmbedAttribute = blip.GetAttribute("embed", namespaceUri);

                        IList <OpenXmlAttribute> attributes = blip.GetAttributes();

                        if (oldEmbedAttribute != null)
                        {
                            attributes.Remove(oldEmbedAttribute);
                        }

                        // Удалить хз что, выявлено практическим путем
                        blipFill.RemoveAllChildren <SourceRectangle>();

                        // Установить новую картинку
                        blip.SetAttribute(new OpenXmlAttribute(prefix, localName, namespaceUri, relationShipId));
                        blip.SetAttribute(new OpenXmlAttribute("cstate", "", "print"));

                        // Подогнать размеры
                        Extent extent = inline.GetFirstChild <Extent>();

                        OpenXmlAttribute oldCxExtent = extent.GetAttribute("cx", "");
                        if (oldCxExtent != null)
                        {
                            var maxWidthEmus = long.Parse(oldCxExtent.Value);
                            if (widthEmus > maxWidthEmus)
                            {
                                var ratio = (heightEmus * 1.0m) / widthEmus;
                                widthEmus  = maxWidthEmus;
                                heightEmus = (long)(widthEmus * ratio);
                            }

                            extent.GetAttributes().Remove(oldCxExtent);
                        }

                        OpenXmlAttribute oldCyExtent = extent.GetAttribute("cy", "");
                        if (oldCyExtent != null)
                        {
                            extent.GetAttributes().Remove(oldCyExtent);
                        }

                        extent.SetAttribute(new OpenXmlAttribute("cx", "", widthEmus.ToString()));
                        extent.SetAttribute(new OpenXmlAttribute("cy", "", heightEmus.ToString()));

                        ShapeProperties shapeProperties = pic.GetFirstChild <ShapeProperties>();
                        Transform2D     transform2D     = shapeProperties.GetFirstChild <Transform2D>();
                        Extents         extents         = transform2D.GetFirstChild <Extents>();

                        OpenXmlAttribute oldCxExtents = extents.GetAttribute("cx", "");
                        if (oldCxExtents != null)
                        {
                            extents.GetAttributes().Remove(oldCxExtents);
                        }

                        OpenXmlAttribute oldCyExtents = extents.GetAttribute("cy", "");
                        if (oldCyExtents != null)
                        {
                            extents.GetAttributes().Remove(oldCyExtents);
                        }

                        extents.SetAttribute(new OpenXmlAttribute("cx", "", widthEmus.ToString()));
                        extents.SetAttribute(new OpenXmlAttribute("cy", "", heightEmus.ToString()));

                        // Удалить placeholder
                        ShowingPlaceholder showingPlaceholder = sdtProperties.GetFirstChild <ShowingPlaceholder>();
                        if (showingPlaceholder != null)
                        {
                            sdtProperties.RemoveChild <ShowingPlaceholder>(showingPlaceholder);
                        }
                    }

                    /* Повторяющийся раздел */
                    if (sdtProperties.GetFirstChild <SdtRepeatedSection>() != null)
                    {
                        // Представить repeatedSection как новый xml документ (сделать корнем)
                        XmlDocument repeatedSectionXml = new XmlDocument();
                        repeatedSectionXml.LoadXml(macroVarValue);

                        // Получить корневой элемент repeatedSection
                        XmlElement rootRepeatedSectionXml = repeatedSectionXml.DocumentElement;

                        // Получить количество repeatedSectionItem
                        XmlNodeList repeatedSectionItems = rootRepeatedSectionXml.SelectNodes("repeatedSectionItem");
                        int         repeatedItemCount    = repeatedSectionItems.Count;

                        Console.WriteLine("Количество repeatedSectionItem: " + repeatedItemCount);

                        /* Блок клонирования ноды повтор. раздела до нужного количества */
                        for (int i = 0; i < repeatedItemCount; i++)
                        {
                            XmlElement macroListRepeatedSectionItem = rootRepeatedSectionXml.SelectSingleNode(String.Format(@"repeatedSectionItem[@id=""{0}""]", i)) as XmlElement;
                            Console.WriteLine("Item " + i + ": " + macroListRepeatedSectionItem.OuterXml);

                            SdtContentBlock sdtContentBlockRepeatedSectionItem = sdtContentBlock.Elements <SdtBlock>().Last <SdtBlock>().GetFirstChild <SdtContentBlock>();

                            Fill(sdtContentBlockRepeatedSectionItem, macroListRepeatedSectionItem, wdDoc);

                            if (i + 1 < repeatedItemCount)
                            {
                                SdtBlock clonedRepeatedSectionItem = sdtContentBlock.GetFirstChild <SdtBlock>().Clone() as SdtBlock;
                                sdtContentBlock.AppendChild <SdtBlock>(clonedRepeatedSectionItem);
                            }
                        }
                        /**/

                        //Fill(sdtContentBlock, macroListRepeatedSection, wdDoc);
                    }
                }

                Console.WriteLine();
            }
        }