Hi, I have a question re images in header / footer of Excel.
Which image file types are supported? Are there any limitations?
I’ve found that I can successfully load .png and .jpg, but not .bmp.
I’ve got a small sample file that I’ve saved as all three types, but with aspose only two of them are displayed in the header/footer. There are no errors. The .bmp file is just not displayed.
All three file types can be added to the header/footer if I use Excel to do it.
(I would have uploaded all three image files plus sample excel sheet but I’m not allowed to upload .bmp and .xlsx so it’s not much use,) pngtest-as-jpg.jpg (1.8 KB) pngtest.png (477 Bytes)
@KarinMX
It must be the limitation of MS Excel. If you insert a bmp to header/footer in MS Excel, the saved image is converted to png.Please try the following temp solution:
var workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
sheet.Pictures.Add(0, 0, dir + “1.bmp”);
PageSetup ps = sheet.PageSetup;
ps.SetHeaderPicture(1, ConvertImage(dir + “1.bmp”));
ps.SetHeader(1, “abc&Gefd”);
workbook.Save(dir + @“dest.xls”);
}
private static byte[] ConvertImage(string f)
{ using (Image image = Image.FromFile(f))
{
MemoryStream ms = new MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
return ms.ToArray();
}
}
We will keep on looking into this issue to check whether automatically converting bmp to png when inserting it to header/footer.
Thanks, I’ll try that. Your code is slightly different from the examples I used when I wrote my code earlier. It might make a difference.
I think you may be right re it being an Excel issue. After I asked, I was checking pdf file creation (for other reasons), but I used the same sheet and I found that the bmp file is displayed if I save as pdf, but not if I save as xlsx.
It might be worth checking if it shows in other possible file types. But I don’t think it’s connected to the xlsx file type. I can take the xlsx file and add the same bmp file in manually in Excel, and then it shows.
You can try the workaround code to cope with your issue for the time being.
Please note, we might add relevant APIs, something like “ImageUtil.SaveImageToPng” internally to convert the bitmap image to PNG file format dynamically, so you do not need to use the suggested temp solution (as described above) anymore. A ticket was logged already with an id “CELLSNET-50041” for it. Once we have an update on it, we will let you know.
Good to know that your issue is resolved by the new fix. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.
The issues you have found earlier (filed as CELLSNET-50041) have been fixed in this update. This message was posted using Bugs notification tool by simon.zhao