How to get/calculate the character width in MS Word?

BEFORE a lot of text strings are written to a Word file using Office Automation, I need to know the width of each string. Is there any way to do it

Please note that office automation cannot be used, because the Word file is NOT available yet.

Thanks.



Answer this question

How to get/calculate the character width in MS Word?

  • PeterM

    I've asked around and I'm sorry to inform you that I have found no answer to your issue. VSTO doesn't have built in functionality to determine width of a string in pixels or relative units of a string.

    Can you please reiterate what is the original issue you are trying to solve because this seems to be a very difficult way of trying to solve your original problem.


  • YongLi

    Thanks, Maarten & Mark,

    To Maarten: I do have the font information.

    To Mark: This is the only way I can think of, but my boss doesn't like it, because there may be hundreds of thousands of text strings.

    Thanks again.


  • Hazel

    We have built a typesetting system around Word and that is the biggest issue that we have, determining the length of a string of text. It is unfortunate that such a small request is so difficult to resolve.

    What are you trying to accomplish with Word Why do you need the length of a string There may be another approach that you could take.


  • SanjeevUpd

    While there is a means of getting the length of a string in .NET you will find that it will not match the actual width of a string in Word. One option is to insert a one cell table in a Word document, insert the string into the cell and cell the width of the cell to autmatically resize to the width of the string. The width of the cell will be the width of the string in points.
  • Adi.Condor


    It's not really a VSTO related question, but besides that I think you are not in a position where you can determine the width of the string before knowing what font is used, the size of the font etc etc.

    Every font (except the fixed fonts) has its own width. A Verdana string can turn out to be of a different length compared to an Arial string.

    -= Maarten =-



  • Shen Yizhe

    The problem is that you can NOT get the length of a string, using a particular font,  in .NET that matches the length of that string in Word. You also can not easily get the length of a string in Word easily based on a particular font.

    You can verify this by inserting a string of text into a cell in Word then use that same string to determine the length of that string using .NET. You can then take the length in points returned from .NET and use it to set the width of the cell. No match, not even close.

    This seems like such a simple request for either Office or .NET.

    The bottom line we need to determine the length of a string of text based on a font family and size that will match what Word is doing.

    Mark Baird


  • How to get/calculate the character width in MS Word?