Is there any way to insert a Text Box into an Excel sheet. I found number of examples of how to insert image and comments, but nothing related to inserting text boxes.
Another issue I'm having is when placing images on a sheet. I know the width of the images in pixels and I know the width of the cells in "1/256s of average character width" (the width property on the cell). How can I convert that to pixels?
Thanks in advance,
Trausti
In the future, please post individual questions separately so the threads are easier to to follow for everyone else. Thanks.
Text boxes are currently not fully supported, but they do have round trip support, which means if you load in a Workbook which has text boxes on it, modify it, and then save it out again, the text boxes will still be there. So if you only need a text box in a predefined location, you could have a Excel file that you use as a template which has the text boxes. Then, instead of creating a new Workbook object, load one from the existing file. Add the data to it and then save it.
In fact, you can even modify the position and text of the text boxes in the loaded Workbook because they are accessible in the Worksheet.Shapes collection as UnknownShape instances, which have Text and position properties. So all you really need in the preexisting file is the correct number of text boxes. However, if you need to dynamically create an unknown number of text boxes, you will need to submit a feature request for this ability.
As for positioning shapes relative to cells, I would recommend using twips instead of pixels or 1/256th of the average character width. The WorksheetCell object defines a couple GetBoundsInTwips methods which tell you the twip bounds the cell occupies on the worksheet. The WorksheetShape class defines similar methods as well as SetBoundsInTwips methods. So if you want to position a shape directly over a cell, you could to something like this:
shape.SetBoundsInTwips(cell.Worksheet, cell.GetBoundsInTwips());
Thanks Mike for the reply. From now on I'll post each question in a separate thread :)
I had not noticed the GetBoundsInTwips function, this is very helpful.
Unfortunatly, I need to create text boxes dynamically at run time. I'll submit feature request for this.
Thanks again,
Regarding the text boxes, I thought of one more thing you could try: your tmeplate file could have a large number of text boxes (more than you would ever need at runtime). Then when you generate your file, you would load in the template, customize the first X number of text boxes you need and then remove the rest from the Shapes collection of the worksheet.
That could work. I decided to just use the Microsoft.Office interface to do this and some other things that are either not available or limited in the Infragistics.Excel interface.
Thanks,
Hello ,
I just checking the progress of this issue. As far as I understand from you latest post, you were able to solve your issue.
Let me know if you have any further questions.
Thanks for that Hristo. Yes, this was solved by using Microsoft's Excel interface.