예제 #1
0
        public void SaveStyles()
        {
            StringBuilder stringBuilder = new StringBuilder();
            XmlWriter     xmlWriter     = XmlWriter.Create(stringBuilder);
            XmlDocument   xmlDoc        = new XmlDocument();

            XmlElement stylesNode = xmlDoc.CreateElement("Styles");

            xmlDoc.AppendChild(stylesNode);

            foreach (int index in styleIndex.Values)
            {
                StyleCopy thisStyle = defaultStyle;
                if (styles.ContainsKey(index))
                {
                    thisStyle = styles[index];
                }
                XmlElement styleElement = xmlDoc.CreateElement("Style");

                XmlAttribute name = xmlDoc.CreateAttribute("index");
                name.Value = index.ToString();
                styleElement.Attributes.Append(name);

                XmlAttribute fontName = xmlDoc.CreateAttribute("fontName");
                fontName.Value = thisStyle.Font;
                styleElement.Attributes.Append(fontName);

                XmlAttribute fontSize = xmlDoc.CreateAttribute("fontSize");
                fontSize.Value = thisStyle.Size.ToString();
                styleElement.Attributes.Append(fontSize);

                XmlAttribute foreColor = xmlDoc.CreateAttribute("foreColor");
                foreColor.Value = thisStyle.ForeColor.ToArgb().ToString("X");
                styleElement.Attributes.Append(foreColor);

                XmlAttribute backColor = xmlDoc.CreateAttribute("backColor");
                backColor.Value = thisStyle.BackColor.ToArgb().ToString("X");
                styleElement.Attributes.Append(backColor);

                XmlAttribute bold = xmlDoc.CreateAttribute("bold");
                bold.Value = thisStyle.Bold.ToString();
                styleElement.Attributes.Append(bold);

                XmlAttribute italic = xmlDoc.CreateAttribute("italic");
                italic.Value = thisStyle.Italic.ToString();
                styleElement.Attributes.Append(italic);

                XmlAttribute underline = xmlDoc.CreateAttribute("underline");
                underline.Value = thisStyle.Underline.ToString();
                styleElement.Attributes.Append(italic);

                stylesNode.AppendChild(styleElement);
            }

            xmlDoc.WriteContentTo(xmlWriter);
            xmlWriter.Close();
            Properties.Settings.Default.StyleConfig = stringBuilder.ToString();
        }
예제 #2
0
        private void LoadStyle()
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(Properties.Settings.Default.StyleConfig);
            XmlNodeList nodeList = xmlDoc.SelectNodes("Styles/Style");

            foreach (XmlElement styleNode in nodeList)
            {
                StyleCopy thisStyle = defaultStyle;
                int       styleIndex;

                string index     = styleNode.GetAttribute("index");
                string fontName  = styleNode.GetAttribute("fontName");
                string fontSize  = styleNode.GetAttribute("fontSize");
                string foreColor = styleNode.GetAttribute("foreColor");
                string backColor = styleNode.GetAttribute("backColor");
                string bold      = styleNode.GetAttribute("bold");
                string italic    = styleNode.GetAttribute("italic");
                string underline = styleNode.GetAttribute("underline");

                if (index == "" || int.TryParse(index, out styleIndex) == false)
                {
                    continue;
                }

                if (fontName != "")
                {
                    thisStyle.Font = fontName;
                }
                if (parseFloat(fontSize) > float.MinValue)
                {
                    thisStyle.Size = float.Parse(fontSize);
                }
                if (parseHex(foreColor) > int.MinValue)
                {
                    thisStyle.ForeColor = Color.FromArgb(int.Parse(foreColor, System.Globalization.NumberStyles.HexNumber));
                }
                if (parseHex(backColor) > int.MinValue)
                {
                    thisStyle.BackColor = Color.FromArgb(int.Parse(backColor, System.Globalization.NumberStyles.HexNumber));
                }
                if (isBool(bold))
                {
                    thisStyle.Bold = bool.Parse(bold);
                }
                if (isBool(italic))
                {
                    thisStyle.Italic = bool.Parse(italic);
                }
                if (isBool(underline))
                {
                    thisStyle.Underline = bool.Parse(underline);
                }

                styles[styleIndex] = thisStyle;
            }
        }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CopyStyleOnlineRequest"/> class.
 /// </summary>
 /// <param name="document">The document.</param>
 /// <param name="styleCopy">Style to copy.</param>
 /// <param name="loadEncoding">Encoding that will be used to load an HTML (or TXT) document if the encoding is not specified in HTML.</param>
 /// <param name="password">Password for opening an encrypted document.</param>
 /// <param name="destFileName">Result path of the document after the operation. If this parameter is omitted then result of the operation will be saved as the source document.</param>
 /// <param name="revisionAuthor">Initials of the author to use for revisions.If you set this parameter and then make some changes to the document programmatically, save the document and later open the document in MS Word you will see these changes as revisions.</param>
 /// <param name="revisionDateTime">The date and time to use for revisions.</param>
 public CopyStyleOnlineRequest(System.IO.Stream document, StyleCopy styleCopy, string loadEncoding = null, string password = null, string destFileName = null, string revisionAuthor = null, string revisionDateTime = null)
 {
     this.Document         = document;
     this.StyleCopy        = styleCopy;
     this.LoadEncoding     = loadEncoding;
     this.Password         = password;
     this.DestFileName     = destFileName;
     this.RevisionAuthor   = revisionAuthor;
     this.RevisionDateTime = revisionDateTime;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CopyStyleRequest"/> class.
 /// </summary>
 /// <param name="name">The filename of the input document.</param>
 /// <param name="styleCopy">Style to copy.</param>
 /// <param name="folder">Original document folder.</param>
 /// <param name="storage">Original document storage.</param>
 /// <param name="loadEncoding">Encoding that will be used to load an HTML (or TXT) document if the encoding is not specified in HTML.</param>
 /// <param name="password">Password for opening an encrypted document.</param>
 /// <param name="destFileName">Result path of the document after the operation. If this parameter is omitted then result of the operation will be saved as the source document.</param>
 /// <param name="revisionAuthor">Initials of the author to use for revisions.If you set this parameter and then make some changes to the document programmatically, save the document and later open the document in MS Word you will see these changes as revisions.</param>
 /// <param name="revisionDateTime">The date and time to use for revisions.</param>
 public CopyStyleRequest(string name, StyleCopy styleCopy, string folder = null, string storage = null, string loadEncoding = null, string password = null, string destFileName = null, string revisionAuthor = null, string revisionDateTime = null)
 {
     this.Name             = name;
     this.StyleCopy        = styleCopy;
     this.Folder           = folder;
     this.Storage          = storage;
     this.LoadEncoding     = loadEncoding;
     this.Password         = password;
     this.DestFileName     = destFileName;
     this.RevisionAuthor   = revisionAuthor;
     this.RevisionDateTime = revisionDateTime;
 }
예제 #5
0
        public void SetStyle(int index, StyleCopy style)
        {
            styles[index] = style;

            StyleDidChange.Invoke(this, new EventArgs());
        }