I am trying to insert EMF(Enhanced metafile images) in to Excel worksheet. We have saved these metafiles in the database, I am reading them, constructing a Memory Stream object and passing as a parameter to the Worksheet.Pictures.Add method. It thorws the following exception when I try to output the generated excel file to webclient.
System.Exception: Unknown error
at Aspose.Cells.Record.?.?(Worksheet ?, Int32 ?, Int32 ?, Int32 ?, Int32 ?, Int32 ?)
at Aspose.Cells.Worksheet.?(? ?)
at Aspose.Cells.Worksheets.?(? ?)
at Aspose.Cells.Worksheets.?(FileFormatType ?)
at Aspose.Cells.Worksheets.?(Stream ?, FileFormatType ?)
at Aspose.Cells.Worksheets.?(String ?, SaveType ?, FileFormatType ?, HttpResponse ?)
at Aspose.Cells.Excel.Save(String fileName, SaveType saveType, FileFormatType fileFormatType, HttpResponse response)
The code for image insertion is below
MemoryStream msCurveFitImage = new MemoryStream((byte)orImgReader.GetOracleLob(0).Value);
int iPicId = xlActWorkSheet.Pictures.Add(iXlCurrRowNum,iColNo,msCurveFitImage);
// int iPicId = xlActWorkSheet.Pictures.Add(iXlCurrRowNum,iColNo,@"c:\test.emf");
Picture xlPicture = xlActWorkSheet.Pictures[iPicId];
xlPicture.Left = 1;
xlPicture.Top = iCurveFitXPos;
xlPicture.Placement = PlacementType.MoveAndSize;
The image is storead as Oracle BLOB. If I use "PNG" image instead of "EMF" image data, above code works,
the output file gets generated. It fails only if I try to insert EMF image.
I was having older version of Aspose.Excel, even after upgrading to latest version 22.214.171.124 same problem persist.
If I pass in file name of an EMF image, then the code works fine and output file gets generated. It fails only when I use Memory Stream object.
One thing I noticed when I pass EMF image file name is that, the EMF images are not stored in the Native form. I think they are converted to Bitmap/PNG format. Actually Excel can handle EMF files in Native form. I don't know why this conversion is taking place. The reason I am adding EMF file to Excel is that, they are scaleable. Since the library is converting them to Bitmap/PNG it beats the very purpose of adding EMF file. Open excel doument. Add an EMF picture object and save the excel document. Open the saved excel, EMF picture will still be in the native form and you can scale it.
I am attaching a sample EMF metafile.