Flexcel.Net Reports and Images

Hi,


I'm currently trying to replace an image in an xlsx file using the FlexCelReport object. Currently  I have tried using the "SetValue()" function with the image variable name and the value set to either a filepath to an image on the local filesystem, or actually passing the bytes of the image data as a byte[] array. Neither seem to result in the image being replaced. 

I have viewed the online video tutorial where an image is replaced, but this appears to pull the data directly from the database. I was unable to find any other examples or information in the documentation for image replacement.

Does anybody have any ideas as to where I am going wrong?

Many thanks,
Ben

Hi Adrian,


I don't think your last post came through ok.

Thanks,
Ben

Hi,

Image must be a byte array, not a filename. Normally FlexCel will figure out which format the image is in, and add the correct one to the file.

You can see an example in the first of the report Demos: "Getting Started Reports". the code used in that demo is:
using (FileStream fs= new FileStream(Path.Combine(DataPath, "img.png"), FileMode.Open))
{
byte[] b= new byte[fs.Length];
fs.Read(b,0,b.Length);
reportStart.SetValue("Img", b);
}

and of course the image is named <#img> as you can see in the template.

Do you have any more information on the issues you are having?

Regards,
   Adrian.

Hi Adrian,


I've modified my file load code to match your method of obtaining the bytearray and run it through again and still no joy. I'll try to produce a standalone example to test and get back to you with more information. It will probably be Monday before I can do this though (I'm on UK time).

Other information that may be useful:
I'm using MS Excel 2007 and saving the template excel file in the XLSX format.
The image I'm attempting to load into the excel file is a jpeg.

Thanks for your time,
Ben

Hi Adrian,


I should have also added, that the Flexcel library doesn't throw any exceptions or errors. The excel template is otherwise populated correctly, and the generated pdf is fine apart from the original image still being there.

Thanks,
Ben

Hi,

I have been investigating the code and I think I have identified a bug that could happen when you use xlsx templates. I will see to fix it and let you know when it is ready.
Please email me to adrian@tmssoftware.com with your registration data and I will send you an url to the fixed version, to see if it works for you

Regards,
   Adrian.

Hi Adrian,

Thanks for all your help so far.

I now have the images successfully being replaced in the XLSX files. I was wondering how to get them to automatically readjust the aspect ratio to suit the new image data. I've tried unchecking the "Lock aspect ratio" option within Excel on the Image object itself. Is there something else I need to do?

Thanks,
Ben

You can use the <#imgsize> tag in the name of the image to keep the aspect ratio.


Please take a look at the "Images" demo (in report section) for an example, it show not only how to keep aspect ratio, but other possibilities, like keeping the width, keeping the height, resizing to 50%, centering the image, etc)ç

Also note that in the demo we use expressions, so the tags are in the Config sheet, ans instead of naming the image directly <#Employees.Photo><#ImgSize> we name it PhotoAutoSize and then define the expression PhotoAutoSize to be the full name. This is not such a bad idea, espceially because editing tags in the image name is kind of difficult.

Regards,
   Adrian.

Great thanks for the pointer. I'll read through those demos in more detail.


Thanks again,
Ben