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 = UriHelper.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"); } } }
protected override PackagePart CreatePartCore(Uri partUri, string contentType, CompressionOption compressionOption) { ZipPackagePart part = new ZipPackagePart(this, partUri, contentType, compressionOption); Parts.Add(part.Uri, part); return(part); }
protected override PackagePart[] GetPartsCore() { ZipPackagePart[] p = new ZipPackagePart[Parts.Count]; Parts.Values.CopyTo(p, 0); return(p); }
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(); }
/// <summary> /// Method to create file at the temp folder /// </summary> /// <param name="rootFolder"></param> /// <param name="contentFileURI"></param> /// <returns></returns> private void createFile(string rootFolder, ZipPackagePart contentFile) { // Initially create file under the folder specified string contentFilePath = string.Empty; contentFilePath =contentFile.Uri.OriginalString.Replace('/', System.IO.Path.DirectorySeparatorChar); if (contentFilePath.StartsWith( System.IO.Path.DirectorySeparatorChar.ToString())) { contentFilePath = contentFilePath.TrimStart( System.IO.Path.DirectorySeparatorChar); } else { //do nothing } contentFilePath = System.IO.Path.Combine(rootFolder, contentFilePath); //contentFilePath = System.IO.Path.Combine(rootFolder, contentFilePath); //Check for the folder already exists. If not then create that folder if (System.IO.Directory.Exists( System.IO.Path.GetDirectoryName(contentFilePath)) != true) { System.IO.Directory.CreateDirectory( System.IO.Path.GetDirectoryName(contentFilePath)); } else { //do nothing } System.IO.FileStream newFileStream = System.IO.File.Create( contentFilePath ); newFileStream.Close(); byte[] content = new byte[contentFile.GetStream().Length]; contentFile.GetStream().Read(content, 0, content.Length ); System.IO.File.WriteAllBytes(contentFilePath, content); }
internal ExcelVbaSignature(Packaging.ZipPackagePart vbaPart) { _vbaPart = vbaPart; GetSignature(); }
//------------------------------------------------------ // // Constructors // //------------------------------------------------------ /// <summary> /// Build a System.IO.Stream on a part that possibly consists of multiple files /// An InterleavedZipPartStream gets created by ZipPackagePart.GetStreamCore when the part /// is interleaved. It wraps one or more Zip streams (one per piece). /// (pieces). /// </summary> /// <param name="mode">Mode (create, etc.) in which piece streams should be opened</param> /// <param name="access">Access (read, write, etc.) with which piece streams should be opened</param> /// <param name="owningPart"> /// The part to build a stream on. It contains all ZipFileInfo descriptors for the part's pieces /// (see ZipPackage.GetPartsCore). /// </param> internal InterleavedZipPartStream(ZipPackagePart owningPart, FileMode mode, FileAccess access) : this(PackUriHelper.GetStringForPartUri(owningPart.Uri), owningPart.PieceDescriptors, mode, access) { }
private static void ExtractFile(string rootFolder, ZipPackagePart contentFile) { try { string contentFilePath = contentFile.Uri.OriginalString.Replace('/', Path.DirectorySeparatorChar); if (contentFilePath.StartsWith(Path.DirectorySeparatorChar.ToString())) { contentFilePath = contentFilePath.TrimStart(Path.DirectorySeparatorChar); } contentFilePath = Path.Combine(rootFolder, contentFilePath); if (Directory.Exists(Path.GetDirectoryName(contentFilePath)) != true) { Directory.CreateDirectory(Path.GetDirectoryName(contentFilePath)); } FileStream newFileStream = System.IO.File.Create(contentFilePath); newFileStream.Close(); byte[] content = new byte[contentFile.GetStream().Length]; contentFile.GetStream().Read(content, 0, content.Length); System.IO.File.WriteAllBytes(contentFilePath, content); } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); } }