Example #1
0
        private static RunProperties AddRunProperties(string textFont, string textSize, bool bold, bool italic)
        {
            var runProperties = new RunProperties();
            var font          = new RunFonts {
                Ascii = textFont
            };
            var size = new FontSize {
                Val = new StringValue(textSize)
            };

            runProperties.AppendChild(font);
            runProperties.AppendChild(size);

            if (bold)
            {
                runProperties.AppendChild(new Bold());
            }

            if (italic)
            {
                runProperties.AppendChild(new Italic());
            }

            return(runProperties);
        }
Example #2
0
        /**public void getFooterWithPageNumber()
         * {
         *  foreach (Section wordSection in this.adoc.Sections)
         *  {
         *      Range footerRange = wordSection.Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
         *      footerRange.InlineShapes.AddHorizontalLineStandard();
         *      footerRange.Font.ColorIndex = WdColorIndex.wdDarkRed;
         *      footerRange.Font.Size = 10;
         *      footerRange.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
         *      adoc.Sections[1].Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].PageNumbers.Add();
         *  }
         * }**/

        public void generateCoverPage(string data)
        {
            body.Append(new Paragraph(new Run(new Break())));
            body.Append(new Paragraph(new Run(new Break())));
            body.Append(new Paragraph(new Run(new Break())));
            body.Append(new Paragraph(new Run(new Break())));

            //heading
            Paragraph           heading = new Paragraph();
            ParagraphProperties hp      = new ParagraphProperties();

            hp.Justification = new Justification()
            {
                Val = JustificationValues.Center
            };
            heading.Append(hp);
            Run           r             = new Run();
            RunProperties runProperties = r.AppendChild(new RunProperties());
            Bold          bold          = new Bold();

            bold.Val = OnOffValue.FromBoolean(true);
            FontSize size = new FontSize();

            size.Val = "60";
            runProperties.AppendChild(bold);
            runProperties.AppendChild(size);
            Text t = new Text(data);

            r.Append(t);
            heading.Append(r);
            body.Append(heading);

            //subheading
            Paragraph           subheading = new Paragraph();
            ParagraphProperties shp        = new ParagraphProperties();

            shp.Justification = new Justification()
            {
                Val = JustificationValues.Center
            };
            subheading.Append(shp);
            Run           rs           = new Run();
            RunProperties rhProperties = rs.AppendChild(new RunProperties());
            Bold          bs           = new Bold();

            bs.Val = OnOffValue.FromBoolean(true);
            FontSize sh = new FontSize();

            sh.Val = "40";
            rhProperties.AppendChild(bs);
            rhProperties.AppendChild(sh);
            Text subhead = new Text("BUSINESS PLAN");

            rs.Append(subhead);
            subheading.Append(rs);
            body.Append(subheading);
            addPageBreak();
        }
Example #3
0
        public void AddText(String text = "", uint fontSize = 12, bool bold = false, bool italic = false)
        {
            Wp.Run           _r  = new Wp.Run();
            Wp.RunProperties _rp = new Wp.RunProperties();
            Wp.RunFonts      _rf = new Wp.RunFonts()
            {
                Ascii         = "Calibri",
                HighAnsi      = "Calibri",
                EastAsia      = "Calibri",
                ComplexScript = "Calibri"
            };
            Wp.FontSize _fs = new Wp.FontSize()
            {
                Val = fontSize.ToString()
            };
            Wp.Languages _l = new Wp.Languages()
            {
                Bidi = "en-us"
            };

            _rp.Append(_rf);
            _rp.Append(_fs);
            _rp.Append(_l);

            if (italic)
            {
                _rp.Append(new Wp.Italic());
            }

            if (bold)
            {
                _rp.Append(new Wp.Bold());
            }

            Wp.Text _t = new Wp.Text();
            _t.Text = text;

            _r.Append(_rp);
            _r.Append(_t);

            this._Paragraph.Append(_r);
        }
Example #4
0
        async Task ReadOpenXml()
        {
            Stopwatch sw = Stopwatch.StartNew();

            _app.ScreenUpdating = false;

            Interop.Range range = _app.ActiveDocument.Range();

            string tmpFile = new OpenXmlHelper().CopyToFile(range);

            _app.ScreenUpdating = true;

            int i = 0;
            await Task.Run(() => {
                using (WordprocessingDocument doc = WordprocessingDocument.Open(tmpFile, true)) {
                    IEnumerable <OpenXml.Paragraph> paragraphs = doc.MainDocumentPart
                                                                 .Document
                                                                 .Body
                                                                 .Elements <OpenXml.Paragraph>();
                    foreach (OpenXml.Paragraph paragraph in paragraphs)
                    {
                        foreach (OpenXml.Run run in paragraph.Elements <OpenXml.Run>())
                        {
                            OpenXml.RunProperties properties = run.RunProperties;
                            string text               = run.Elements <OpenXml.Text>().FirstOrDefault()?.Text;
                            OpenXml.Bold bold         = properties?.Bold;
                            OpenXml.Italic italic     = properties?.Italic;
                            OpenXml.Color color       = properties?.Color;
                            StringValue backColor     = properties?.Shading.Fill;
                            OpenXml.FontSize fontSize = properties?.FontSize;
                            i++;
                        }
                    }
                }
            });

            File.Delete(tmpFile);

            sw.Stop();
            MessageBox.Show(sw.Elapsed.ToString(), $"OpenXML: read {i}");
        }
    private Run GetTableCellRun(TableRow tr, int width, int gridSpan, JustificationValues justification, int fontSize, bool globalTC)
    {
        TableCell tcRun = new TableCell();
        TableCellProperties properties = new TableCellProperties();
        if(width > 0)
            properties.Append(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = StringValue.FromString(width.ToString()) });

        if (gridSpan > 0)
            properties.Append(new GridSpan() { Val = gridSpan });

        tcRun.Append(properties);
        
        paragraph = new Paragraph();
        ParagraphProperties paraProperties = new ParagraphProperties();
        paraProperties.Append(new Justification() { Val = justification });
        paraProperties.Append(new SpacingBetweenLines() { After = "10", Line = "240", LineRule = LineSpacingRuleValues.Auto });

        paragraph.Append(paraProperties);
        Run run = new Run();

        if (fontSize != 0)
        {
            RunProperties runProperties = new RunProperties();
            FontSize size = new FontSize();
            size.Val = StringValue.FromString(fontSize.ToString());
            runProperties.Append(size);
            run.Append(runProperties);
        }

        paragraph.Append(run);
        tcRun.Append(paragraph);
        tr.Append(tcRun);

        //if (globalTC)
        //    tcLetter = tcRun;
        firstLine = false;
        return run;
    }
Example #6
0
        public Wordprocessing.Body insertinform()
        {
            Wordprocessing.Body body = new Wordprocessing.Body();
            //Параграф1
            Wordprocessing.Paragraph paragraph1 = new Wordprocessing.Paragraph();
            Wordprocessing.ParagraphProperties paragraphProperties1 = new Wordprocessing.ParagraphProperties();
            Wordprocessing.SpacingBetweenLines spacingBetweenLines1 = new Wordprocessing.SpacingBetweenLines() { After = "0" };
            Wordprocessing.Justification justification1 = new Wordprocessing.Justification() { Val = Wordprocessing.JustificationValues.Center };
            paragraphProperties1.Append(spacingBetweenLines1);
            paragraphProperties1.Append(justification1);
            Wordprocessing.Run run1 = new Wordprocessing.Run();
            Wordprocessing.RunProperties runProperties1 = new Wordprocessing.RunProperties();
            Wordprocessing.RunFonts runFonts2 = new Wordprocessing.RunFonts() { Ascii = "Times New Roman", HighAnsi = "Times New Roman", ComplexScript = "Times New Roman" };
            Wordprocessing.Bold bold2 = new Wordprocessing.Bold();
            Wordprocessing.FontSize fontSize2 = new Wordprocessing.FontSize() { Val = "24" };
            runProperties1.Append(runFonts2);
            runProperties1.Append(bold2);
            runProperties1.Append(fontSize2);
            Wordprocessing.Text text1 = new Wordprocessing.Text();
            text1.Text = "ФГБОУВПО \"ПЕРМСКИЙ ГОСУДАРСТВЕННЫЙ НАЦИОНАЛЬНЫЙ ИССЛЕДОВАТЕЛЬСКИЙ УНИВЕРСИТЕТ\"";
            run1.Append(runProperties1);
            run1.Append(text1);
            paragraph1.Append(paragraphProperties1);
            paragraph1.Append(run1);

            //Параграф2
            Wordprocessing.Paragraph paragraph2 = new Wordprocessing.Paragraph();

            Wordprocessing.ParagraphProperties paragraphProperties2 = new Wordprocessing.ParagraphProperties();
            Wordprocessing.SpacingBetweenLines spacingBetweenLines2 = new Wordprocessing.SpacingBetweenLines() { After = "0" };
            Wordprocessing.Justification justification2 = new Wordprocessing.Justification() { Val = Wordprocessing.JustificationValues.Center };
            paragraphProperties2.Append(spacingBetweenLines2);
            paragraphProperties2.Append(justification2);
            Wordprocessing.Run run2 = new Wordprocessing.Run();

            Wordprocessing.RunProperties runProperties2 = new Wordprocessing.RunProperties();
            Wordprocessing.RunFonts runFonts4 = new Wordprocessing.RunFonts() { Ascii = "Times New Roman", HighAnsi = "Times New Roman", ComplexScript = "Times New Roman" };
            Wordprocessing.FontSize fontSize4 = new Wordprocessing.FontSize() { Val = "24" };

            runProperties2.Append(runFonts4);
            runProperties2.Append(fontSize4);
            Wordprocessing.Text text2 = new Wordprocessing.Text();
            text2.Text = "Механико-математический факультет ";

            run2.Append(runProperties2);
            run2.Append(text2);

            Wordprocessing.Run run3 = new Wordprocessing.Run();

            Wordprocessing.RunProperties runProperties3 = new Wordprocessing.RunProperties();
            Wordprocessing.RunFonts runFonts5 = new Wordprocessing.RunFonts() { Ascii = "Times New Roman", HighAnsi = "Times New Roman", ComplexScript = "Times New Roman" };
            Wordprocessing.FontSize fontSize5 = new Wordprocessing.FontSize() { Val = "24" };
            runProperties3.Append(runFonts5);
            runProperties3.Append(fontSize5);
            Wordprocessing.Break break1 = new Wordprocessing.Break();
            Wordprocessing.Text text3 = new Wordprocessing.Text();
            text3.Text = "очная форма обучения";

            run3.Append(runProperties3);
            run3.Append(break1);
            run3.Append(text3);

            paragraph2.Append(paragraphProperties2);
            paragraph2.Append(run2);
            paragraph2.Append(run3);

            //Параграф2
            Wordprocessing.Paragraph paragraph3 = new Wordprocessing.Paragraph() { RsidParagraphAddition = "004D49E1", RsidParagraphProperties = "004D49E1", RsidRunAdditionDefault = "004D49E1" };

            Wordprocessing.ParagraphProperties paragraphProperties3 = new Wordprocessing.ParagraphProperties();
            Wordprocessing.SpacingBetweenLines spacingBetweenLines3 = new Wordprocessing.SpacingBetweenLines() { After = "0" };
            Wordprocessing.Justification justification3 = new Wordprocessing.Justification() { Val = Wordprocessing.JustificationValues.Center };
            paragraphProperties3.Append(spacingBetweenLines3);
            paragraphProperties3.Append(justification3);
            Wordprocessing.Run run4 = new Wordprocessing.Run();

            Wordprocessing.RunProperties runProperties4 = new Wordprocessing.RunProperties();
            Wordprocessing.RunFonts runFonts7 = new Wordprocessing.RunFonts() { Ascii = "Times New Roman", HighAnsi = "Times New Roman", ComplexScript = "Times New Roman" };
            Wordprocessing.Bold bold4 = new Wordprocessing.Bold();

            runProperties4.Append(runFonts7);
            runProperties4.Append(bold4);
            Wordprocessing.Text text4 = new Wordprocessing.Text();
            text4.Text = "ЭКЗАМЕНАЦИОННАЯ ВЕДОМОСТЬ";
            run4.Append(runProperties4);
            run4.Append(text4);

            Wordprocessing.Run run5 = new Wordprocessing.Run();
            Wordprocessing.Break break2 = new Wordprocessing.Break();
            run5.Append(break2);

            paragraph3.Append(paragraphProperties3);
            paragraph3.Append(run4);
            paragraph3.Append(run5);

            body.Append(paragraph1);
            body.Append(paragraph2);
            body.Append(paragraph3);
            return body;
        }