Click here to Skip to main content
13,002,271 members (89,331 online)
Click here to Skip to main content

Stats

112.4K views
3.8K downloads
100 bookmarked
Posted 30 Jul 2010

RTF Document Constructor Library

, 16 Aug 2010
Create Rich Text Format documents programatically.
using System;
using System.Collections.Generic;
using System.Text;

namespace ESCommon.Rtf
{
    /// <summary>
    /// Represents cell definition containing information about cell style and width.
    /// </summary>
    public class RtfTableCellDefinition
    {
        private RtfTableCell _cell;
        private RtfTableCellStyle _style;

        private bool
            hasStyle = false,
            widthSet = false,
            firstHorizontallyMergedCell = false,
            horizontallyMergedCell = false,
            firstVerticallyMergedCell = false,
            verticallyMergedCell = false;

        internal int WidthInternal = 9797;

        internal bool FirstHorizontallyMergedCellInternal
        {
            get { return firstHorizontallyMergedCell; }
            set
            {
                if (firstHorizontallyMergedCell = value)
                {
                    horizontallyMergedCell = false;
                    _cell.Clear();
                }
            }
        }

        internal bool HorizontallyMergedCellInternal
        {
            get { return horizontallyMergedCell; }
            set
            {
                if (horizontallyMergedCell = value)
                {
                    firstHorizontallyMergedCell = false;
                    _cell.Clear();
                }
            }
        }

        internal bool FirstVerticallyMergedCellInternal
        {
            get { return firstVerticallyMergedCell; }
            set
            {
                if (firstVerticallyMergedCell = value)
                {
                    verticallyMergedCell = false;
                    _cell.Clear();
                }
            }
        }

        internal bool VerticallyMergedCellInternal
        {
            get { return verticallyMergedCell; }
            set
            {
                if (verticallyMergedCell = value)
                {
                    firstVerticallyMergedCell = false;
                    _cell.Clear();
                }
            }
        }

        internal bool IsWidthSet
        {
            get { return widthSet; }
        }

        internal bool HasStyle
        {
            get { return hasStyle; }
        }

        internal RtfTableCellStyle StyleInternal
        {
            get { return _style; }
            set { _style = value; }
        }

        /// <summary>
        /// Gets a Boolean value indicating that the cell is the first cell in a range of table cells to be merged.
        /// </summary>
        [RtfControlWord("clmgf")]
        public bool FirstHorizontallyMergedCell
        {
            get { return firstHorizontallyMergedCell; }
        }

        /// <summary>
        /// Gets a Boolean value indicating that the contents of the table cell are merged with those of the preceding cell.
        /// </summary>
        [RtfControlWord("clmrg")]
        public bool HorizontallyMergedCell
        {
            get { return horizontallyMergedCell; }
        }

        /// <summary>
        /// Gets a Boolean value indicating that the cell is the first cell in a range of table cells to be vertically merged.
        /// </summary>
        [RtfControlWord("clvmgf")]
        public bool FirstVerticallyMergedCell
        {
            get { return firstVerticallyMergedCell; }
        }

        /// <summary>
        /// Gets a Boolean value indicating that the contents of the table cell are vertically merged with those of the preceding cell.
        /// </summary>
        [RtfControlWord("clvmrg")]
        public bool VerticallyMergedCell
        {
            get { return verticallyMergedCell; }
        }

        /// <summary>
        /// Gets or sets the style of the cell.
        /// </summary>
        [RtfInclude]
        public RtfTableCellStyle Style
        {
            get { return _style; }
            set
            {
                _style = value;

                if (hasStyle = _style != null)
                {
                    _cell.Formatting = _style.DefaultParagraphFormatting;
                }
            }
        }

        /// <summary>
        /// Gets the right boundary of the cell in twips.
        /// </summary>
        [RtfControlWord("cellx")]
        public int RightBoundary
        {
            get 
            {
                int boundary = 0;

                for (int i = 0; i <= _cell.ColumnIndexInternal; i++)
                    boundary += _cell.RowInternal.Cells[i].Definition.Width;

                return boundary;
            }
        }

        /// <summary>
        /// Gets or sets the width of the cell in twips.
        /// </summary>
        public int Width
        {
            get { return WidthInternal; }
            set
            {
                widthSet = true;
                WidthInternal = value;
            }
        }

        internal RtfTableCellDefinition(RtfTableCell cell)
        {
            _cell = cell;
        }

        internal RtfTableCellDefinition(RtfTableCell cell, RtfTableCellStyle style)
        {
            _cell = cell;
            _style = style;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Dima Popov
Software Developer Energoservice
Russian Federation Russian Federation
Dmitry lives in Arkhangelsk, Russia. He has developed C# applications since 2007.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170624.1 | Last Updated 16 Aug 2010
Article Copyright 2010 by Dima Popov
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid