internal ExcelDrawingsGroup(ExcelGroupShape parent, XmlNamespaceManager nsm, XmlNode topNode) { _parent = parent; _nsm = nsm; _topNode = topNode; AddDrawings(); }
private void AddDrawings() { _groupDrawings = new List <ExcelDrawing>(); foreach (XmlNode node in _topNode.ChildNodes) { ExcelDrawing grpDraw; switch (node.LocalName) { case "sp": grpDraw = new ExcelShape(_parent._drawings, node, _parent); break; case "pic": grpDraw = new ExcelPicture(_parent._drawings, node, _parent); break; case "graphicFrame": grpDraw = ExcelChart.GetChart(_parent._drawings, node, _parent); break; case "grpSp": grpDraw = new ExcelGroupShape(_parent._drawings, node, _parent); break; case "cxnSp": grpDraw = new ExcelConnectionShape(_parent._drawings, node, _parent); break; default: continue; } _groupDrawings.Add(grpDraw); _drawingNames.Add(grpDraw.Name, _groupDrawings.Count - 1); } }
internal ExcelPicture(ExcelDrawings drawings, XmlNode node, ExcelGroupShape shape = null) : base(drawings, node, "xdr:pic", "xdr:nvPicPr/xdr:cNvPr", shape) { XmlNode picNode = node.SelectSingleNode("xdr:pic/xdr:blipFill/a:blip", drawings.NameSpaceManager); if (picNode != null) { IPictureContainer container = this; container.RelPic = drawings.Part.GetRelationship(picNode.Attributes["r:embed"].Value); container.UriPic = UriHelper.ResolvePartUri(drawings.UriDrawing, container.RelPic.TargetUri); Part = drawings.Part.Package.GetPart(container.UriPic); FileInfo f = new FileInfo(container.UriPic.OriginalString); ContentType = PictureStore.GetContentType(f.Extension); _image = Image.FromStream(Part.GetStream()); #if (Core) byte[] iby = ImageCompat.GetImageAsByteArray(_image); #else ImageConverter ic = new ImageConverter(); var iby = (byte[])ic.ConvertTo(_image, typeof(byte[])); #endif var ii = _drawings._package.PictureStore.LoadImage(iby, container.UriPic, Part); container.ImageHash = ii.Hash; } }
internal ExcelDrawingsGroup(ExcelGroupShape parent, XmlNamespaceManager nsm, XmlNode topNode) { _parent = parent; _nsm = nsm; _topNode = topNode; _drawingNames = new Dictionary <string, int>(); AddDrawings(); }
internal static void Validate(ExcelDrawing d, ExcelDrawings drawings, ExcelGroupShape grp) { if (d._drawings != drawings) { throw new InvalidOperationException("All drawings must be in the same worksheet."); } if (d._parent != null && d._parent != grp) { throw new InvalidOperationException($"The drawing {d.Name} is already in a group different from the other drawings.");; } }
internal ExcelDrawing(ExcelDrawings drawings, XmlNode node, string topPath, string nvPrPath, ExcelGroupShape parent = null) : base(drawings.NameSpaceManager, node) { _drawings = drawings; _parent = parent; if (node != null) //No drawing, chart xml only. This currently happends when created from a chart template { _topNode = node; _id = drawings.Worksheet.Workbook._nextDrawingID++; AddSchemaNodeOrder(new string[] { "from", "pos", "to", "ext", "pic", "graphicFrame", "sp", "cxnSp ", "nvSpPr", "nvCxnSpPr", "spPr", "style", "clientData" }, _schemaNodeOrderSpPr); if (_parent == null) { _topPath = topPath; _nvPrPath = _topPath + "/" + nvPrPath; _hyperLinkPath = $"{_nvPrPath}/a:hlinkClick"; CellAnchor = GetAnchoreFromName(node.LocalName); SetPositionProperties(drawings, node); GetPositionSize(); //Get the drawing position and size, so we can adjust it upon save, if the normal font is changed string relID = GetXmlNodeString(_hyperLinkPath + "/@r:id"); if (!string.IsNullOrEmpty(relID)) { HypRel = drawings.Part.GetRelationship(relID); if (HypRel.TargetUri == null) { if (!string.IsNullOrEmpty(HypRel.Target)) { Hyperlink = new ExcelHyperLink(HypRel.Target.Substring(1), ""); } } else { if (HypRel.TargetUri.IsAbsoluteUri) { Hyperlink = new ExcelHyperLink(HypRel.TargetUri.AbsoluteUri); } else { Hyperlink = new ExcelHyperLink(HypRel.TargetUri.OriginalString, UriKind.Relative); } } ((ExcelHyperLink)Hyperlink).ToolTip = GetXmlNodeString(_hyperLinkPath + "/@tooltip"); } } else { _topPath = ""; _nvPrPath = nvPrPath; _hyperLinkPath = $"{_nvPrPath}/a:hlinkClick"; } } }
internal ExcelGroupShape(ExcelDrawings drawings, XmlNode node, ExcelGroupShape parent = null) : base(drawings, node, "xdr:grpSp", "xdr:nvGrpSpPr/xdr:cNvPr", parent) { var grpNode = CreateNode(_topPath); if (grpNode.InnerXml == "") { grpNode.InnerXml = "<xdr:nvGrpSpPr><xdr:cNvPr name=\"\" id=\"3\"><a:extLst><a:ext uri=\"{FF2B5EF4-FFF2-40B4-BE49-F238E27FC236}\"><a16:creationId id=\"{F33F4CE3-706D-4DC2-82DA-B596E3C8ACD0}\" xmlns:a16=\"http://schemas.microsoft.com/office/drawing/2014/main\"/></a:ext></a:extLst></xdr:cNvPr><xdr:cNvGrpSpPr/></xdr:nvGrpSpPr><xdr:grpSpPr><a:xfrm><a:off y=\"0\" x=\"0\"/><a:ext cy=\"0\" cx=\"0\"/><a:chOff y=\"0\" x=\"0\"/><a:chExt cy=\"0\" cx=\"0\"/></a:xfrm></xdr:grpSpPr>"; } if (parent == null) { CreateNode("xdr:clientData"); } }
internal void AddDrawing(ExcelDrawing drawing) { if (drawing._parent == _parent) { return; //This drawing is already added to the group, exit } ExcelGroupShape.Validate(drawing, drawing._drawings, _parent); AdjustXmlAndMoveToGroup(drawing); ExcelGroupShape.Validate(drawing, _parent._drawings, _parent); AppendDrawingNode(drawing.TopNode); drawing._parent = _parent; _groupDrawings.Add(drawing); _drawingNames.Add(drawing.Name, _groupDrawings.Count - 1); }
internal ExcelPicture(ExcelDrawings drawings, XmlNode node, ExcelGroupShape shape = null) : base(drawings, node, "xdr:pic", "xdr:nvPicPr/xdr:cNvPr", shape) { XmlNode picNode = node.SelectSingleNode("xdr:pic/xdr:blipFill/a:blip", drawings.NameSpaceManager); if (picNode != null) { IPictureContainer container = this; container.RelPic = drawings.Part.GetRelationship(picNode.Attributes["embed", ExcelPackage.schemaRelationships].Value); container.UriPic = UriHelper.ResolvePartUri(drawings.UriDrawing, container.RelPic.TargetUri); Part = drawings.Part.Package.GetPart(container.UriPic); var extension = Path.GetExtension(container.UriPic.OriginalString); ContentType = PictureStore.GetContentType(extension); #if (Core) try { _image = Image.FromStream(Part.GetStream()); } catch { if (extension.ToLower() == ".emf" || extension.ToLower() == ".wmf") //Not supported in linux environments, so we ignore them and set image to null. { _image = null; return; } else { throw; } } byte[] iby = ImageCompat.GetImageAsByteArray(_image); #else _image = Image.FromStream(Part.GetStream()); ImageConverter ic = new ImageConverter(); var iby = (byte[])ic.ConvertTo(_image, typeof(byte[])); #endif var ii = _drawings._package.PictureStore.LoadImage(iby, container.UriPic, Part); container.ImageHash = ii.Hash; } }
internal ExcelShapeBase(ExcelDrawings drawings, XmlNode node, string topPath, string nvPrPath, ExcelGroupShape parent = null) : base(drawings, node, topPath, nvPrPath, parent) { Init(string.IsNullOrEmpty(_topPath) ? "" : _topPath + "/"); }
/// <summary> /// Disposes the class /// </summary> public void Dispose() { _parent = null; }
internal ExcelGroupShape(ExcelDrawings drawings, XmlNode node, ExcelGroupShape parent = null) : base(drawings, node, "xdr:grpSp", "xdr:nvGrpSpPr/xdr:cNvPr", parent) { }
internal ExcelShape(ExcelDrawings drawings, XmlNode node, ExcelGroupShape shape = null) : base(drawings, node, "xdr:sp", "xdr:nvSpPr/xdr:cNvPr", shape) { }
internal ExcelConnectionShape(ExcelDrawings drawings, XmlNode node, ExcelGroupShape parent = null) : base(drawings, node, "xdr:cxnSp", "xdr:nvCxnSpPr/xdr:cNvPr", parent) { Init(drawings, node); }
/// <summary> /// Disposes the class /// </summary> public void Dispose() { _parent = null; _topNode = null; }