Link to home
Start Free TrialLog in
Avatar of TimAttaway
TimAttawayFlag for United States of America

asked on

Workaround for Excel not Wrapping Text in Merged Cells

I am creating a spreadsheet using Open Office XML.  The spreadsheet contains merged cells that contain text.  In many cases, the text is longer than the size of the merged cells so it needs to wrap.  I have the cell style set to wrap, but Excel ignores it.  From searching on the internet, it seems that Excel ignoring "wrap' on merged cells is a long standing problem.  The only workarounds that I see offered are to manually resize the rows, which would not be a problem if I were creating the spreadsheet manually.

Does anybody know a way to programmatically assess the size of a text string to figure out what the height of the row needs to be?  Given a string, a font, a font size, font characteristics (bold, italics, whatever), and the width of the cell (in points or pixels), how can I compute what the height of row containing the cell needs to be so that I can see the entire string?

Thanks.
Avatar of TimAttaway
TimAttaway
Flag of United States of America image

ASKER

I found the Graphics.MeasureString method, which looked promising, but I need something that will work in a class that is not necessarily bound to any particular control.  It will be running on a web server.
Avatar of ukerandi
Check this file for column Size
size.xlsm
This one showing according to font
size.xlsm
Thanks, but this does not really have anything to do with the question that I asked. I need something that can run on a server creating the sheet using open office xml, not a macro that runs inside the spreadsheet.
ASKER CERTIFIED SOLUTION
Avatar of TimAttaway
TimAttaway
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I solved this issue myself.  I am posting the results in case they may be useful to someone else.