Exemplo n.º 1
0
 /// <summary>
 /// Add a image to the current worksheet.
 /// </summary>
 /// <param name="image">The image.</param>
 /// <exception cref="T:System.ArgumentNullException">image</exception>
 /// <exception cref="T:System.NotSupportedException"></exception>
 public void SetSheetImage(IExcelImage image)
 {
     if (image == null)
     {
         throw new ArgumentNullException("image");
     }
     if (string.IsNullOrWhiteSpace(image.Name))
     {
         throw new NotSupportedException(ResourceHelper.GetResourceString("EmptyImageNameError"));
     }
     using (List <IExcelChart> .Enumerator enumerator = this.ExcelCharts.GetEnumerator())
     {
         while (enumerator.MoveNext())
         {
             if (enumerator.Current.Name == image.Name)
             {
                 throw new NotSupportedException(ResourceHelper.GetResourceString("CurrentWorksheetHasSameImageError"));
             }
         }
     }
     if (image != null)
     {
         this.ExcelImages.Add(image);
     }
 }
Exemplo n.º 2
0
 public void SetExcelImage(int sheetIndex, IExcelImage excelImage)
 {
     if (excelImage != null)
     {
         this._workbook.Worksheets[sheetIndex].SetSheetImage(excelImage);
     }
 }
Exemplo n.º 3
0
        internal XFile GetExcelImageIdex(IExcelImage excelImage)
        {
            if ((excelImage == null) || (this.Images.Count == 0))
            {
                return(null);
            }
            for (int i = 0; i < this.Images.Count; i++)
            {
                IExcelImage image = this.Images[i].Item1;
                if (((image.ImageType == excelImage.ImageType) && (image.SourceArray.Length == excelImage.SourceArray.Length)) && Enumerable.SequenceEqual <byte>(image.SourceArray, excelImage.SourceArray))
                {
                    return(this.Images[i].Item2);
                }
            }
            string str = "jpg";

            switch (excelImage.ImageType)
            {
            case ImageType.JPG:
                str = "jpg";
                break;

            case ImageType.PNG:
                str = "png";
                break;

            case ImageType.Bitmap:
                str = "bmp";
                break;

            case ImageType.Gif:
                str = "gif";
                break;
            }
            string str2 = @"\xl";
            XFile  file = new XFile(string.Concat((string[])new string[] { str2, @"\media\image", ((int)this.ImageCounter).ToString((IFormatProvider)CultureInfo.InvariantCulture.NumberFormat), ".", str }), "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image");
            string str3 = string.Format("image{0}.{1}", (object[])new object[] { ((int)this.ImageCounter).ToString((IFormatProvider)CultureInfo.InvariantCulture), str });

            file.Target = "../media/" + str3;
            MemoryStream stream = new MemoryStream(excelImage.SourceArray);

            stream.Seek(0L, (SeekOrigin)SeekOrigin.Begin);
            this.CreateMemoryFile(file.FileName, (Stream)stream);
            this.Images.Add(new Tuple <IExcelImage, XFile>(excelImage, file));
            return(file);
        }