User defined function

Hello,

I'am using "FlexCelReport" for creating excel reports and I want to add a custom function that inserts an image into an excel sheet. So I created a new class which extends "TFlexCelUserFunction" and added it to the FlexCelReport. My "Evaluate" function returns an instance of TUIImage. But as a result I just get the text "System.Drawing.Bitmap". Is it possible to insert an image via an user defined function?

Thanks in advance

Hi,

Yes, it is possible, but you should return the byte[] array of the image in Evaluate. Also, you need to set the tag in an existing image, as shown in the "Images" demo.

I've uploaded a simple demo at
http://www.tmssoftware.biz/download/flexcel/samples/ImgTest.zip

Note that in the example I do a lot of extra work: I create a TUIImage from a file, then save the UIImage to a stream, then return the stream. For this case, you would just use a FileStream to read the data, save it to a byte array and return that. But if you are doing some image manipulation, you might want to use the TUIImage.

Thank you for your help, it works now! But I have also another question. In the "XlsFile" class there is also a method called "AddUserDefinedFunction" that takes an "TUserDefinedFunction" as an argument. Can you explain me the difference between "TUserDefinedFunction" and "TFlexCelUserFunction"?

Hi,

They are completely different things. TUserDefinedFunction refers to Excel user defined functions, it isn't related to reports. TUserDefinedFunction was added later than TFlexCelUserFunction, and we couldn't rename TFlexCelUserFunction then, or we would have, maybe to something like TReportUserFunction.

TUserDefinedFunction is used to calculate formulas in Excel that are defined via macros, and that FlexCel wouldn't be able to calculate other way. Take a look at the example:
Modules\10.API\78.Excel User Defined Functions
to see how they work.

OK, thank you