Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.ExtLibs/HeuristicLab.EPPlus/3.1.3/EPPlus-3.1.3/ExcelComment.cs @ 12440

Last change on this file since 12440 was 9580, checked in by sforsten, 12 years ago

#1730:

  • added SymbolicDataAnalysisExpressionExcelFormatter
  • changed modifiers in SymbolicExpressionTreeChart of methods SaveImageAsBitmap and SaveImageAsEmf to public
  • added menu item ExportSymbolicSolutionToExcelMenuItem to export a symbolic solution to an excel file
  • added EPPlus-3.1.3 to ExtLibs
File size: 5.4 KB
Line 
1/*******************************************************************************
2 * You may amend and distribute as you like, but don't remove this header!
3 *
4 * EPPlus provides server-side generation of Excel 2007/2010 spreadsheets.
5 * See http://www.codeplex.com/EPPlus for details.
6 *
7 * Copyright (C) 2011  Jan Källman
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
17 * See the GNU Lesser General Public License for more details.
18 *
19 * The GNU Lesser General Public License can be viewed at http://www.opensource.org/licenses/lgpl-license.php
20 * If you unfamiliar with this license or have questions about it, here is an http://www.gnu.org/licenses/gpl-faq.html
21 *
22 * All code and executables are provided "as is" with no warranty either express or implied.
23 * The author accepts no liability for any damage or loss of business that this product may cause.
24 *
25 * Code change notes:
26 *
27 * Author             Change            Date
28 *******************************************************************************
29 * Jan Källman    Initial Release       
30 * Jan Källman    License changed GPL-->LGPL 2011-12-27
31 *******************************************************************************/
32using System;
33using System.Collections.Generic;
34using System.Text;
35using OfficeOpenXml.Style;
36using System.Xml;
37using OfficeOpenXml.Drawing;
38using OfficeOpenXml.Drawing.Vml;
39
40namespace OfficeOpenXml
41{
42    /// <summary>
43    /// An Excel Cell Comment
44    /// </summary>
45    public class ExcelComment : ExcelVmlDrawingComment
46    {
47        internal XmlHelper _commentHelper;
48        internal ExcelComment(XmlNamespaceManager ns, XmlNode commentTopNode, ExcelRangeBase cell)
49            : base(null, cell, cell.Worksheet.VmlDrawingsComments.NameSpaceManager)
50        {
51            //_commentHelper = new XmlHelper(ns, commentTopNode);
52            _commentHelper = XmlHelperFactory.Create(ns, commentTopNode);
53            var textElem=commentTopNode.SelectSingleNode("d:text", ns);
54            if (textElem == null)
55            {
56                textElem = commentTopNode.OwnerDocument.CreateElement("text", ExcelPackage.schemaMain);
57                commentTopNode.AppendChild(textElem);
58            }
59            if (!cell.Worksheet._vmlDrawings.ContainsKey(ExcelAddress.GetCellID(cell.Worksheet.SheetID, cell.Start.Row, cell.Start.Column)))
60            {
61                cell.Worksheet._vmlDrawings.Add(cell);
62            }
63
64            TopNode = cell.Worksheet.VmlDrawingsComments[ExcelCellBase.GetCellID(cell.Worksheet.SheetID, cell.Start.Row, cell.Start.Column)].TopNode;
65            RichText = new ExcelRichTextCollection(ns,textElem);
66        }
67        const string AUTHORS_PATH = "d:comments/d:authors";
68        const string AUTHOR_PATH = "d:comments/d:authors/d:author";
69        /// <summary>
70        /// Author
71        /// </summary>
72        public string Author
73        {
74            get
75            {
76                int authorRef = _commentHelper.GetXmlNodeInt("@authorId");
77                return _commentHelper.TopNode.OwnerDocument.SelectSingleNode(string.Format("{0}[{1}]", AUTHOR_PATH, authorRef+1), _commentHelper.NameSpaceManager).InnerText;
78            }
79            set
80            {
81                int authorRef = GetAuthor(value);
82                _commentHelper.SetXmlNodeString("@authorId", authorRef.ToString());
83            }
84        }
85        private int GetAuthor(string value)
86        {
87            int authorRef = 0;
88            bool found = false;
89            foreach (XmlElement node in _commentHelper.TopNode.OwnerDocument.SelectNodes(AUTHOR_PATH, _commentHelper.NameSpaceManager))
90            {
91                if (node.InnerText == value)
92                {
93                    found = true;
94                    break;
95                }
96                authorRef++;
97            }
98            if (!found)
99            {
100                var elem = _commentHelper.TopNode.OwnerDocument.CreateElement("d", "author", ExcelPackage.schemaMain);
101                _commentHelper.TopNode.OwnerDocument.SelectSingleNode(AUTHORS_PATH, _commentHelper.NameSpaceManager).AppendChild(elem);
102                elem.InnerText = value;
103            }
104            return authorRef;
105        }
106        /// <summary>
107        /// The comment text
108        /// </summary>
109        public string Text
110        {
111            get
112            {
113                return RichText.Text;
114            }
115            set
116            {
117                RichText.Text = value;
118            }
119        }
120        /// <summary>
121        /// Sets the font of the first richtext item.
122        /// </summary>
123        public ExcelRichText Font
124        {
125            get
126            {
127                if (RichText.Count > 0)
128                {
129                    return RichText[0];
130                }
131                return null;
132            }
133        }
134        /// <summary>
135        /// Richtext collection
136        /// </summary>
137        public ExcelRichTextCollection RichText
138        {
139           get;
140           set;
141        }
142    }
143}
Note: See TracBrowser for help on using the repository browser.