Example #1
0
        internal ExcelPicture(ExcelDrawings drawings, XmlNode node) :
            base(drawings, node, "xdr:pic/xdr:nvPicPr/xdr:cNvPr/@name")
        {
            XmlNode picNode = node.SelectSingleNode("xdr:pic/xdr:blipFill/a:blip", drawings.NameSpaceManager);
            if (picNode != null)
            {
                RelPic = drawings.Part.GetRelationship(picNode.Attributes["r:embed"].Value);
                UriPic = PackUriHelper.ResolvePartUri(drawings.UriDrawing, RelPic.TargetUri);

                Part = drawings.Part.Package.GetPart(UriPic);
                FileInfo f = new FileInfo(UriPic.OriginalString);
                ContentType = GetContentType(f.Extension);
                _image = Image.FromStream(Part.GetStream());
                ImageConverter ic=new ImageConverter();
                var iby=(byte[])ic.ConvertTo(_image, typeof(byte[]));
                var ii = _drawings._package.LoadImage(iby, UriPic, Part);
                ImageHash = ii.Hash;

                string relID = GetXmlNodeString("xdr:pic/xdr:nvPicPr/xdr:cNvPr/a:hlinkClick/@r:id");
                if (!string.IsNullOrEmpty(relID))
                {
                    HypRel = drawings.Part.GetRelationship(relID);
                    if (HypRel.TargetUri.IsAbsoluteUri)
                    {
                        _hyperlink = new ExcelHyperLink(HypRel.TargetUri.AbsoluteUri);
                    }
                    else
                    {
                        _hyperlink = new ExcelHyperLink(HypRel.TargetUri.OriginalString, UriKind.Relative);
                    }
                    ((ExcelHyperLink)_hyperlink).ToolTip = GetXmlNodeString("xdr:pic/xdr:nvPicPr/xdr:cNvPr/a:hlinkClick/@tooltip");
                }
            }
        }
Example #2
0
        internal ExcelPicture(ExcelDrawings drawings, XmlNode node)
            : base(drawings, node, "xdr:pic/xdr:nvPicPr/xdr:cNvPr/@name")
        {
            XmlNode picNode = node.SelectSingleNode("xdr:pic/xdr:blipFill/a:blip", drawings.NameSpaceManager);
            if (picNode != null)
            {
                PackageRelationship drawingRelation = drawings.Part.GetRelationship(picNode.Attributes["r:embed"].Value);
                UriPic = PackUriHelper.ResolvePartUri(drawings.UriDrawing, drawingRelation.TargetUri);

                PackagePart part = drawings.Part.Package.GetPart(UriPic);
                _image = Image.FromStream(part.GetStream());
            }
        }
Example #3
0
 internal ExcelDrawing(ExcelDrawings drawings, XmlNode node, string nameXPath)
     : base(drawings.NameSpaceManager, node)
 {
     _drawings = drawings;
     _topNode = node;
     XmlNode posNode = node.SelectSingleNode("xdr:from", drawings.NameSpaceManager);
     if (node != null)
     {
         From = new ExcelPosition(posNode, drawings.NameSpaceManager);
     }
     posNode = node.SelectSingleNode("xdr:to", drawings.NameSpaceManager);
     if (node != null)
     {
         To = new ExcelPosition(posNode, drawings.NameSpaceManager);
     }
     _nameXPath = nameXPath;
 }
Example #4
0
        internal ExcelPicture(ExcelDrawings drawings, XmlNode node, Image image)
            : base(drawings, node, "xdr:pic/xdr:nvPicPr/xdr:cNvPr/@name")
        {
            XmlElement picNode = node.OwnerDocument.CreateElement("xdr", "pic", ExcelPackage.schemaSheetDrawings);
            node.InsertAfter(picNode,node.SelectSingleNode("xdr:to",NameSpaceManager));
            picNode.InnerXml = PicStartXml();

            node.InsertAfter(node.OwnerDocument.CreateElement("xdr", "clientData", ExcelPackage.schemaSheetDrawings), picNode);

            Package package = drawings.Worksheet.xlPackage.Package;
            //Get the picture if it exists or save it if not.
            _image = image;
            string relID = SavePicture(image);

            //Create relationship
            node.SelectSingleNode("xdr:pic/xdr:blipFill/a:blip/@r:embed", NameSpaceManager).Value = relID;

            SetPosDefaults(image);
            package.Flush();
        }
Example #5
0
 internal ExcelPicture(ExcelDrawings drawings, XmlNode node, Image image) :
    this(drawings, node, image, null)
 {
 }
Example #6
0
 internal ExcelPicture(ExcelDrawings drawings, XmlNode node, FileInfo imageFile) :
    this(drawings,node,imageFile,null)
 {
 }
Example #7
0
 internal ExcelShapeBase(ExcelDrawings drawings, XmlNode node, string topPath, string nvPrPath, ExcelGroupShape parent = null) :
     base(drawings, node, topPath, nvPrPath, parent)
 {
     Init(string.IsNullOrEmpty(_topPath) ? "" : _topPath + "/");
 }
Example #8
0
 /// <summary>
 /// Add new Drawing types here
 /// </summary>
 /// <param name="drawings">The drawing collection</param>
 /// <param name="node">Xml top node</param>
 /// <returns>The Drawing object</returns>
 internal static ExcelDrawing GetDrawing(ExcelDrawings drawings, XmlNode node)
 {
     if (node.SelectSingleNode("xdr:sp", drawings.NameSpaceManager) != null)
     {
         return new ExcelShape(drawings, node);
     }
     else if (node.SelectSingleNode("xdr:pic", drawings.NameSpaceManager) != null)
     {
         return new ExcelPicture(drawings, node);
     }
     else if (node.SelectSingleNode("xdr:graphicFrame", drawings.NameSpaceManager) != null)
     {
         return ExcelChart.GetChart(drawings, node);
     }
     else
     {
         return new ExcelDrawing(drawings, node, "");
     }
 }
Example #9
0
        internal ExcelShape(ExcelDrawings drawings, XmlNode node, eShapeStyle style) :
            base(drawings, node, "xdr:sp/xdr:nvSpPr/xdr:cNvPr/@name")
        {
            init();
            XmlElement shapeNode = node.OwnerDocument.CreateElement("xdr", "sp", ExcelPackage.schemaSheetDrawings);
            shapeNode.SetAttribute("macro", "");
            shapeNode.SetAttribute("textlink", "");
            node.AppendChild(shapeNode);

            shapeNode.InnerXml = ShapeStartXml();
            node.AppendChild(shapeNode.OwnerDocument.CreateElement("xdr", "clientData", ExcelPackage.schemaSheetDrawings));
        }
Example #10
0
 internal ExcelShape(ExcelDrawings drawings, XmlNode node) :
     base(drawings, node, "xdr:sp/xdr:nvSpPr/xdr:cNvPr/@name")
 {
     init();
 }
Example #11
0
        internal ExcelChart(ExcelDrawings drawings, XmlNode node)
            : base(drawings, node, "xdr:graphicFrame/xdr:nvGraphicFramePr/xdr:cNvPr/@name")
        {
            XmlNode chartNode = node.SelectSingleNode("xdr:graphicFrame/a:graphic/a:graphicData/c:chart", drawings.NameSpaceManager);
            if (chartNode != null)
            {
                PackageRelationship drawingRelation = drawings.Part.GetRelationship(chartNode.Attributes["r:id"].Value);
                UriChart = PackUriHelper.ResolvePartUri(drawings.UriDrawing, drawingRelation.TargetUri);

                Part = drawings.Part.Package.GetPart(UriChart);
                ChartXml = new XmlDocument();
                ChartXml.Load(Part.GetStream());
                SetChartType();
                _chartXmlHelper = new XmlHelper(drawings.NameSpaceManager, ChartXml);
                _series = new ExcelChartSeries(this, drawings.NameSpaceManager, ChartXml.SelectSingleNode(_chartPath, drawings.NameSpaceManager));
                LoadAxis();
            }
            else
            {
                ChartXml = null;
            }
        }
 internal ExcelDrawingConnectionPoint(ExcelDrawings drawings, XmlNode topNode, string elementName, string[] schemaNodeOrder) : base(drawings.NameSpaceManager, topNode)
 {
     _path           = string.Format(_path, elementName);
     _drawings       = drawings;
     SchemaNodeOrder = schemaNodeOrder;
 }
Example #13
0
 internal ExcelPicture(ExcelDrawings drawings, XmlNode node, Image image) :
     this(drawings, node, image, null)
 {
 }
Example #14
0
 internal ExcelPicture(ExcelDrawings drawings, XmlNode node, FileInfo imageFile) :
     this(drawings, node, imageFile, null)
 {
 }
Example #15
0
 internal ExcelGroupShape(ExcelDrawings drawings, XmlNode node, ExcelGroupShape parent = null) :
     base(drawings, node, "xdr:grpSp", "xdr:nvGrpSpPr/xdr:cNvPr", parent)
 {
 }
Example #16
0
 internal ExcelShape(ExcelDrawings drawings, XmlNode node, ExcelGroupShape shape = null) :
     base(drawings, node, "xdr:sp", "xdr:nvSpPr/xdr:cNvPr", shape)
 {
 }
Example #17
0
        internal ExcelPicture(ExcelDrawings drawings, XmlNode node, FileInfo imageFile)
            : base(drawings, node, "xdr:pic/xdr:nvPicPr/xdr:cNvPr/@name")
        {
            XmlElement picNode = node.OwnerDocument.CreateElement("xdr", "pic", ExcelPackage.schemaSheetDrawings);
            node.InsertAfter(picNode, node.SelectSingleNode("xdr:to", NameSpaceManager));
            picNode.InnerXml = PicStartXml();

            node.InsertAfter(node.OwnerDocument.CreateElement("xdr", "clientData", ExcelPackage.schemaSheetDrawings), picNode);

            Package package = drawings.Worksheet.xlPackage.Package;
            SetContentType(imageFile.Extension);
            _image = Image.FromFile(imageFile.FullName);
            ImageConverter ic = new ImageConverter();
            byte[] img = (byte[])ic.ConvertTo(_image, typeof(byte[]));

            string relID = GetPictureRelID(img);

            if (relID == "")
            {
                UriPic = GetNewUri(package, "/xl/media/image{0}" + imageFile.Extension);
                Part = package.CreatePart(UriPic, ContentType, CompressionOption.NotCompressed);

                //Save the picture to package.
                byte[] file = File.ReadAllBytes(imageFile.FullName);
                var strm = Part.GetStream(FileMode.Create, FileAccess.Write);
                strm.Write(file, 0, file.Length);

                PackageRelationship picRelation = drawings.Part.CreateRelationship(UriPic, TargetMode.Internal, ExcelPackage.schemaRelationships + "/image");
                relID = picRelation.Id;
                AddNewPicture(img, relID);

            }
            else
            {
                var rel = _drawings.Part.GetRelationship(relID);
                UriPic = rel.TargetUri;
            }
            SetPosDefaults(Image);
            //Create relationship
            node.SelectSingleNode("xdr:pic/xdr:blipFill/a:blip/@r:embed", NameSpaceManager).Value = relID;
            package.Flush();
        }
Example #18
0
 internal ExcelConnectionShape(ExcelDrawings drawings, XmlNode node, ExcelGroupShape parent = null) :
     base(drawings, node, "xdr:cxnSp", "xdr:nvCxnSpPr/xdr:cNvPr", parent)
 {
     Init(drawings, node);
 }
Example #19
0
 internal ExcelShape(ExcelDrawings drawings, XmlNode node) :
     base(drawings, node, "xdr:sp/xdr:nvSpPr/xdr:cNvPr/@name")
 {
     init();
 }
Example #20
0
 private void Init(ExcelDrawings drawings, XmlNode node)
 {
     ConnectionStart = new ExcelDrawingConnectionPoint(drawings, node, "a:stCxn", SchemaNodeOrder);
     ConnectionEnd   = new ExcelDrawingConnectionPoint(drawings, node, "a:endCxn", SchemaNodeOrder);
 }
Example #21
0
 internal ExcelDrawing(ExcelDrawings drawings, XmlNode node, string nameXPath) :
     base(drawings.NameSpaceManager, node)
 {
     _drawings = drawings;
     _topNode = node;
     _id = drawings.Worksheet.Workbook._nextDrawingID++;
     XmlNode posNode = node.SelectSingleNode("xdr:from", drawings.NameSpaceManager);
     if (node != null)
     {
         From = new ExcelPosition(drawings.NameSpaceManager, posNode);
     }
     posNode = node.SelectSingleNode("xdr:to", drawings.NameSpaceManager);
     if (node != null)
     {
         To = new ExcelPosition(drawings.NameSpaceManager, posNode);
     }
     else
     {
         To = null;
     }
     _nameXPath = nameXPath;
     SchemaNodeOrder = new string[] { "from", "to", "graphicFrame", "sp", "clientData"  };
 }
Example #22
0
 internal ExcelPicture(ExcelDrawings drawings, XmlNode node, Uri hyperlink) :
     base(drawings, node, "xdr:pic", "xdr:nvPicPr/xdr:cNvPr")
 {
     CreatePicNode(node);
     Hyperlink = hyperlink;
 }
Example #23
0
        internal ExcelPicture(ExcelDrawings drawings, XmlNode node, FileInfo imageFile, Uri hyperlink)
            : base(drawings, node, "xdr:pic/xdr:nvPicPr/xdr:cNvPr/@name")
        {
            XmlElement picNode = node.OwnerDocument.CreateElement("xdr", "pic", ExcelPackage.schemaSheetDrawings);
            node.InsertAfter(picNode, node.SelectSingleNode("xdr:to", NameSpaceManager));
            _hyperlink = hyperlink;
            picNode.InnerXml = PicStartXml();

            node.InsertAfter(node.OwnerDocument.CreateElement("xdr", "clientData", ExcelPackage.schemaSheetDrawings), picNode);

            //Changed to stream 2/4-13 (issue 14834). Thnx SClause
            var package = drawings.Worksheet._package.Package;
            ContentType = GetContentType(imageFile.Extension);
            var imagestream = new FileStream(imageFile.FullName, FileMode.Open, FileAccess.Read);
            _image = Image.FromStream(imagestream);
            ImageConverter ic = new ImageConverter();
            var img = (byte[])ic.ConvertTo(_image, typeof(byte[]));
            imagestream.Close();

            UriPic = GetNewUri(package, "/xl/media/{0}" + imageFile.Name);
            var ii = _drawings._package.AddImage(img, UriPic, ContentType);
            string relID;
            if(!drawings._hashes.ContainsKey(ii.Hash))
            {
                Part = ii.Part;
                RelPic = drawings.Part.CreateRelationship(UriHelper.GetRelativeUri(drawings.UriDrawing, ii.Uri), Packaging.TargetMode.Internal, ExcelPackage.schemaRelationships + "/image");
                relID = RelPic.Id;
                _drawings._hashes.Add(ii.Hash, relID);
                AddNewPicture(img, relID);
            }
            else
            {
                relID = drawings._hashes[ii.Hash];
                var rel = _drawings.Part.GetRelationship(relID);
                UriPic = UriHelper.ResolvePartUri(rel.SourceUri, rel.TargetUri);
            }
            ImageHash = ii.Hash;
            _height = Image.Height;
            _width = Image.Width;
            SetPosDefaults(Image);
            //Create relationship
            node.SelectSingleNode("xdr:pic/xdr:blipFill/a:blip/@r:embed", NameSpaceManager).Value = relID;
            package.Flush();
        }
Example #24
0
        internal ExcelPicture(ExcelDrawings drawings, XmlNode node, FileInfo imageFile, Uri hyperlink) :
            base(drawings, node, "xdr:pic/xdr:nvPicPr/xdr:cNvPr/@name")
        {
            XmlElement picNode = node.OwnerDocument.CreateElement("xdr", "pic", ExcelPackage.schemaSheetDrawings);
            node.InsertAfter(picNode, node.SelectSingleNode("xdr:to", NameSpaceManager));
            _hyperlink = hyperlink;
            picNode.InnerXml = PicStartXml();

            node.InsertAfter(node.OwnerDocument.CreateElement("xdr", "clientData", ExcelPackage.schemaSheetDrawings), picNode);

            Package package = drawings.Worksheet._package.Package;
            ContentType = GetContentType(imageFile.Extension);
            _image = Image.FromFile(imageFile.FullName);
            ImageConverter ic = new ImageConverter();
            byte[] img = (byte[])ic.ConvertTo(_image, typeof(byte[]));


            UriPic = GetNewUri(package, "/xl/media/{0}" + imageFile.Name);
            var ii = _drawings._package.AddImage(img, UriPic, ContentType);
            //string relID = GetPictureRelID(img);

            //if (relID == "")
            string relID;
            if(!drawings._hashes.ContainsKey(ii.Hash))
            {
                //UriPic = GetNewUri(package, "/xl/media/image{0}" + imageFile.Extension);
                //Part =  package.CreatePart(UriPic, ContentType, CompressionOption.NotCompressed);

                ////Save the picture to package.
                //byte[] file = File.ReadAllBytes(imageFile.FullName);
                //var strm = Part.GetStream(FileMode.Create, FileAccess.Write);
                //strm.Write(file, 0, file.Length);
                Part = ii.Part;
                RelPic = drawings.Part.CreateRelationship(PackUriHelper.GetRelativeUri(drawings.UriDrawing, ii.Uri), TargetMode.Internal, ExcelPackage.schemaRelationships + "/image");
                relID = RelPic.Id;
                _drawings._hashes.Add(ii.Hash, relID);
                AddNewPicture(img, relID);

            }
            else
            {
                relID = drawings._hashes[ii.Hash];
                var rel = _drawings.Part.GetRelationship(relID);
                UriPic = PackUriHelper.ResolvePartUri(rel.SourceUri, rel.TargetUri);
            }
            SetPosDefaults(Image);
            //Create relationship
            node.SelectSingleNode("xdr:pic/xdr:blipFill/a:blip/@r:embed", NameSpaceManager).Value = relID;
            package.Flush();
        }