コード例 #1
0
ファイル: EditTestForm.cs プロジェクト: PashaEagle/year_paper
        private void bExport_Click(object sender, EventArgs e)
        {
            SaveFileDialog dialog = new SaveFileDialog();

            dialog.Title      = "Створення файлу з питаннями";
            dialog.FileName   = "Питання";
            dialog.DefaultExt = "docx";
            dialog.Filter     = "DOCX |*.docx";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                var    doc           = DocX.Create(dialog.FileName);
                string title         = "Питання";
                string textParagraph = "";

                Xceed.Words.NET.Formatting titleFormat = new Xceed.Words.NET.Formatting();
                titleFormat.Size      = 20;
                titleFormat.Position  = 40;
                titleFormat.FontColor = System.Drawing.Color.Navy;
                titleFormat.Italic    = true;
                titleFormat.Bold      = true;


                Xceed.Words.NET.Formatting textParagraphFormat = new Xceed.Words.NET.Formatting();
                textParagraphFormat.Size = 10;

                foreach (TestQuestion temp in Global.currentTestQuestions)
                {
                    textParagraph += temp.question + Environment.NewLine + Environment.NewLine;
                }

                Paragraph paragraphTitle = doc.InsertParagraph(title, false, titleFormat);
                paragraphTitle.Alignment = Alignment.center;
                doc.InsertParagraph(textParagraph, false, textParagraphFormat);

                doc.Save();

                MessageBox.Show("Файл з питаннями збережено");
            }
            назадToolStripMenuItem.Enabled             = true;
            редагуватиНаявнийToolStripMenuItem.Enabled = true;
            створитиНовийToolStripMenuItem.Enabled     = true;
        }
コード例 #2
0
        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            SaveFileDialog dialog = new SaveFileDialog();

            dialog.Title      = "Створення файлу з результатами";
            dialog.FileName   = "Результати";
            dialog.DefaultExt = "docx";
            dialog.Filter     = "DOCX |*.docx";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                var    doc           = DocX.Create(dialog.FileName);
                string title         = "Результати";
                string textParagraph = "";

                Xceed.Words.NET.Formatting titleFormat = new Xceed.Words.NET.Formatting();
                titleFormat.Size      = 26;
                titleFormat.Position  = 40;
                titleFormat.FontColor = System.Drawing.Color.Navy;
                titleFormat.Italic    = true;
                titleFormat.Bold      = true;


                Xceed.Words.NET.Formatting textParagraphFormat = new Xceed.Words.NET.Formatting();
                textParagraphFormat.Size = 10;

                foreach (TestParticipant temp in Global.participants)
                {
                    textParagraph += "Імя: " + temp.name + ";\t";
                    textParagraph += "Група: " + temp.group + ";\t";
                    textParagraph += "Дата: " + temp.date + ";\t";
                    textParagraph += "Результат: " + temp.result + Environment.NewLine + Environment.NewLine;
                }

                Paragraph paragraphTitle = doc.InsertParagraph(title, false, titleFormat);
                paragraphTitle.Alignment = Alignment.center;
                doc.InsertParagraph(textParagraph, false, textParagraphFormat);

                doc.Save();

                MessageBox.Show("Файл з результатами збережено");
            }
        }
コード例 #3
0
        public virtual Paragraph InsertParagraphAfterSelf(string text, bool trackChanges, Formatting formatting)
        {
            XElement newParagraph = new XElement
                                    (
                XName.Get("p", DocX.w.NamespaceName), new XElement(XName.Get("pPr", DocX.w.NamespaceName)), HelperFunctions.FormatInput(text, formatting.Xml)
                                    );

            if (trackChanges)
            {
                newParagraph = Paragraph.CreateEdit(EditType.ins, DateTime.Now, newParagraph);
            }

            Xml.AddAfterSelf(newParagraph);
            XElement newlyInserted = Xml.ElementsAfterSelf().First();

            Paragraph p = new Paragraph(Document, newlyInserted, -1);

            return(p);
        }
コード例 #4
0
        public int CompareTo(object obj)
        {
            Formatting other = ( Formatting )obj;

            if (other._hidden != _hidden)
            {
                return(-1);
            }

            if (other._bold != _bold)
            {
                return(-1);
            }

            if (other._italic != _italic)
            {
                return(-1);
            }

            if (other._strikethrough != _strikethrough)
            {
                return(-1);
            }

            if (other._script != _script)
            {
                return(-1);
            }

            if (other._highlight != _highlight)
            {
                return(-1);
            }

            if (other._shading != _shading)
            {
                return(-1);
            }

            if (other._border != _border)
            {
                return(-1);
            }

            if (other._size != _size)
            {
                return(-1);
            }

            if (other._fontColor != _fontColor)
            {
                return(-1);
            }

            if (other._underlineColor != _underlineColor)
            {
                return(-1);
            }

            if (other._underlineStyle != _underlineStyle)
            {
                return(-1);
            }

            if (other._misc != _misc)
            {
                return(-1);
            }

            if (other._capsStyle != _capsStyle)
            {
                return(-1);
            }

            if (other._fontFamily != _fontFamily)
            {
                return(-1);
            }

            if (other._percentageScale != _percentageScale)
            {
                return(-1);
            }

            if (other._kerning != _kerning)
            {
                return(-1);
            }

            if (other._position != _position)
            {
                return(-1);
            }

            if (other._spacing != _spacing)
            {
                return(-1);
            }

            if (other._styleName != _styleName)
            {
                return(-1);
            }

            if (!other._language.Equals(_language))
            {
                return(-1);
            }

            return(0);
        }
コード例 #5
0
        public static Formatting Parse(XElement rPr, Formatting formatting = null)
        {
            if (formatting == null)
            {
                formatting = new Formatting();
            }

            if (rPr == null)
            {
                return(formatting);
            }

            // Build up the Formatting object.
            foreach (XElement option in rPr.Elements())
            {
                switch (option.Name.LocalName)
                {
                case "lang":
                    formatting.Language = new CultureInfo(option.GetAttribute(XName.Get("val", DocX.w.NamespaceName), null) ?? option.GetAttribute(XName.Get("eastAsia", DocX.w.NamespaceName), null) ?? option.GetAttribute(XName.Get("bidi", DocX.w.NamespaceName)));
                    break;

                case "spacing":
                    formatting.Spacing = Double.Parse(option.GetAttribute(XName.Get("val", DocX.w.NamespaceName))) / 20.0;
                    break;

                case "position":
                    formatting.Position = Int32.Parse(option.GetAttribute(XName.Get("val", DocX.w.NamespaceName))) / 2;
                    break;

                case "kern":
                    formatting.Kerning = Int32.Parse(option.GetAttribute(XName.Get("val", DocX.w.NamespaceName))) / 2;
                    break;

                case "w":
                    formatting.PercentageScale = Int32.Parse(option.GetAttribute(XName.Get("val", DocX.w.NamespaceName)));
                    break;

                case "sz":
                    formatting.Size = Double.Parse(option.GetAttribute(XName.Get("val", DocX.w.NamespaceName))) / 2;
                    break;

                case "rFonts":
                    var fontName = option.GetAttribute(XName.Get("ascii", DocX.w.NamespaceName), null)
                                   ?? option.GetAttribute(XName.Get("hAnsi", DocX.w.NamespaceName), null)
                                   ?? option.GetAttribute(XName.Get("cs", DocX.w.NamespaceName), null)
                                   ?? option.GetAttribute(XName.Get("hint", DocX.w.NamespaceName), null)
                                   ?? option.GetAttribute(XName.Get("eastAsia", DocX.w.NamespaceName), null);

                    formatting.FontFamily = (fontName != null)
                                    ? new Font(fontName)
                                    : (formatting.FontFamily == null) ?
                                            new Font("Calibri") : formatting.FontFamily;
                    break;

                case "color":
                    try
                    {
                        var color = option.GetAttribute(XName.Get("val", DocX.w.NamespaceName));
                        formatting.FontColor = (color == "auto") ? Color.Black : ColorTranslator.FromHtml(string.Format("#{0}", color));
                    }
                    catch (Exception)
                    {
                        // ignore
                    }
                    break;

                case "vanish":
                    formatting._hidden = true;
                    break;

                case "b":
                    formatting.Bold = option.GetAttribute(XName.Get("val", DocX.w.NamespaceName)) != "0";
                    break;

                case "i":
                    formatting.Italic = true;
                    break;

                case "highlight":
                    switch (option.GetAttribute(XName.Get("val", DocX.w.NamespaceName)))
                    {
                    case "yellow":
                        formatting.Highlight = NET.Highlight.yellow;
                        break;

                    case "green":
                        formatting.Highlight = NET.Highlight.green;
                        break;

                    case "cyan":
                        formatting.Highlight = NET.Highlight.cyan;
                        break;

                    case "magenta":
                        formatting.Highlight = NET.Highlight.magenta;
                        break;

                    case "blue":
                        formatting.Highlight = NET.Highlight.blue;
                        break;

                    case "red":
                        formatting.Highlight = NET.Highlight.red;
                        break;

                    case "darkBlue":
                        formatting.Highlight = NET.Highlight.darkBlue;
                        break;

                    case "darkCyan":
                        formatting.Highlight = NET.Highlight.darkCyan;
                        break;

                    case "darkGreen":
                        formatting.Highlight = NET.Highlight.darkGreen;
                        break;

                    case "darkMagenta":
                        formatting.Highlight = NET.Highlight.darkMagenta;
                        break;

                    case "darkRed":
                        formatting.Highlight = NET.Highlight.darkRed;
                        break;

                    case "darkYellow":
                        formatting.Highlight = NET.Highlight.darkYellow;
                        break;

                    case "darkGray":
                        formatting.Highlight = NET.Highlight.darkGray;
                        break;

                    case "lightGray":
                        formatting.Highlight = NET.Highlight.lightGray;
                        break;

                    case "black":
                        formatting.Highlight = NET.Highlight.black;
                        break;
                    }
                    break;

                case "strike":
                    formatting.StrikeThrough = NET.StrikeThrough.strike;
                    break;

                case "dstrike":
                    formatting.StrikeThrough = NET.StrikeThrough.doubleStrike;
                    break;

                case "u":
                    formatting.UnderlineStyle = HelperFunctions.GetUnderlineStyle(option.GetAttribute(XName.Get("val", DocX.w.NamespaceName)));
                    try
                    {
                        var color = option.GetAttribute(XName.Get("color", DocX.w.NamespaceName));
                        if (!string.IsNullOrEmpty(color))
                        {
                            formatting.UnderlineColor = System.Drawing.ColorTranslator.FromHtml(string.Format("#{0}", color));
                        }
                    }
                    catch (Exception)
                    {
                        // ignore
                    }
                    break;

                case "vertAlign": //script
                    var script = option.GetAttribute(XName.Get("val", DocX.w.NamespaceName), null);
                    formatting.Script = (Script)Enum.Parse(typeof(Script), script);
                    break;

                case "caps":
                    formatting.CapsStyle = NET.CapsStyle.caps;
                    break;

                case "smallCaps":
                    formatting.CapsStyle = NET.CapsStyle.smallCaps;
                    break;

                case "shd":
                    var fill = option.GetAttribute(XName.Get("fill", DocX.w.NamespaceName));
                    if (!string.IsNullOrEmpty(fill))
                    {
                        formatting.Shading = System.Drawing.ColorTranslator.FromHtml(string.Format("#{0}", fill));
                    }
                    break;

                case "bdr":
                    var borderSize  = BorderSize.one;
                    var borderColor = Color.Black;
                    var borderSpace = 0;
                    var borderStyle = BorderStyle.Tcbs_single;

                    var bdrColor = option.Attribute(XName.Get("color", DocX.w.NamespaceName));
                    if ((bdrColor != null) && (bdrColor.Value != "auto"))
                    {
                        borderColor = System.Drawing.ColorTranslator.FromHtml(string.Format("#{0}", bdrColor.Value));
                    }
                    var size = option.Attribute(XName.Get("sz", DocX.w.NamespaceName));
                    if (size != null)
                    {
                        var sizeValue = System.Convert.ToSingle(size.Value);
                        if (sizeValue == 2)
                        {
                            borderSize = BorderSize.one;
                        }
                        else if (sizeValue == 4)
                        {
                            borderSize = BorderSize.two;
                        }
                        else if (sizeValue == 6)
                        {
                            borderSize = BorderSize.three;
                        }
                        else if (sizeValue == 8)
                        {
                            borderSize = BorderSize.four;
                        }
                        else if (sizeValue == 12)
                        {
                            borderSize = BorderSize.five;
                        }
                        else if (sizeValue == 18)
                        {
                            borderSize = BorderSize.six;
                        }
                        else if (sizeValue == 24)
                        {
                            borderSize = BorderSize.seven;
                        }
                        else if (sizeValue == 36)
                        {
                            borderSize = BorderSize.eight;
                        }
                        else if (sizeValue == 48)
                        {
                            borderSize = BorderSize.nine;
                        }
                        else
                        {
                            borderSize = BorderSize.one;
                        }
                    }
                    var space = option.Attribute(XName.Get("space", DocX.w.NamespaceName));
                    if (space != null)
                    {
                        borderSpace = System.Convert.ToInt32(space.Value);
                    }
                    var bdrStyle = option.Attribute(XName.Get("val", DocX.w.NamespaceName));
                    if (bdrStyle != null)
                    {
                        borderStyle = (BorderStyle)Enum.Parse(typeof(BorderStyle), "Tcbs_" + bdrStyle.Value);
                    }

                    formatting.Border = new Border(borderStyle, borderSize, borderSpace, borderColor);
                    break;

                case "rStyle":
                    var style = option.GetAttribute(XName.Get("val", DocX.w.NamespaceName), null);
                    formatting.StyleName = style;
                    break;

                default:
                    break;
                }
            }

            return(formatting);
        }
コード例 #6
0
ファイル: Container.cs プロジェクト: ChuckByram/DocX
        public virtual Paragraph InsertParagraph(int index, string text, bool trackChanges, Formatting formatting)
        {
            var newParagraph = new Paragraph(this.Document, new XElement(DocX.w + "p"), index);

            newParagraph.InsertText(0, text, trackChanges, formatting);

            var firstPar = HelperFunctions.GetFirstParagraphEffectedByInsert(Document, index);

            if (firstPar != null)
            {
                var splitIndex = index - firstPar._startIndex;
                if (splitIndex > 0)
                {
                    var splitParagraph = HelperFunctions.SplitParagraph(firstPar, splitIndex);
                    firstPar.Xml.ReplaceWith(splitParagraph[0], newParagraph.Xml, splitParagraph[1]);
                }
                else
                {
                    firstPar.Xml.ReplaceWith(newParagraph.Xml, firstPar.Xml);
                }
            }
            else
            {
                this.Xml.Add(newParagraph);
            }

            this.SetParentContainer(newParagraph);
            return(newParagraph);
        }