Hi,
First of all, let me tell you that to get this to work you will have to use a monospaced font. If using proportional fonts, all widths are different and it won't be possible to align them at the right. Say an space is 3 pixels, a "i" 4 pixels and a "M" 5 pixels. You have a line with an i, the other with an M, and you want to align them with spaces. It is not possible, because i + space = 7, while M is 5, and M + space is 8. It is very unlikely that with a proportional font you will get the spaces to neatly align the letters.
For example, with the font in this forum:
1)This is a test HHH
2)iii o YMHHH <-Not enough
3)iii o YMHHH <-With an extra space, it is too much.
The human eye is sadly very good at noticing this kind of stuff, and you will get a right column that doesn't look right. So you really need to use a monospaced font. (You could use Courier, but there are nicer ones, maybe Consolas?) And if you are using a monospaced font, you can just ensure that all the lines have the same number of characters. So the algorithm could be:
1)count the characters in all the lines, and get the max.
2)Add spaces so all the lines have the same number of characters as the max.
If you want to do it with proportional fonts, you can use:
ColWidth = xls.GetColWidth(col) / ExcelMetrics.ColMultDisplay(Workbook);
This will give you the result in "device independent pixels" (1/96 of an inch). If you want them in points (1/72 of an inch), which is the unit FlexCel uses to draw, you have to multiply it by 72.0/92.0. It depends in the units on which you get the measured text.
You might also need to add some adjustment, because the column widths in Excel aren't always the same: they depend in the zoom level and in the resolution. Everything explained here still applies:
So, you might want to subtract some security margins from the number you got above, so the text looks well in all resolutions and doesn't wrap to the next line.