Esempio n. 1
0
        public static Formatting Parse(XElement rPr)
        {
            Formatting formatting = new 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.Position = 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;

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


                case "rFonts":
                    formatting.FontFamily =
                        new Font(
                            option.GetAttribute(XName.Get("cs", DocX.w.NamespaceName), null) ??
                            option.GetAttribute(XName.Get("ascii", DocX.w.NamespaceName), null) ??
                            option.GetAttribute(XName.Get("hAnsi", DocX.w.NamespaceName), null) ??
                            option.GetAttribute(XName.Get("eastAsia", DocX.w.NamespaceName)));
                    break;

                case "color":
                    try
                    {
                        string color = option.GetAttribute(XName.Get("val", DocX.w.NamespaceName));
                        formatting.FontColor = System.Drawing.ColorTranslator.FromHtml(string.Format("#{0}", color));
                    }
                    catch { }
                    break;

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

                case "b": formatting.Bold = true; break;

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

                case "u": formatting.UnderlineStyle = HelperFunctions.GetUnderlineStyle(option.GetAttribute(XName.Get("val", DocX.w.NamespaceName)));
                    break;

                default: break;
                }
            }


            return(formatting);
        }
Esempio n. 2
0
        public virtual Paragraph InsertParagraph(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 = HelperFunctions.CreateEdit(EditType.ins, DateTime.Now, newParagraph);
            }

            Xml.Add(newParagraph);

            var paragraphAdded = Paragraphs.Last();

            GetParent(paragraphAdded);

            return(paragraphAdded);
        }
Esempio n. 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);
        }
Esempio n. 4
0
        public virtual Paragraph InsertParagraph(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 = HelperFunctions.CreateEdit(EditType.ins, DateTime.Now, newParagraph);
            }
            Xml.Add(newParagraph);
            var paragraphAdded = new Paragraph(Document, newParagraph, 0);

            if (this is Cell)
            {
                var cell = this as Cell;
                paragraphAdded.PackagePart = cell.mainPart;
            }
            else if (this is DocX)
            {
                paragraphAdded.PackagePart = Document.mainPart;
            }
            else if (this is Footer)
            {
                var f = this as Footer;
                paragraphAdded.mainPart = f.mainPart;
            }
            else if (this is Header)
            {
                var h = this as Header;
                paragraphAdded.mainPart = h.mainPart;
            }
            else
            {
                Console.WriteLine("No idea what we are {0}", this);
                paragraphAdded.PackagePart = Document.mainPart;
            }


            GetParent(paragraphAdded);

            return(paragraphAdded);
        }