About the question: Technically you can, but I am not completely sure you should. In any case, I'll explain and leave the decision to you :)
The thing with UDFs is that they are supposed to be static: You pass a bunch of values and it returns a calculated value. They aren't supposed to have side effects like adding a comment, and that's why in the Evaluate method we don't offer you a handle to the XlsFile.
But, you can do it. To do it, you would have to:
1)Have a variable holding the XlsFile object so you can add the comment in the UDF.
2)Pass the row and the column where you want to insert it to the udf. You can use =Row() and =Column() Excel functions for this.
3)In the evaluate method, use the XlsFile stored in 1) to add the comment.
Mostly that is it. I made a simple example that you can get at:
ok, I sent "Post reply" too soon. I also wanted to mention that the reason I think you might not need any of this is because you can do it directly with FlexCel and no UDF.
You want to add a comment in a cell that doesn't have a comment in the template. But you can think it on reverse: You can add a comment to the template (instead of writing <#CommentUDF()> in the cell). Then send null to the cells where you don't want a comment, and the text to the cells where you want it. FlexCel will automatically delete all null comments, so the end result should be the same.
In your approach, you add comments only to some cells.
In this other approach, you add a comment to "all" the cells, but remove those you don't want by assigning null to them.