Exemple #1
0
        /// <summary>
        /// A text formatting.
        /// </summary>
        public Formatting()
        {
            capsStyle = CapsStyle.none;
            strikethrough = StrikeThrough.none;
            script = Script.none;
            highlight = Highlight.none;
            underlineStyle = UnderlineStyle.none;
            misc = Misc.none;

            rPr = new XElement(XName.Get("rPr", DocX.w.NamespaceName));
        }
        /// <summary>
        /// A text formatting.
        /// </summary>
        public Formatting()
        {
            capsStyle = CapsStyle.none;
            strikethrough = StrikeThrough.none;
            script = Script.none;
            highlight = Highlight.none;
            underlineStyle = UnderlineStyle.none;
            misc = Misc.none;

            // Use current culture by default
            language = CultureInfo.CurrentCulture;

            rPr = new XElement(XName.Get("rPr", DocX.w.NamespaceName));
        }
Exemple #3
0
        private void ParseText()
        {
            try
            {
                parsed = true;
                parser.Parse(this.Text);
                parseStatus = Resources.ParseSucceededMessageBox;
            }
            catch (SyntaxException ex)
            {
                parsed = false;
                parseStatus = string.Format(Resources.Culture, Resources.ParseFailedMessage, ex.Message);
                int position = ex.Index;
                if (position < this.Text.Length - 1)
                {
                    position++;
                }

                this.SelectionStart = position;
                this.SelectionLength = this.Text.Length == 0 ? 0 : this.Text.Length - position - 1;
                this.SelectionUnderlineStyle = UnderlineStyle.Wave;
                this.SelectionUnderlineColor = UnderlineColor.Red;
            }
        }
Exemple #4
0
        private void HighlightTokens()
        {
            this.SelectionStart = 0;
            this.SelectionLength = this.Text.Length;

            this.SelectionUnderlineColor = UnderlineColor.None;
            this.SelectionUnderlineStyle = UnderlineStyle.None;

            LexicalAnalyzer lexer = new LexicalAnalyzer(this.Text);

            TokenType lastToken = TokenType.Any;

            for (TokenType tokenType = lexer.MoveNext(); tokenType != TokenType.EndOfFile; tokenType = lexer.MoveNext())
            {
                this.SelectionStart = lexer.CurrentMatch.Index;
                this.SelectionLength = lexer.CurrentMatch.Length;

                switch (tokenType)
                {
                    case TokenType.And:
                    case TokenType.Or:
                    case TokenType.Not:
                        this.SelectionColor = Color.Blue;
                        break;
                    case TokenType.Identity:
                    case TokenType.Role:
                        this.SelectionColor = Color.Navy;
                        break;
                    case TokenType.Word:
                    case TokenType.QuotedString:
                        if (lastToken == TokenType.Identity || lastToken == TokenType.Role)
                        {
                            this.SelectionColor = Color.Navy;
                        }
                        else
                        {
                            this.SelectionColor = Color.Black;
                        }
                        break;
                    default:
                        this.SelectionColor = Color.Black;
                        break;
                }

                lastToken = tokenType;
            }
        }
Exemple #5
0
        /// <summary>
        /// For use with Append() and AppendLine()
        /// </summary>
        /// <param name="underlineStyle">The underline style to use for the appended text.</param>
        /// <returns>This Paragraph with the last appended text underlined.</returns>
        /// <example>
        /// Append text to this Paragraph and then underline it.
        /// <code>
        /// // Create a document.
        /// using (DocX document = DocX.Create(@"Test.docx"))
        /// {
        ///     // Insert a new Paragraph.
        ///     Paragraph p = document.InsertParagraph();
        ///
        ///     p.Append("I am ")
        ///     .Append("Underlined").UnderlineStyle(UnderlineStyle.doubleLine)
        ///     .Append(" I am not");
        ///        
        ///     // Save this document.
        ///     document.Save();
        /// }// Release this document from memory.
        /// </code>
        /// </example>
        public Paragraph UnderlineStyle(UnderlineStyle underlineStyle)
        {
            string value;
            switch (underlineStyle)
            {
                case Novacode.UnderlineStyle.none: value = string.Empty; break;
                case Novacode.UnderlineStyle.singleLine: value = "single"; break;
                case Novacode.UnderlineStyle.doubleLine: value = "double"; break;
                default: value = underlineStyle.ToString(); break;
            }

            ApplyTextFormattingProperty(XName.Get("u", DocX.w.NamespaceName), string.Empty, new XAttribute(XName.Get("val", DocX.w.NamespaceName), value));
            return this;
        }
Exemple #6
0
        private void WriteUnderlineAttribute(UnderlineStyle style)
        {
            this._innerWriter.Escape = false;
            switch (style)
            {
                case UnderlineStyle.None:
                    this._innerWriter.Write(@"\ul0");
                    break;

                case UnderlineStyle.Single:
                    this._innerWriter.Write(@"\ul");
                    break;

                case UnderlineStyle.Word:
                    this._innerWriter.Write(@"\ulw");
                    break;

                case UnderlineStyle.Dotted:
                    this._innerWriter.Write(@"\uld");
                    break;

                case UnderlineStyle.Doubled:
                    this._innerWriter.Write(@"\uldb");
                    break;

                case UnderlineStyle.Wave:
                    this._innerWriter.Write(@"\ulwave");
                    break;
            }
            this._innerWriter.Escape = true;
        }
Exemple #7
0
 /// <summary>
 /// 字体样式(加粗,斜体,下划线)
 /// </summary>
 /// <param name="startRow">起始行</param>
 /// <param name="startColumn">起始列</param>
 /// <param name="endRow">结束行</param>
 /// <param name="endColumn">结束列</param>
 /// <param name="isBold">是否加粗</param>
 /// <param name="isItalic">是否斜体</param>
 /// <param name="underline">下划线类型</param>
 public void FontStyle(int startRow, int startColumn, int endRow, int endColumn, bool isBold, bool isItalic, UnderlineStyle underline)
 {
     Excel.Range range = myExcel.get_Range(myExcel.Cells[startRow, startColumn], myExcel.Cells[endRow, endColumn]);
     range.Font.Bold = isBold;
     range.Font.Underline = underline;
     range.Font.Italic = isItalic;
 }