Hi,
im using Aspose cells version 20.8.0.0
when converting the attached Excel that contains pictures the operation fails ,
all other excels i’ve tested are ok,
please download file from here : https://transferxl.com/08jrB1gx3t5mxT
here’s the code sample im using
using System.Drawing;
using System.Drawing.Imaging;
using Aspose.Cells;
try
{
int jpegQuality = 90;
if (_file.ToLower().EndsWith("xls") | _file.ToLower().EndsWith("xlsx") | _file.ToLower().EndsWith("csv") | _file.ToLower().EndsWith("mht"))
{
Aspose.Cells.Workbook work = new Aspose.Cells.Workbook(_file);
foreach (Worksheet WSH1 in work.Worksheets)
{
// Convert VML shapes.
foreach (Aspose.Cells.Drawing.Picture vmlShape in WSH1.Pictures)
{
try
{
Aspose.Cells.Rendering.ImageOrPrintOptions IOR1 = new Aspose.Cells.Rendering.ImageOrPrintOptions();
IOR1.SaveFormat = Aspose.Cells.SaveFormat.Auto;
byte[] originalBytes = vmlShape.Data;
Aspose.Cells.Drawing.ImageType imageType = vmlShape.ImageType;
if (vmlShape == null)
continue;
if (originalBytes == null)
continue;
try
{
using (System.Drawing.Image srcImage = vmlShape.ToImage(IOR1))
{
using (Bitmap dstImage = new Bitmap(vmlShape.OriginalWidth, vmlShape.OriginalHeight))
{
using (Graphics gr = Graphics.FromImage(dstImage))
{
gr.DrawImage(srcImage, 0, 0, vmlShape.OriginalWidth, vmlShape.OriginalHeight);
}
ImageCodecInfo[] encoders = ImageCodecInfo.GetImageEncoders();
ImageCodecInfo enc = null;
System.Drawing.Imaging.ImageFormat format = System.Drawing.Imaging.ImageFormat.Png;
try
{
for (int i = 0; i < encoders.Length; i++)
{
if (encoders[i].FormatID == format.Guid)
enc = encoders[i];
}
throw new Exception("Cannot find a codec.");
}
catch { }
EncoderParameters encoderParams = new EncoderParameters();
encoderParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, jpegQuality);
MemoryStream dstStream = new MemoryStream();
dstImage.Save(dstStream, enc, encoderParams);
dstStream.Position = 0;
vmlShape.Data = dstStream.ToArray();
}
}
}
catch { }
}
catch (Exception)
{
throw;
}
}
}
work.Save(_file + ".Xlsx", Aspose.Cells.SaveFormat.Xlsx);
}
}
catch { }