Esempio n. 1
0
		internal Comment Clone(Cell cell)
		{
			Comment cloneComment = new Comment(cell);
			cloneComment._Anchor = this._Anchor;
			cloneComment._BackgroundColor = this._BackgroundColor;
			cloneComment._From = this._From;
			cloneComment._HorizontalAlignment = this._HorizontalAlignment;
			cloneComment._LineColor = this._LineColor;
			cloneComment._LineStyle = this._LineStyle;
			cloneComment._LineWidth = this._LineWidth;
			cloneComment._RichText = this._RichText;
			cloneComment._Style = this._Style;
			cloneComment._To = this._To;
			cloneComment._VerticalAlignment = this._VerticalAlignment;
			cloneComment._Visible = this._Visible;

			return cloneComment;
		}
Esempio n. 2
0
        private XElement WriteComments_comment(Comment cellComment, Dictionary<string, int> authorsList)
        {
            XElement comment = new XElement(XName.Get("comment", ExcelCommon.Schema_WorkBook_Main.NamespaceName), new XAttribute("ref", cellComment._Cell.ToString()));
            if (cellComment.Author.IsNotEmpty())
            {
                int authorId = 0;
                if (authorsList.ContainsKey(cellComment.Author))
                {
                    authorId = authorsList[cellComment.Author];
                }
                else
                {
                    authorId = authorsList.Count;
                    authorsList.Add(cellComment.Author, authorId);
                }
                comment.Add(new XAttribute("authorId", authorId));
            }

            if (cellComment.Text.IsNotEmpty())
            {
                WriteComments_comment_text(comment, cellComment);
            }

            return comment;
        }
Esempio n. 3
0
 private void ReadSheetCommentVmlDrawing_shape_ClientData_TextVAlign(XElement childElement, Comment comment)
 {
     XElement clientChildNode = childElement.Element(XName.Get("TextVAlign", ExcelCommon.schemaMicrosoftExcel));
     if (clientChildNode != null)
     {
         switch (clientChildNode.Value)
         {
             case "Center":
                 comment.VerticalAlignment = ExcelTextAlignVerticalVml.Center;
                 break;
             case "Bottom":
                 comment.VerticalAlignment = ExcelTextAlignVerticalVml.Bottom;
                 break;
         }
     }
 }
		public VmlDrawingPosition(Comment comment, int startPos)
		{
			this.comment = comment;
			this.p = startPos;
		}
Esempio n. 5
0
        internal void ReadSheetComments_Comment(List<string> authors, XElement commentMode, Comment cellComment)
        {
            if (commentMode.Attribute("authorId") != null)
            {
                cellComment.Author = authors[int.Parse(commentMode.Attribute("authorId").Value)];
            }

            XElement textPropertyNode = commentMode.Element(XName.Get("text", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
            if (textPropertyNode != null)
            {
                IEnumerable<XElement> richTextNodes = textPropertyNode.Elements(XName.Get("r", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                foreach (XElement richtextNode in richTextNodes)
                {
                    RichText rt = new RichText();
                    XElement rtnode = richtextNode.Element(XName.Get("t", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                    if (rtnode != null)
                    {
                        if (rtnode.Attribute(XName.Get("space", ExcelCommon.Schema_Xml)) != null)
                        {
                            rt.PreserveSpace = true;
                        }
                        rt.Text = rtnode.Value;
                    }

                    rtnode = richtextNode.Element(XName.Get("rPr", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                    if (rtnode != null)
                    {
                        XElement rPrNode = rtnode.Element(XName.Get("b", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                        if (rPrNode != null)
                        {
                            rt.Bold = true;
                        }

                        rPrNode = rtnode.Element(XName.Get("charset", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                        if (rPrNode != null)
                        {
                            if (rPrNode.Attribute(XName.Get("val", ExcelCommon.Schema_WorkBook_Main.NamespaceName)) != null)
                            {
                                rt.Charset = int.Parse(rPrNode.Attribute(XName.Get("val", ExcelCommon.Schema_WorkBook_Main.NamespaceName)).Value);
                            }
                        }
                        rPrNode = rtnode.Element(XName.Get("color", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                        if (rPrNode != null)
                        {
                            ColorXmlWrapper rtColor = new ColorXmlWrapper();
                            ReadStyles_Color(rPrNode, rtColor);
                            rt._DataBarColor = rtColor;
                        }
                        rPrNode = rtnode.Element(XName.Get("condense", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                        if (rPrNode != null)
                        {
                            rt.Condense = true;
                        }
                        rPrNode = rtnode.Element(XName.Get("extend", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                        if (rPrNode != null)
                        {
                            rt.Extend = true;
                        }

                        //todo: family
                        //rPrNode = richtextNode.Element(XName.Get("family", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                        //if (rPrNode != null)
                        //{
                        //    if (rPrNode.Attribute(XName.Get("val", ExcelCommon.Schema_WorkBook_Main.NamespaceName)) != null)
                        //    {
                        //        rt.FontName = rPrNode.Attribute(XName.Get("val", ExcelCommon.Schema_WorkBook_Main.NamespaceName)).Value;
                        //    }
                        //}

                        rPrNode = rtnode.Element(XName.Get("i", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                        if (rPrNode != null)
                        {
                            rt.Italic = true;
                        }

                        rPrNode = rtnode.Element(XName.Get("outline", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                        if (rPrNode != null)
                        {
                            rt.Outline = true;
                        }

                        rPrNode = rtnode.Element(ExcelCommon.Schema_WorkBook_Main + "rFont");
                        if (rPrNode != null)
                        {
                            if (rPrNode.Attribute("val") != null)
                            {
                                rt.FontName = rPrNode.Attribute("val").Value;
                            }
                        }

                        rPrNode = rtnode.Element(XName.Get("scheme", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                        if (rPrNode != null)
                        {
                            if (rPrNode.Attribute("val") != null)
                            {
                                rt.Scheme = rPrNode.Attribute("val").Value;
                            }
                        }

                        rPrNode = rtnode.Element(XName.Get("shadow", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                        if (rPrNode != null)
                        {
                            rt.Shadow = true;
                        }

                        rPrNode = rtnode.Element(XName.Get("strike", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                        if (rPrNode != null)
                        {
                            rt.Strike = true;
                        }

                        rPrNode = rtnode.Element(XName.Get("sz", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                        if (rPrNode != null)
                        {
                            if (rPrNode.Attribute("val") != null)
                            {
                                rt.Size = float.Parse(rPrNode.Attribute("val").Value);
                            }
                        }

                        rPrNode = rtnode.Element(XName.Get("u", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                        if (rPrNode != null)
                        {
                            rt.UnderLine = true;
                        }

                        rPrNode = rtnode.Element(XName.Get("vertAlign", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                        if (rPrNode != null)
                        {
                            if (rPrNode.Attribute("val") != null)
                            {
                                rt.VerticalAlign = (ExcelVerticalAlignmentFont)Enum.Parse(typeof(ExcelVerticalAlignmentFont), rPrNode.Attribute("val").Value, true); ;
                            }
                        }
                    }

                    cellComment.RichText.Add(rt);
                }
            }
        }
Esempio n. 6
0
 private void ReadSheetCommentVmlDrawing_shape_ClientData_Visible(XElement childElement, Comment comment)
 {
     XElement clientChildNode = childElement.Element(XName.Get("Visible", ExcelCommon.schemaMicrosoftExcel));
     if (clientChildNode != null)
     {
         comment.Visible = true;
     }
 }
Esempio n. 7
0
        internal void ReadSheetCommentVmlDrawing_shape_ClientData(CommentCollection target, XElement clientDataElement, Comment comment)
        {
            XElement childElement = clientDataElement.Element(XName.Get("ClientData", ExcelCommon.schemaMicrosoftExcel));
            if (childElement != null)
            {
                ReadSheetCommentVmlDrawing_shape_ClientData_TextVAlign(childElement, comment);

                ReadSheetCommentVmlDrawing_shape_ClientData_TextHAlign(childElement, comment);

                ReadSheetCommentVmlDrawing_shape_ClientData_Visible(childElement, comment);

                ReadSheetCommentVmlDrawing_shape_ClientData_Locked(childElement, comment);

                ReadSheetCommentVmlDrawing_shape_ClientData_AutoFill(childElement, comment);

                ReadSheetCommentVmlDrawing_shape_ClientData_LockText(childElement, comment);

                ReadSheetCommentVmlDrawing_shape_ClientData_anchor(childElement, comment);
            }
        }
Esempio n. 8
0
 private void WriteCommentsVmlDrawing_shape_textbox(XElement vmlDrawing_shapeNode, Comment comment)
 {
     XElement textboxNode = new XElement(XName.Get("textbox", ExcelCommon.schemaMicrosoftVml));
     if (comment.AutoFit)
     {
         textboxNode.Add(new XAttribute("style", "mso-direction-alt:auto;mso-fit-shape-to-text:t"));
     }
     else
     {
         textboxNode.Add(new XAttribute("style", "mso-direction-alt:auto"));
     }
     textboxNode.Add(new XElement("div", new XAttribute("style", "text-align:left")));
     vmlDrawing_shapeNode.Add(textboxNode);
 }
Esempio n. 9
0
 private void ReadSheetCommentVmlDrawing_shape_stroke(XElement shapetypeNode, Comment comment)
 {
     XElement stroke = shapetypeNode.Element(XName.Get("stroke", ExcelCommon.schemaMicrosoftVml));
     if (stroke != null)
     {
         if (stroke.Attribute(XName.Get("dashstyle")) != null)
         {
             string v = stroke.Attribute(XName.Get("dashstyle")).Value;
             if (string.IsNullOrEmpty(v))
             {
                 comment.LineStyle = ExcelLineStyleVml.Solid;
             }
             else if (v == "1 1")
             {
                 v = stroke.Attribute(XName.Get("endcap")).Value;
                 comment.LineStyle = (ExcelLineStyleVml)Enum.Parse(typeof(ExcelLineStyleVml), v, true);
             }
             else
             {
                 comment.LineStyle = (ExcelLineStyleVml)Enum.Parse(typeof(ExcelLineStyleVml), v, true);
             }
         }
     }
 }
Esempio n. 10
0
 private void ReadSheetCommentVmlDrawing_shape_BackgroundColor(XElement shapetypeNode, Comment comment)
 {
     if (shapetypeNode.Attribute(XName.Get("fillcolor")) != null)
     {
         string col = shapetypeNode.Attribute(XName.Get("fillcolor")).Value;
         if (!string.IsNullOrEmpty(col))
         {
             if (col.StartsWith("#"))
             {
                 col = col.Substring(1, col.Length - 1);
             }
             int res;
             if (int.TryParse(col, System.Globalization.NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out res))
             {
                 comment.BackgroundColor = Color.FromArgb(res);
             }
             else
             {
                 comment.BackgroundColor = ReadSheetCommentVmlDrawing_shape_Fill(shapetypeNode);
             }
         }
         else
         {
             comment.BackgroundColor = ReadSheetCommentVmlDrawing_shape_Fill(shapetypeNode);
         }
     }
     else
     {
         comment.BackgroundColor = ReadSheetCommentVmlDrawing_shape_Fill(shapetypeNode);
     }
 }
Esempio n. 11
0
        private void ReadSheetCommentVmlDrawing_shape_strokeweight(XElement shapetypeNode, Comment ct)
        {
            if (shapetypeNode.Attribute(XName.Get("strokeweight")) != null)
            {
                string wt = shapetypeNode.Attribute(XName.Get("strokeweight")).Value;
                if (!string.IsNullOrEmpty(wt))
                {
                    if (wt.EndsWith("pt"))
                        wt = wt.Substring(0, wt.Length - 2);

                    Single ret;
                    if (Single.TryParse(wt, System.Globalization.NumberStyles.Any, CultureInfo.InvariantCulture, out ret))
                    {
                        ct.LineWidth = ret;
                    }
                    else
                    {
                        ct.LineWidth = 0;
                    }
                }
            }
        }
Esempio n. 12
0
 private void ReadSheetCommentVmlDrawing_shape_textbox(XElement shapetypeNode, Comment ct)
 {
     XElement textboxNode = shapetypeNode.Element(XName.Get("textbox", ExcelCommon.schemaMicrosoftVml));
     if (textboxNode != null)
     {
         if (textboxNode.Attribute(XName.Get("style")) != null)
         {
             string value = textboxNode.Attribute(XName.Get("style")).Value;
             GetStyle(value, "mso-fit-shape-to-text", out value);
             if (value == "t")
             {
                 ct.AutoFit = true;
             }
         }
     }
 }
Esempio n. 13
0
        internal void ReadSheetCommentVmlDrawing_shape(CommentCollection target, XElement vmlDrawingElement)
        {
            IEnumerable<XElement> shapetypes = vmlDrawingElement.Elements(XName.Get("shape", ExcelCommon.schemaMicrosoftVml));

            List<Comment> listComment = new List<Comment>();
            foreach (XElement shapetypeNode in shapetypes)
            {
                Comment ct = new Comment();

                ReadSheetCommentVmlDrawing_shape_BackgroundColor(shapetypeNode, ct);
                ReadSheetCommentVmlDrawing_shape_stroke(shapetypeNode, ct);
                ReadSheetCommentVmlDrawing_shape_strokecolor(shapetypeNode, ct);
                ReadSheetCommentVmlDrawing_shape_strokeweight(shapetypeNode, ct);
                ReadSheetCommentVmlDrawing_shape_textbox(shapetypeNode, ct);

                if (shapetypeNode.Attribute(XName.Get("id", ExcelCommon.schemaMicrosoftVml)) != null)
                {
                    ct.ID = shapetypeNode.Attribute(XName.Get("id", ExcelCommon.schemaMicrosoftVml)).Value;
                }

                ReadSheetCommentVmlDrawing_shape_ClientData(target, shapetypeNode, ct);

                listComment.Add(ct);
            }

            this.Context.DrawingShapes.Add(target._WorkSheet.Name, listComment);
        }
Esempio n. 14
0
        private void WriteComments_comment_text(XElement comment, Comment cellComment)
        {
            XElement textNode = new XElement(XName.Get("text", ExcelCommon.Schema_WorkBook_Main.NamespaceName));

            foreach (RichText rt in cellComment.RichText)
            {
                XElement rNode = new XElement(XName.Get("r", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                WriteComments_comment_text_rPr(rNode, rt);

                XElement tNode = new XElement(XName.Get("t", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                if (rt.PreserveSpace)
                {
                    tNode.Add(new XAttribute(XName.Get("space", ExcelCommon.Schema_Xml), "preserve"));
                }
                tNode.Value = rt.Text;
                rNode.Add(tNode);
                textNode.Add(rNode);
            }

            comment.Add(textNode);
        }
Esempio n. 15
0
        private void ReadSheetCommentVmlDrawing_shape_ClientData_anchor(XElement childElement, Comment comment)
        {
            XElement clientChildNode = childElement.Element(XName.Get("anchor", ExcelCommon.schemaMicrosoftExcel));
            if (clientChildNode != null)
            {
                string anchor = clientChildNode.Value;
                if (string.IsNullOrEmpty(anchor))
                {
                    string[] numbers = anchor.Split(',');
                    if (numbers.Length == 8)
                    {
                        int ret;
                        if (int.TryParse(numbers[2], out ret))
                        {
                            comment.From.Row = ret;
                        }
                        if (int.TryParse(numbers[3], out ret))
                        {
                            comment.From.RowOffset = ret;
                        }
                        if (int.TryParse(numbers[0], out ret))
                        {
                            comment.From.Column = ret;
                        }
                        if (int.TryParse(numbers[1], out ret))
                        {
                            comment.From.ColumnOffset = ret;
                        }

                        if (int.TryParse(numbers[6], out ret))
                        {
                            comment.To.Row = ret;
                        }
                        if (int.TryParse(numbers[8], out ret))
                        {
                            comment.To.RowOffset = ret;
                        }
                        if (int.TryParse(numbers[4], out ret))
                        {
                            comment.To.Column = ret;
                        }
                        if (int.TryParse(numbers[5], out ret))
                        {
                            comment.To.ColumnOffset = ret;
                        }
                    }
                }
            }
        }
Esempio n. 16
0
        private XElement WriteCommentsVmlDrawing_shape(Comment comment, int rowIndex, int columnIndex, int id)
        {
            XElement vmlDrawing_shapeNode = new XElement(XName.Get("shape", ExcelCommon.schemaMicrosoftVml),
                new XAttribute("id", string.Format("shapeDr{0}", id)),
                new XAttribute("type", "#_x0000_t202"));

            if (comment.Visible)
            {
                vmlDrawing_shapeNode.Add(new XAttribute("style", "position:absolute;z-index:1; visibility:visible"));
            }
            else
            {
                vmlDrawing_shapeNode.Add(new XAttribute("style", "position:absolute;z-index:1; visibility:hidden"));
            }

            string color = comment.BackgroundColor.ToArgb().ToString("x");
            if (color.Length > 6)
            {
                color = color.Substring(2, 6);
            }
            if (color.Length < 6)
            {
                color = "ffffe1";
            }
            color = "#" + color;
            vmlDrawing_shapeNode.Add(new XAttribute("fillcolor", color));

            vmlDrawing_shapeNode.Add(new XAttribute(XName.Get("insetmode", ExcelCommon.schemaMicrosoftOffice), "auto"));
            vmlDrawing_shapeNode.Add(new XElement(XName.Get("fill", ExcelCommon.schemaMicrosoftVml),
                new XAttribute("color2", "#ffffe1")));

            if (comment.LineStyle != ExcelLineStyleVml.Solid)
            {
                XElement strokeNode = new XElement(XName.Get("stroke", ExcelCommon.schemaMicrosoftVml));
                if (comment.LineStyle == ExcelLineStyleVml.Round || comment.LineStyle == ExcelLineStyleVml.Square)
                {
                    strokeNode.Add(new XAttribute(XName.Get("dashstyle"), "1 1"));
                    if (comment.LineStyle == ExcelLineStyleVml.Round)
                    {
                        strokeNode.Add(new XAttribute(XName.Get("endcap"), "round"));
                    }
                }
                else
                {
                    string v = comment.LineStyle.ToString();
                    v = v.Substring(0, 1).ToLower() + v.Substring(1, v.Length - 1);
                    strokeNode.Add(new XAttribute(XName.Get("dashstyle"), v));
                }
                vmlDrawing_shapeNode.Add(strokeNode);
            }

            vmlDrawing_shapeNode.Add(new XElement(XName.Get("shadow", ExcelCommon.schemaMicrosoftVml),
                new XAttribute("on", "t"),
                new XAttribute("color", "black"),
                new XAttribute("obscured", "t")));

            vmlDrawing_shapeNode.Add(new XElement(XName.Get("path", ExcelCommon.schemaMicrosoftVml),
                new XAttribute(XName.Get("connecttype", ExcelCommon.schemaMicrosoftOffice), "none")));

            WriteCommentsVmlDrawing_shape_textbox(vmlDrawing_shapeNode, comment);

            XElement clientDataElement = new XElement(XName.Get("ClientData", ExcelCommon.schemaMicrosoftExcel),
                    new XAttribute("ObjectType", "Note"),
                    new XElement(XName.Get("MoveWithCells", ExcelCommon.schemaMicrosoftExcel)),
                    new XElement(XName.Get("SizeWithCells", ExcelCommon.schemaMicrosoftExcel)));

            WriteCommentsVmlDrawing_shape_Anchor(clientDataElement, comment, rowIndex, columnIndex);

            if (comment.Locked)
            {
                clientDataElement.Add(new XElement(XName.Get("Locked", ExcelCommon.schemaMicrosoftExcel)) { Value = "1" });
            }

            if (comment.AutoFill)
            {
                clientDataElement.Add(new XElement(XName.Get("AutoFill", ExcelCommon.schemaMicrosoftExcel)) { Value = "True" });
            }
            else
            {
                clientDataElement.Add(new XElement(XName.Get("AutoFill", ExcelCommon.schemaMicrosoftExcel)) { Value = "False" });
            }

            if (comment.VerticalAlignment != ExcelTextAlignVerticalVml.Top)
            {
                switch (comment.VerticalAlignment)
                {
                    case ExcelTextAlignVerticalVml.Center:
                        clientDataElement.Add(new XElement(XName.Get("TextVAlign", ExcelCommon.schemaMicrosoftExcel)) { Value = "Center" });
                        break;
                    case ExcelTextAlignVerticalVml.Bottom:
                        clientDataElement.Add(new XElement(XName.Get("TextVAlign", ExcelCommon.schemaMicrosoftExcel)) { Value = "Bottom" });
                        break;
                }
            }

            if (comment.HorizontalAlignment != ExcelTextAlignHorizontalVml.Left)
            {
                switch (comment.HorizontalAlignment)
                {
                    case ExcelTextAlignHorizontalVml.Center:
                        clientDataElement.Add(new XElement(XName.Get("TextHAlign", ExcelCommon.schemaMicrosoftExcel)) { Value = "Center" });
                        break;
                    case ExcelTextAlignHorizontalVml.Right:
                        clientDataElement.Add(new XElement(XName.Get("TextHAlign", ExcelCommon.schemaMicrosoftExcel)) { Value = "Right" });
                        break;
                }
            }
            clientDataElement.Add(new XElement(XName.Get("Row", ExcelCommon.schemaMicrosoftExcel)) { Value = (rowIndex - 1).ToString() });
            clientDataElement.Add(new XElement(XName.Get("Column", ExcelCommon.schemaMicrosoftExcel)) { Value = (columnIndex - 1).ToString() });
            if (comment.Visible)
            {
                clientDataElement.Add(new XElement(XName.Get("Visible", ExcelCommon.schemaMicrosoftExcel)));
            }

            vmlDrawing_shapeNode.Add(clientDataElement);

            return vmlDrawing_shapeNode;

        }
Esempio n. 17
0
 private void ReadSheetCommentVmlDrawing_shape_ClientData_Locked(XElement childElement, Comment comment)
 {
     XElement clientChildNode = childElement.Element(XName.Get("Locked", ExcelCommon.schemaMicrosoftExcel));
     if (clientChildNode != null)
     {
         comment.Locked = clientChildNode.Value.Equals("1") ? true : false;
     }
 }
Esempio n. 18
0
 private void WriteCommentsVmlDrawing_shape_Anchor(XElement clientDataElement, Comment comment, int rowIndex, int columnIndex)
 {
     XElement anchorElement = new XElement(XName.Get("Anchor", ExcelCommon.schemaMicrosoftExcel));
     if (!string.IsNullOrEmpty(comment.Anchor))
     {
         anchorElement.Value = comment.Anchor;
     }
     else
     {
         anchorElement.Value = string.Format("{0}, 15, {1}, 2, {2}, 31, {3}, 1", columnIndex, rowIndex - 1, columnIndex + 2, rowIndex + 3);
     }
     clientDataElement.Add(anchorElement);
 }
Esempio n. 19
0
 public VmlDrawingPosition(Comment comment, int startPos)
 {
     this.comment = comment;
     this.p       = startPos;
 }