Padding cell contents with ... to the end

M

Mike

Hi! I am creating a table programmatically in C# / Word 2000.

I need to pad the contents of some cells with "." to the end of the cells.
I can not figure out how to do it. How do I find how many characters a cell
can hold ? I can get the Width of the cell but I can not determined based on
the
font size how many characters I can fit.

Any ideas/suggestions/ samples are greatly appreciated.

Thank you in advance,
 
D

Doug Robbins

How about inserting a tabstop with a ... leader at the end of the cell and
then insert the text and a vbtab character.

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
M

Mike

Thank you for taking a look. My requirements stay that the ........ should
fill the rest of the line. Will your technique satisfy my reqs? I am not sure
if tabs can produce
....... all the way to the end? Is there a way to find out where/when the
cell ends ?

Many Thanks in Advance,
 
D

Doug Robbins

From a manual test, I believe that it can be done.

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
M

Mike

Thank you again. I really appreciate your help.
I searched on the internet on how to create a tabstop programmatically and
could not find anything. Can you recommend a site or code sample please?
How do I manually insert the tabstop you mentioned - I can not find this
option in Word ?

Many Thanks in Advance,

--Mike
 
D

Doug Robbins

I would recommend the Visual Basic Help file that comes with Word. Here is
the example from that source:

Selection.Paragraphs(1).TabStops.Add Position:=InchesToPoints(1), _
Leader:=wdTabLeaderDots, Alignment:=wdAlignTabLeft

I've no idea however how you would do that in C#. Probably better to ask in
a newsgroup devoted to that language than here.

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
M

Mike

Thank you, Doug. I've played with your suggestion extensively and still
unable to
fill the rest of a table cell with dots :-(. Please let me know if you come
across some examples.

Many Thanks in Advance,
 
D

Doug Robbins

Using VBA, the example from the VBA help file works. As mentioned before
however, I have no idea at all how to do it with C#

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
H

Helmut Weber

Hi Mike,
I think you might want to add dots to some text before the cells
end until this causes a new line, and then remove the last character.

Like this, but only a workaraound and pretty slow.

And make sure, you are in print view, and to switch back
to normal view and again to printview. Otherwise,
Information(wdFirstCharacterLineNumber) might not work.

Sub test00001()
Dim l1 As Long ' first Line
Dim l2 As Long ' second line after inserting a dot
Dim oTbl As Table
Dim oCll As Cell
For Each oTbl In ActiveDocument.Range.Tables
oTbl.AllowAutoFit = False '!!!
For Each oCll In oTbl.Range.Cells
oCll.Select
Selection.End = Selection.End - 1
Selection.Collapse direction:=wdCollapseEnd
l1 = Selection.Information(wdFirstCharacterLineNumber)
Selection.TypeText Text:="."
l2 = Selection.Information(wdFirstCharacterLineNumber)
If l2 <> l1 Then
Selection.TypeBackspace
Else
While l1 = l2
l1 = Selection.Information(wdFirstCharacterLineNumber)
Selection.TypeText Text:="."
l2 = Selection.Information(wdFirstCharacterLineNumber)
Wend
End If
Selection.TypeBackspace
Next

Next
End Sub

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top